LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus/TCP Queries

Hi,

I am trying to use Modbus TCP to set the time / date on my cFP-2120 running Labview Real-Time 5.0.1. For this purpose I have set up four holding registers that hold two single precision floats, one for the time (format: hhmmss) and one for the date (mmddyy). The idea is that each time the Modbus Master writes to the holding registers, the time / date of the cFP2120 gets set.

In my application, I have implemented Modbus communication similar to the MB Ethernet Example Slave.vi, which came with the NI Modbus library for Labview 8.2. This is also similar to the Modbus tutorial here. Essentially, I am reading the appropriate Modbus holding registers using the MB Register Manager.vi (also part of the Modbus library) and use their values to set the controller.

The problem arising is that I set the controller time even if the Master has not written to the holding registers, which results in wrong times/dates. Is there a way to determine whether these holding registers have been written to by the Master, so that I can react on it as soon as this happens?

Thanks,
Volker



0 Kudos
Message 1 of 5
(5,094 Views)
Hi Volker,

There are two methods that you might consider using.  If your program operates in a loop, you could add shift registers that store the date and time values used for the last clock update.  Compare any subsequent reads with these values and update the clock only if they have changed.

The other option would be to set up another holding register which holds a "value changed" boolean.  When you write to the date and time registers, write a true to this register.  Then your controller can just check this value.  If it is true, set it to false and read the date/time and set the clock.  If it is false, that means there has been no new updates, so don't update the time.
0 Kudos
Message 2 of 5
(5,063 Views)
Devin,
thanks for the response.
Your suggestion are a possibility, especially the first one.

However, as these registers are holding registers (read/write), I was hoping to also post to them the current time by the slave to be read by the master.
In case the time needs to be synched, the master posts the correct time to the same registers upon which the slave will update its time and again start posting its current time to these registers.

I realize that the easiest way to accomplish this would be to just use different registers for posting the time by the slave and have the holding registers reserved to be written to by the Master. In a previous implementation in C ( ... please forgive me) I used to listen to the traffic and parsed each message coming in in order to determine whether (a) my device was queried and (b) which function code was used for which registers. Based upon the info I decided whether to just send back the current time of the slave to teh master or take the incoming time value and set the time of the slave.

How would I implement something like this in Labview? Or am I better off just having different registers for reading from and writing to the slave?

Volker  
0 Kudos
Message 3 of 5
(5,044 Views)
Volker,

I do not know of a good way to monitor and parse the traffic like you described.  You might be able to drill down into the modbus VIs until you find where communication occurs and work from there, but it seems like it would be more work than it's worth.  I don't see a problem with using different registers for reading and writing.
0 Kudos
Message 4 of 5
(5,026 Views)
Devin,
you are right, seems that using two different registers is the most efficient way to implement what I am trying to do.
Thanks for your input.
Best regards,
Volker
0 Kudos
Message 5 of 5
(5,007 Views)