Nmodbus ModbusIpMaster.createIP Sample code

553 views
Skip to first unread message

harshal samdani

unread,
Nov 18, 2014, 1:29:58 AM11/18/14
to nmodbus...@googlegroups.com
Hi all, 

I am newbie to modbus over TCP, i am using nmodbus in my project and my implementation for createRTU ( modbus over serial port) is working very fantastic. 

Now i am implementing the code for modbus over TCP , If some one can give me some code sample which will handle all the cases as below will be greatly appreciable. 

1. Automatic reconnect if connection close. 
2. detect error code(E.g timeout, invalid function code/data address, master busy) 

// My code for reference :- 

                    tcpObj = new TcpClient();
                    tcpObj.BeginConnect("192.168.2.5", 1025, null, null);

                    Modbus.Device.ModbusIpMaster _rishDevice1340;
                   _rishDevice1340 = Modbus.Device.ModbusIpMaster.CreateIp(tcpObj);

                    try
                   {
                           registerData = _rishDevice1340.ReadInputRegisters(meterID, startAdd, register);
                    }catch()
                    {
                      //Exception handling. 
                    }

Anyone's help or even small inputs are greatly appreciable. 

Thanks in advance. 


Reply all
Reply to author
Forward
0 new messages