How to update modbus slave value


Recommended Posts

My first try at DF and not having much luck. I need to -

1. Aquire an OPC value - no problem here

2. when the OPC value changes I need to convert the value to a signed 16 bit integer and update the value of a modbus slave register with that value.

I think I have the modbus slave channel created but i can't seem to force a value into it.

The OPC point after conversion applied will always be less than 32768

I think the opc point event code should look something like:


MODBUS1001 = from.word(opcvalue[0])


but this doesn't do anything....

Link to comment
Share on other sites

OK, lets first be clear: is the device you are trying to send this data point to acting as the Modbus Master or the Modbus Slave? How this is done depends on your answer. If your device is a Modbus Master, then you need to set up DAQFactory as the slave by creating a new serial device with Modbus Slave protocol selected, then assigning a tag number to the OPC channel (opcvalue?). For signed 16, use tag #1. The thing is, since DAQFactory is the slave, it will only send the value when your device, the master, requests it.

If your device is the slave, then its a bit easier. Create a regular modbus device, create an output channel on it, then in the event of your opcvalue channel, put:

Modbus1001 = opcvalue[0]

On a separate note, there is only one numeric data type in DAQFactory, so "convert the value to signed 16 bit integer" doesn't really apply. You just need to scale the value to ensure it fits in the range of -32767 to +32767, and then if you want to be meticulous, use the floor() function to strip any fraction.

The from.word() is not designed for what you are trying to do. It is designed for manipulating arrays of bytes.

Finally, you should NEVER do the script you sent. This is an infinite loop without any delay and will result in the computer spending all its time trying to set Modbus1001 to opcvalue[0], and will likely hang the computer. If you put it in the event, there is no reason for a loop, since the timing loop on the opcvalue channel is the loop. Actually you really never want loops of any sort inside of events because they slow the event down and events should always be fast, otherwise they slow other things down.

Link to comment
Share on other sites

thanks for the quick response.

Daq factory will be the modbus slave, modbus over TCP, device 1, port 502.

I don't understand the while(1) construct but that was the syntax of the user manual examples for channel events. I'll avoid the infinite loop.

Link to comment
Share on other sites

That's because there is no such thing as a modbus slave channel. The modbus slave device works differently than other devices because DF doesn't instigate the polling. You simply create a modbus slave device attached to the appropriate port (in this case, an Ethernet server on port 502 with Modbus TCP slave). Then, you'll find there is a separate column in the channel table for slave #. This is the tag # for that particular channel. When the master asks for that tag #, the last value of that channel is returned. That is all you have to do. Again, remember, if the other device is the master, than it must instigate the query. DAQFactory can't update a Modbus Master on its own.

I would also look at the monitor for your port and make sure the master is actually sending queries.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.