Elsist Electronic systems since 1983   Italiano  Italian Flag   
 
 
ELSIST - Electronic Systems since 1983 SlimLine series PLCs  - Automation made in Italy Touchscreen HMIs Interface conversion Wireless LAN solutions GSM/GPRS/UMTS products and solutions IP monitoring solutions
 LOGIN  
Username
Password
 Remember data
Allows to register Register now
Allows to subscribe to the newsletter Newsletter subscription
Allows emergency site access Forgot your password?
 GO TO TOPIC
 NEWS
View recently updated pages New/revised pages
View new products New products
View new downloads New downloads
View new posts on forum New Forum posts
 SERVICES
Sends an Email with infos request Info request
Displays the quote request form Quote request
 SHOWCASE
4G LTE router LR77 v2 Full (Plastic case)
4G LTE router LR77 v2 Full (Plastic case)
AirCam Wall - IP Camera Wall mount
AirCam Wall - IP Camera Wall mount
40A DC Uninterruptible Power Supply
40A DC Uninterruptible Power Supply
Reader ProxPoint Plus 6008BKB00
Reader ProxPoint Plus 6008BKB00
600533  I/O Controller II
600533 I/O Controller II
EDGE 4-band ER75i v2 Basic Router (Plastic case)
EDGE 4-band ER75i v2 Basic Router (Plastic case)
SlimLine Relay output exp. I/O Module 16In 8Out
SlimLine Relay output exp. I/O Module 16In 8Out
Radiant 868 Radiomodem base
Radiant 868 Radiomodem base
ATC-2000WF Wi-fi to serial converter
ATC-2000WF Wi-fi to serial converter
SlimLine Mixed Signal I/O Module + RS232
SlimLine Mixed Signal I/O Module + RS232
 OFFERS Go to offer page 
RS232/422/485 to single mode fiber optic Converter
RS232/422/485 to single mode fiber optic Converter
€ 273.00
Price reduced € 263.00
 You are here: Forums list  Reselled products: Interface converters  Protocoll... IP con script PHP Add page to favourites Send this page by email Print this page
Messages list
  FORUM
Interface converters
Interface converter products use suggestions
 Discussion
Protocollo modbus over IP con script PHP
Script PHP per gestire lettura registri con protocollo modbus over IP utilizzando un convertitore ethernet/seriale
Author:  Bertaser Date (GMT):  16/10/2008 08:11:51
Flags Message
Messaggio in Italiano
 
Date (GMT):  16/10/2008 08:11:51  
Author:  Bertaser
Utilizzando un convertitore ethernet/seriale è possibile con un semplice script PHP eseguire la lettura di registri da un nostro sistema Netlog utilizzando il protocollo modbus over IP.
 
Lo script PHP esegue l'apertura del socket verso il convertitore TRP-C31, invia sul socket la stringa di comando per la lettura del registro ed attende la risposta dal convertitore.
 
Il convertitore TRP-C31, provvede ad inviare sulla linea seriale la stringa modbus ricevuta dal socket che inviata alla porta seriale del sistema Netlog genererà il messaggio di risposta che il convertitore TRP-C31 invierà al socket. Download script.
 
// Eseguo definizioni per connessione TRP-C31.
 
$IPAddress="192.168.0.20"; //Indirizzo IP convertitore
$PortNr=4000; //Porta host convertitore
set_time_limit(5); //Imposto tempo limite socket (5 Sec)
 
// Eseguo creazione e connessione al socket.
 
if (($TRPSkt=socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false)
    {echo "socket_create ".socket_strerror(socket_last_error()); return;}
 
if (!socket_connect($TRPSkt, $IPAddress, $PortNr ))
    {echo "socket_connect ".socket_strerror(socket_last_error()); socket_close($TRPSkt); return;}
 
// Eseguo interrogazione valore registro 0x0000 da nodo 0x01.
 
echo "Value is: ".ModbusRead($TRPSkt, 0x01, 0x0000);
socket_close($TRPSkt);
 
function ModbusRead($Skt, $Node, $Register)
{
    // Genero valore di transaction identifier.
 
    $TrnIdf=rand(0, 65535); //Transaction identifier
 
    // Invio stringa interrogazione modbus, Code 03: Read input registers.
 
    $OutString=chr($TrnIdf/256); //Transaction identifier (Hi)
    $OutString.=chr($TrnIdf); //Transaction identifier (Lo)
    $OutString.=chr(0x00); //Protocol identifier (Hi)
    $OutString.=chr(0x00); //Protocol identifier (Lo)
    $OutString.=chr(0x00); //Length (Hi)
    $OutString.=chr(0x06); //Length (Lo)
    $OutString.=chr($Node); //Unit identifier
    $OutString.=chr(0x03); //Function code
    $OutString.=chr($Register/256); //Register address (Hi)
    $OutString.=chr($Register); //Register address (Lo)
    $OutString.=chr(0x00); //No of Points (Hi)
    $OutString.=chr(0x01); //No of Points (Lo)
    socket_write($Skt, $OutString);
 
    // Eseguo attesa ricezione stringa di risposta.
    // La stringa di risposta contiene il valore del registro 9o e 10o byte.
 
    $TimeBf=time(); //Salvo tempo per timeout
    while (socket_recv($Skt, $IString, 1024, PHP_BINARY_READ))
        if (time() > $TimeBf+2)
        {
            // Eseguo controllo se ricevuto frame di risposta corretto.
            // Se valore di transaction identifier stringa di risposta diverso
            // da stringa di richiesta considero valore errato e ritorno "0".
   
            if ($TrnIdf != (ord($IString[0])*256+ord($IString[1]))) return(0);
            return(ord($IString[9])*256+ord($IString[10]));
         }
}
Messaggio in Italiano
 
Date (GMT):  03/03/2009 16:31:13  
Author:  Bertaser
Ricordo che per poter gestire i socket da script PHP occorre controllare che in fase di installazione del PHP sia stata caricata la dll di gestione socket php_sockets.dll e che nel file php.ini, nella sezione Dynamic Extensions sia stata abilitata l'estensione socket.
 
; Dynamic Extensions ;

extension=php_sockets.dll
Messaggio in Italiano
 
Date (GMT):  27/08/2011 11:28:48  
Author:  marcom87
Analogamente a questo script, si potrebbe avere una funzione equivalente di esempio per la scrittura di un registro ?
Messaggio in Italiano
 
Date (GMT):  29/08/2011 06:03:16  
Author:  Bertaser
Puoi trovare quello che c erchi in questo post. Altri esempi di utilizzo socket da Php in questo post.
Page:  (1)      
 © Copyright 1996-2013 ELSIST Srl - VAT ID: IT01122830068