Synchronization Troubles


Recommended Posts

Hello,

I have recently hooked up a device to my computer using the serial port. I am reading the data from the comm port using a while loop that is timed every second. In addition I have the outrate from my device as one second. So the device is sending data to the comm port every second, and I am looping every second. The problem is that I am displaying the current values parsed from the incoming string, but there are times when the values are not correct. This has to do with the synchronization of the sequence. I am not sure what is happening, but I know the timing is wrong. Basically the values will change every second on a page, but then they become unsynchronized, and display values that do not correspond to what the device is sending. So for instance, I have a variable display on a page for the test channel testchan1. Now testchan1 will change every second, but the values are similar. So it is initially 1.4567, then 1.5647, then 1.4789, and then 6 seconds later it will read -0.4567 which is incorrect. This happens to all the test channels being displayed on the page. How do I synchronize the read function in the loop with the outrate from the device? I have copied and pasted my sequence code below. I have tried the delay function, but to no avail. Any suggestions?

global string strIn0

global string strIn1

global string strIn2

global string strIn3

global string strIn4

global string strIn5

global string strIn

global test0

global test1

global test2

global test3

global test4

global test5

while (1)

try

strIn = Device.LI820.ReadUntil(13)

strIn0= parse(strIn,0," ")

test0=strtodouble(strIn0)

testchan0.AddValue(test0)

? testchan0[0]

strIn1=parse(strIn,1," ")

test1=strtodouble(strIn1)

testchan1.AddValue(test1)

? testchan1[0]

strIn2=parse(strIn,2," ")

test2=strtodouble(strIn2)

testchan2.AddValue(test2)

? testchan2[0]

strIn3=parse(strIn,3," ")

test3=strtodouble(strIn3)

testchan3.AddValue(test3)

? testchan3[0]

strIn4=parse(strIn,4," ")

test4=strtodouble(strIn4)

testchan4.AddValue(test4)

? testchan4[0]

strIn5=parse(strIn,5," ")

test5=strtodouble(strIn5)

testchan5.AddValue(test5)

? testchan5[0]

catch() // catch any comm errors and ignore

delay(.1)

endcatch

endwhile

Thank You,

Paul

Link to comment
Share on other sites

I'm guessing you forgot to set the Timing of the channels to 0. In almost all cases when using AddValue() you want a Timing of 0 on that channel. In the case of test channels, if its not 0, it causes the test device driver to be called. That driver simply generates sine waves based on the current time, so will generate a number between -1 and 1. This is getting intermingled with the data coming from your sequence. If you set the Timing to 0, this will stop.

Link to comment
Share on other sites

Archived

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