Monitoring a Channel at different Time Intervals


Recommended Posts

I am trying to monitor the same modbus channel at different time intervals. I am trying to monitor the channel at a 1 minute interval to update a current value table. Then every 15 minutes I would like to write the data to a database containing the points. I tried to setup two different channels at different timing intervals, but it appears the 15 minute channel is getting populated at the same frequency as the 1 minute intveral. I would like to stay with channels/timing instead of reading the variables directly. I am using conversions and this allows me to keep the code simple. Any advise would be greatly appreciated.

Thanks

Tracy

Link to comment
Share on other sites

Modbus, and most other devices are tagged by their D#, I/O type and Channel #, not their name, so you can't create two channels with the same D#,I/O Type and channel # with different data rates. You get what you see, data coming back and ending up in both channels.

Is your goal to simply log at 15 minutes, but take data at 1 minute? If so, just create a logging set with Fixed Interval / Snapshot and an interval of 900 seconds.

Link to comment
Share on other sites

I thought about that but I using a remote MS SQL database for data storage. This presents a problem for the logging set in that I have to use "DSN" less connection (and using OpenEx) to access my database. In addition, I have not figured out how to get around the two day time differential when using logging/export sets with MSSQL. Otherwise a logging set would perfect. Is there a work around for these two issues?

Link to comment
Share on other sites

I don't know about the dsn less connection. I've not seen a problem using logging sets to access mssql. The big issue, as you said, is the two day offset. I don't know why MSSQL is off from Excel by two days, considering they are both microsoft products. Anyhow, we have a workaround for that one. It takes one line of script:

logging.mylog.timeoffset = 86400*2

It might be -86400*2. I can never remember which way the offset goes.

If you are using db.openex() anyway, you could use db.execute() to write each line, and just do it in a simple loop in a sequence. This gives you total control.

Link to comment
Share on other sites

Here is the connection string that I have to use to get the database to connect remotely:

global string ODBCName = "Driver={SQL Native Client};Server=mydatabase.com;Database=my_database; Uid=My_UID;Pwd=my_Password"

I open the database using

Handle = db.OpenEx(ODBCName)

I was unable to get all of the database functionality to work with a standard DSN connection. The above works flawlessly. Is there a way to get a logging set to use the above string. I will see if I can get logging to work with the standard DSN. The other fix should work fine if I can get the DSN to work.

Thanks

Tracy

Link to comment
Share on other sites

You are basically bypassing DSN. The logging set isn't that flexible. When you need that amount of flexibility you have to drop into script. I would just use script to log anyway. You only need to figure out how to format the SQL update() statement, which is pretty easy to do. Then its just a while loop with a delay() in it.

Link to comment
Share on other sites

The original reason I want to use channels was to ensure that I was actually get a new value. If the connection fails, I am afraid I would be writing the same value to the database each time the event was triggered. If I use events I am assured to only write data when it is valid. I am worrying to much, or is there a simple way around this?

Thanks

Tracy

Link to comment
Share on other sites

Whether you are worrying too much about it I can't address. It really depends on the application. As for a way around it, you can just look at the age of the data point using the last data point time. For example:

if (systime() - mychannel.time[0] < 60)
   // data is new, log it
endif

Personally, you can pretty easily cycle through the channels and build up your SQL string checking for the time the whole way, and writing a NULL value or something if its old. In this case, use the inline if: iif()

private string out

out += iif(systime() - mychannel.time[0] < 60, mychannel[0], "NULL")
out += ","
out += iif(systime() - myotherchannel.time[0] < 60, myotherchannel[0], "NULL")

// etc.

I didn't exactly create a SQL string there, but you get the idea.

Link to comment
Share on other sites

Archived

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