From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
06-23-2021 11:58 AM
We have something like mcduff's code in our libraries. We communicate with a device that doesn't really have a well defined protocol and we can get responses of varying unknown lengths. There fore we read a single character using our maximum data timeout (we don't use bytes at port) and once a character is received we read large blocks with a very short timeout. Once we get a timeout we assume we have received all of the data. It is not full proof but with a few tweaks over the years it has worked well for us. It would be nice if the device had a better protocol but this is what we have to work with.
06-24-2021 12:06 PM
Just in case someone ends up working with the Sutter MP-285 stage motion, here is what ended up working.
Here is generic send and receive:
Here is the one that gets the current position:
This is the move program that has a while loop to compare the current position with the desired final position :
Here is the comparison Vi (you don't actually need the =0 check but I inverted the z axis for our specific purposes so I often get -0 which isn't equal to 0:
I've attached all the actual code. I hope this saves someone a headache.
-Émilie
06-24-2021 12:17 PM
It is never a good idea to test for equality when using floating point numbers. You should always compare against some tolerance. You could end up with two values such 1.000000 and 0.999999 which will always fail an equality test.
06-24-2021 12:42 PM
so I should substract one from the other and make sure it's absolute value is smaller than 0.5 or something?
06-24-2021 12:58 PM - edited 06-24-2021 01:00 PM
@emime wrote:
so I should substract one from the other and make sure it's absolute value is smaller than 0.5 or something?
Yes. You can also use the in range function and negate your tolerance.
06-24-2021 01:03 PM
You could also multiply both the number and the number to compare to by the 10^(decimal places to compare to), round them and do the comparison using the integer results.
06-24-2021 08:23 PM
You can also greatly simplify some of your code if you use the Unflatten From String (when decoding the data) and the Flatten To String (when encoding the data). Both of those functions have an input for Endianness. Set those to be "Little Endian". That will eliminate all of your Swap Bytes and Swap Words.