mmi - thanks for looking at this.
I’ve been trying your code out, but still having issues, which are likely related to the details of how the gage actually stores & releases data.
I took your code, and made the following adjustments:
- pulled the thread out of the middle and put it at the end
- The rest of the code is within a function – “read_gage_test”
- the gage ID parameter passed to the serial read & write functions is actually “sog” rather than “gage1”
- I placed an “end” statement between the sleep and kill statements, as otherwise the write/read sequence was repeating (sometimes indefinitely, sometimes stopping after 10 - 50 cycles).
- Added the gage_write_count variable to track the write/read sequence.
So, here’s my version of your code:
def read_gage_test():
global flush_counter = 0
global gage_write_count = 0
prev_flush_counter = flush_counter
flush_gage_buffer_th = run flush_gage_buffer()
sleep(0.5)
/# each individual read should not take more than 0.5 seconds, so loop can tell that
/# background thread is still reading buffered messages
while(prev_flush_counter != flush_counter):
sleep(0.5)
end # ** inserted to end the while loop here
kill flush_gage_buffer_th
serialWrite("sog", "M1?") #trigger gage
gage_write_count = gage_write_count + 1 #***** track progress here
global gagestring = serialRead("sog") #read the desired output string
end
thread flush_gage_buffer():
while True: #start loop to read/flush unwanted strings
serialRead(“sog”) #read unwanted string from gage
flush_counter = flush_counter + 1
end
end
and here’s the Polyscope program:
Questions:
- Is anything I did above different from your intent with that code?
- Should there be a sync() within the thread? - I’ve tried with and without, doesn’t seem to make a difference.
Unfortunately, when I run this program, I still don’t get the expected results:
If the gage buffer is empty when I start this program, the flush_counter is zero and the gage_write_count variables goes to 1, but I don’t get anything in the gagestring variable (it’s not even created in the Variables window), and the program still hangs. Multiple write commands don’t seem to make a difference.
I had a slightly different version of this code which would give me values - not always the string I was looking for, which depended on me using the gage’s trigger button before running the program - I’ll try to remember what that code version looked like to get a better picture of what’s happening.
I also occasionally get an error which says “Unable to transport XML to server and get XML response back” with the URCap info attached.
It’s looking like there are details within the gage and URCap which still need to be fleshed out.
I’m waiting for ourinternal URCap programmer to get back to me, and hopefully I’ll hear from the Mahr tech guy in Germany - was apparently out on vacation last week, hopefully is back this week.