spy_theod Posted June 24, 2011 Share Posted June 24, 2011 Hello to everyone, When writing code I usually test it by simulating a slave device. In order to do so I need some variables with history points. But when I use a math routine to add values to a virual channel I see that the timestamp is not updated. for example While(1) Minute=(Minute+1) if (Minute==59) then delay(1) Minute=00 endif v.meas.AddValue(v.meas.AddValue[0] * 100) Delay(1) endwhile How will my virtual channel have the correct timestamp? Thanks in advance. Link to comment Share on other sites More sharing options...
AzeoTech Posted June 24, 2011 Share Posted June 24, 2011 OK, first, since its real important and I get on everyone's case about it: watch your indentation. Second, you don't really need to use addValue() with V. channels. Just do V.meas = Third, you don't want v.meas.addvalue[0], you want v.meas[0] Finally, the reason the time stamp isn't updating is because there is already a timestamp in the value you are trying to add to the channel. DAQFactory only puts a timestamp on a value when there isn't one available already. You can force a timestamp either by using .time or inserttime(). So either: private x = v.meas[0] * 100 x.time = systime() v.meas = x or: v.meas = inserttime(v.meas[0] * 100, systime(), 0) Note that you can't do: v.meas.time = Once values are in channels, whether V or regular, you cannot edit them. Link to comment Share on other sites More sharing options...
spy_theod Posted June 30, 2011 Author Share Posted June 30, 2011 Thank you very much. It works fine. But what do you mean by this: "watch your indentation" ? Link to comment Share on other sites More sharing options...
AzeoTech Posted June 30, 2011 Share Posted June 30, 2011 You should indent whenever you have a block level command. This would include while(), if(), for(), try(), switch() and a few others. You indented correctly for the if(), but forgot to indent for the while() so I almost missed it when I first looked at the script. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.