SQL Logging with sequence


Andreschrosa

Recommended Posts

I want to store the equipments' readings over different sql tables inside my database. I didnt figure a way to do it using the logging sets aside from creating a log set for each equipment.

Is it possible to create a loop sequence that gets the channels' data and sends it to the sql database? This way I can create tables dinamicaly for each equipment in the network.

I'm thinking of something like this:

while(continue)
for(private.i=1,i<NETWORK,i++)
   sql = "Insert into equipments_"+curnet+ " (Vm, V1, V2, V3) values (channel.Vm_"+ curnet +", channel.V1_"+ curnet +", channel.V2_"+ curnet +",channel.V3_"+ curnet +")"
endfor
endwhile

NETWORK is a define which stores the number of equipments in the network.

continue is controlled by a button to start stop logging.

The only problem I see is how to ensure that all channels are being sent to the database like the logging set does? Just one big sequence loop running the length of the network will do it properly?

Maybe creating a logging set for each equipment will be a better solution... they will be acessing the same database however.

Link to comment
Share on other sites

Well, you are missing the database commands. They all start with db. You'll need, at minimum, db.open() before the loop, db.execute() for the insert, and db.close() outside the loop. If you were doing a SELECT query, you'd need db.query among others.

Do you mean all channels or all values in a channel? Really, the only way to ensure that channel timing and sequence loops sync up is to actually not use the channel timing and do the channel reads from within the sequence.

Link to comment
Share on other sites

Sorry forgot to write the DB commands, I was in a hurry.

I meant all the channels, say one network has 30 equipments connected to 9 rs485-ethernet converters, so it makes up for 9 communication devices, each having approximatelly 3 equipments on then. Each equipment can read around 20 variables.

Using logging sets I would need 9 sets (one for each rs485-ethernet converter).

My consern with doing this logging using a sequence is if those 20x30 = 600 (possible) channels wont take too long to record vs the use of the DAQFactory build in logging.

Link to comment
Share on other sites

The logging part wouldn't take much longer. You'd have to build up a pretty long SQL statement, but it should just be a for() loop. The real difference would be in the polling. If you use Offsets, you can get the channels to poll each converter simultaneously. With a single sequence, it would have to do them one at a time, however, you could create a separate sequence for each of the 9 converters and then simply wait for them to finish before logging.

Link to comment
Share on other sites

I've decided to create a logging set for each converter, I'm getting a problem starting then however.

Here's the code:

for(private.i=0, i< EQUIPNO, i++)
   execute("logging.LogSQL_"+i+".StartStop()")
   if(evaluate("logging.LogSQL_"+i+".Running"))
	  private string channellist = channel.ListAll() 
	  for(private.i=0, i<(numrows(channellist)), i++)	  
		 private channame = parse(channellist[i],-1,"_")
		 if(channame[2] == i)
		 execute("logging.LogSQL_"+channame[2]+".AddChannel(channellist[i],6)")
		 endif
	  endfor
   endif
endfor

EQUIPNO is a define variable representing the number of converters on the network.

My channels are named like this: variable_modbus_device, like V1_1_0 for device Mod_0 defined on the device configuration.

The error ocurring is that only the first logging starts (LogSQL_0).

Link to comment
Share on other sites

Two things:

1) use Start() and Stop() not StartStop(). StartStop() is designed for buttons when you want to toggle. In this case you always want one or the other.

2) I'm assuming you expect it to start. You should do your addchannel() stuff with the logging set stopped, then start it when done.

Link to comment
Share on other sites

Archived

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