Loading Data Into Empty Channel


Recommended Posts

Is the following code snippet a valid way of adding data to empty channels. The snippet would be incorporated within a startup sequence. Reason: I have an application that references channel names in functions but some of the channels are not currently active so the sequences stop working with an error such as "One of the parameters was empty". The #Hst is set to 10 for the all the channels.


 


 


global timer1 = sysTime()


 


while((sysTime()-timer1)<5)


      TempSensor101.AddValue(0)


      TempSensor101.Time = sysTime()


 


      TempSensor102.AddValue(0)


      TempSensor102.Time = sysTime()


 

      TempSensor103.AddValue(0)


      TempSensor103.Time = sysTime()


 

      TempSensor104.AddValue(0)


      TempSensor105.Time = sysTime()


 

//etc


//etc


endwhile


Link to comment
Share on other sites

Kind of and no.

 

TempSensor101.addValue(0)

 

is a valid way to stick 0 into your TempSensor101 channel.  The timestamp for that value will be the time that statement is executed.

 

But I don't see why you are doing it in a loop.  You only need one value in the channel in most cases.

 

The no part is that you can't do:

 

tempsensor101.time = systime() 

 

if tempsensor101 is a channel.  It works for variables, but to maintain the prestine nature of incoming data, DAQFactory does not allow you to edit it directly once the data is there.  So once you do addValue(), you can't go back and change that particular value.

 

Finally, the easiest way to do this is to simply set the Persist column of your channel to the same value as your #Hst.  Then the history from one session will still be there when you restart DAQFactory.

Link to comment
Share on other sites

Thank you for the reply.

 

I've noticed that a single line of code (as per below) in a startup sequence 

does not add any data to the channel if the #HST = 10. It does however add data if the #HST = 1

 

//////////////////////////

TempSensor101.AddValue(0) 

//////////////////////////

 

 

If I change the code in the start up sequence to the following: -

 

//////////////////////////This adds the 10th value to the TempSensor101 channel if #Hst = 10. 

TempSensor101.AddValue(0) //1

TempSensor101.AddValue(0) //2

TempSensor101.AddValue(0) //3

TempSensor101.AddValue(0) //4

TempSensor101.AddValue(0) //5

TempSensor101.AddValue(0) //6

TempSensor101.AddValue(0) //7

TempSensor101.AddValue(0) //8

TempSensor101.AddValue(0) //9

TempSensor101.AddValue(0) //10    This 10th value is added to the TempSensor101 channel if #Hst = 10. The channel will now have one value at [0] 

//////////////////////////

 

The while loop just avoided the repeated lines above.

 

 

The TempSensor101.Time = sysTime() line of code in my post was a mistake, sorry.

 

The reason for wanting to do manually add the values to the empty channels is that I may not have access to the PC that will be running the modified DF application. If I did have access to the PC I would be able to add the values myself using something like the "SimplyModbus" test program during the DF application test. Approx. 50 sensors have been added to the System. I don't want my DF program failing to start during commissioning because no data is in the NEW channels. Also, during the commissioning stage there is no guarantee that the 50 new sensors will be working correctly initially (connection errors etc.).  

 

Note: My DF program has all channels set to #Hst 10 and Persistance to 3144960
Link to comment
Share on other sites

I'm sorry.  I thought your history length was 10.  I now realize you meant the history update interval.

 

I personally would do it this way: first I'd put all the channels I needed to initialize to 0 into a channel group, say the "initMe" group.  Then I'd write this script:

private string channelList = channel.listall("initMe")

for (private i = 0, i < numrows(channelList), i++)
   while(evaluate("isEmpty(" + channelList[i] + ")"
      execute(channelList[i] + ".addValue(0)")
   endwhile
endfor

You might want a delay(0.01) inside, or run the sequence at priority 0.

 

Note you can also make this fancier (and more flexible / scalable) by storing the desired initial value in, say, the OPC specifier column or the notes 2 column.  Let's say you want to use the OPC specifier since you don't need that for your device driver:

private string channelList = channel.listall("initMe")

for (private i = 0, i < numrows(channelList), i++)
   while(evaluate("isEmpty(" + channelList[i] + ")"
      execute(channelList[i] + ".addValue(strtoDouble(" + channelList[i] + ".strSpecifier))")
   endwhile
endfor

You can also make a default of 0 if the specifier is empty:

private string channelList = channel.listall("initMe")

for (private i = 0, i < numrows(channelList), i++)
   private val = evaluate(channelList[i] + ".strSpecifier")
   if (val == nan())
      val = 0
   endif
   while(evaluate("isEmpty(" + channelList[i] + ")"
      execute(channelList[i] + ".addValue(val)")
   endwhile
endfor
Link to comment
Share on other sites

Archived

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