Bardownski Posted December 6, 2023 Share Posted December 6, 2023 Hi, I am looking for some scripting help. I have data properly passing through the Comm port with a null protocol. (see image below) The data is repeating (100 ms) in 13 byte intervals with no carriage return. The data in the first Byte (\x86) is a constant. I am trying to pass this data into variables in DaqFactory which I can display/log/etc. Most of the help I have found uses the "device.myDevice.readUntil()" which I have been unsuccessful at using Would someone be able to push me in the right direction? Thank you in advanced. Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted December 6, 2023 Share Posted December 6, 2023 Actually, readuntil() would probably be the best choice. You'll want to readuntil(0x86), then make sure you have 13 bytes, then parse it, so something like: private string in private bin while(1) in = device.mydevice.readuntil(0x86) bin = asca(in) if (numrows(bin) != 13) continue endif // now you can parse bin, which is an array of numbers. Note that 0x86 will be at the end, not the beginning. endwhile Two notes: 1- I actually have forgotten if readuntil() also returns the value you are reading until, so the returned length might be 12 and no 0x86 at the end. 2- you do not need a delay() inside this loop, though you may want to add one (delay(0.1)) right after the while() until you are sure you don't have any typos. You don't need the delay() because DAQFactory will essentially delay on its on while doing the readuntil(). If you introduce a delay that causes DAQFactory to loop slower than your device is spitting out data, it will fall behind. Quote Link to comment Share on other sites More sharing options...
Bardownski Posted December 6, 2023 Author Share Posted December 6, 2023 You are the best! Exactly what I needed. I also added a device.mydevice.purge() I do appreciate it! Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted December 7, 2023 Share Posted December 7, 2023 Yes, a purge is a good idea before the while(). I do not recommend it inside the while or you will miss a lot of frames, possibly most or all of them. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.