NI Labs Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

NI LabVIEW Modbus API Discussion

Hi Smithd

Thank u very much for the reply. I did this and its working

I created already two instances and i am writing & reading these slaves seperately with different values. I created the real time application and downloaded this in cRIO. I am accessing it through web browser. As i am writing the values, i can read them in same application correctly. Now i want to access the modbus registers of these two different slave servers through Master device at the same time.

My problem is that i want to create one server at primary port of the cRIO and second one at the secondary port but both may be with the same port no i.e. 502. Both are at different subnet (as you can see above). But I am not able to create different slave server instance on the basis of IP Address and its only according to port no (subvi is password protected)

How can i solve this problem ? Do you have some other ways

Thanks

Varun

0 Kudos
Message 91 of 527
(5,082 Views)

The Modbus slave just uses the standard LabVIEW TCP functions--which means the following is true:

1111.png

As a result, opening a single slave on port 502 will cause it to listen on both NICs, even across subnets. If this is not the desired behavior, the library has an unexposed ability to set this. To do so you will have to either modify (not recommended) or copy (recommended) the current Create TCP Slave function to add this property:

222.png

Thanks,
Daniel

0 Kudos
Message 92 of 527
(5,082 Views)

Hello Daniel

Thanks for the gr8 help . It's all working now and i am happy

Happy New Year

Best Wishes

Varun

0 Kudos
Message 93 of 527
(5,082 Views)

Another build

smithd wrote:

Hi All,

Attached is a new preliminary build of this API. I am looking for people to try out the code, particularly the serial portion.

Basically, what changed is how serial works. Originally, the code was intended to be interoperable between transports (serial, tcp) and protocols (TCP, serial RTU, serial ASCII). In reality, it is impossible for a serial protocol to run over TCP because modbus did not include data length in the packet header until the TCP packet was introduced. This version of the library utilizes this gap to look for data in a less dynamic way. Each serial protocol type (RTU vs ASCII) now has a connection handler. In addition, the serial protocol code was modified to talk to that handler, rather than the port itself. The end result is that there is now a process handling the VISA session while all your user code actually does is read or write from a queue.

The tl;dr version of all this is that the serial code is much better and much more tweakable in the case of errors.

My hope is that some of you nice people out there can try the code, let me know how it works, and let me know if this is the right direction for the API to move. I know that my test hardware now works, but you guys have real-world applications and thats what actually needs to work

Thanks,

Daniel

0 Kudos
Message 94 of 527
(5,083 Views)

Hi Smithd,

First of thanks for this API. I have used it successfully to create a Modbus Serial Master to communicate with my serial slave device. My ultimate goal is to create a Modbus RTU over TCP master to communicate with my serial device via a TCP-to-Serial Modbus gateway.  My question is if  I modify an Instance of the Modbus Master TCP with the Set Unit ID.vi will this work to communicate with my slave device via the TCP to Serial Modbus gateway. I noted in your documentation that the Set Unit ID.vi only work with the Serial Master instance. I cannot try this yet as am awaiting delivery of the gateway.

Thanks,

Shina

0 Kudos
Message 95 of 527
(5,082 Views)

Hi Smithd

I have some further questions. I am communicating 1 Master with 30 slave with different unit ID's. Whenever there is TCP IP connection lost, I am shuting down that instance and generating the error. Further if its only TCP connection lost then starting the connection again other wise not shuting down the instance. My problem is that whenever there is TCP IP connection lost, my front panel freezes for 1 or 2 min per slave. This is because of Timeout value 60,000ms for creating the instance.

For this i took out the connecter of Timeout from TCP Master function but still its taking 60,000ms. Is it possible to control it or might be you can change in the library so that i can configure timeout like in the previous libraries.

Thanks

Varun

0 Kudos
Message 96 of 527
(5,083 Views)

Hi Shina,

That documentation is poorly worded. For the purposes of this API, TCP ignores the unit ID. However, if you set the unit ID it *is* transmitted to the slave, so the slave can use that ID as it wishes. This is intended to provide the backwards compatibility with TCP->Serial gateways as you suggest.

Thanks,
Daniel

ShinaBaba wrote:

Hi Smithd,

First of thanks for this API. I have used it successfully to create a Modbus Serial Master to communicate with my serial slave device. My ultimate goal is to create a Modbus RTU over TCP master to communicate with my serial device via a TCP-to-Serial Modbus gateway.  My question is if  I modify an Instance of the Modbus Master TCP with the Set Unit ID.vi will this work to communicate with my slave device via the TCP to Serial Modbus gateway. I noted in your documentation that the Set Unit ID.vi only work with the Serial Master instance. I cannot try this yet as am awaiting delivery of the gateway.

Thanks,

Shina

0 Kudos
Message 97 of 527
(5,082 Views)

Varun_ECK wrote:

Hi Smithd

I have some further questions. I am communicating 1 Master with 30 slave with different unit ID's. Whenever there is TCP IP connection lost, I am shuting down that instance and generating the error. Further if its only TCP connection lost then starting the connection again other wise not shuting down the instance. My problem is that whenever there is TCP IP connection lost, my front panel freezes for 1 or 2 min per slave. This is because of Timeout value 60,000ms for creating the instance.

For this i took out the connecter of Timeout from TCP Master function but still its taking 60,000ms. Is it possible to control it or might be you can change in the library so that i can configure timeout like in the previous libraries.

Thanks

Varun

Hey Varun, you're right, that wasn't exposed. It is now (attached).

Note: This is a revision of the path started by 1.1.1 with the newer serial code.

0 Kudos
Message 98 of 527
(5,083 Views)

Hi Smithd,

Thanks for the reply.

I now have a the TCP-Serial Gateway all seems to be working well except when I attempt to write a 32bit value to a particular register using the Write Multiple Register.vi. The sequence of commands as shown by the traffic monitor is below

TCP Request:                      00 00 00 00 00 0B 01 10 00 9B 00 02 04 73 61 76 65

Port 1 RTU Request:          01 10 00 9B 00 02 04 73 62 76 65 16 61

Port 1 RTU Response:       01 10 00 9B 00 02 30 27

The above should normally be followed by a TCP response but I get an error  56 and this occurs on the Read ADU Packet.vi  used in the Write Multiple Holding Register.vi as shown by the error description

What I find odd is that if I write any other 32 bit value to the same register this problem does not occur except when I write 73 62 76 65

As the command gets to my device successfully the command is accepted and processed but the error is causing a user interface problem as it disconnect and I have to reconnect  again.

Any pointer on what the issue is?

Regards,

Shina

0 Kudos
Message 99 of 527
(5,082 Views)

Hi Smith,

I figured out what the problem is, it is a time out issue from my device, I changed the  read response timeout configuration on my gateway and this solved the problem.

Thanks,

Regards,

Shina

0 Kudos
Message 100 of 527
(5,082 Views)