Sending database values to Modbus device

Hi,

How’s the easiest way to send a database stored value to a device?
I want to implement a commands queue in a database table. Each time an record is inserted in the database, the value in that record to be sent to the device.

Thank you,

Arian

I think the easiest way to accomplish this is through scripting. The tricky part is to remember which record you sent to the device last. Try doing the following:

  1. Add a new DB tag that is called lastId with an integer data type. Make the default value 0.

  2. Add a new timer script in the Event Scripts Gateway. That way it runs in one location on the gateway. You can set the rate to whatever you want. Keep in mind that the script will run a SQL query at the rate you specify.

  3. The code looks like this:lastId = system.tag.getTagValue("lastId") rs = system.db.runPrepQuery("SELECT id, valueToWrite FROM valueTable WHERE id > ? ORDER BY id DESC LIMIT 1", [lastId]) if len(rs): system.tag.writeToTag("Path/To/Tag/In/PLC", rs[0][1]) system.tag.writeToTag("lastId", rs[0][0])Let us know if you have any questions.

Thanks Travis,

It works fine, I’ve just added a new SQL to delete the command from the table after that.

Arian