03-10-2023 06:12 PM
I am decently new to LabVIEW and am attempting to make an RC Plane motor test stand that will output values of RPM, Thrust, and Input Electric Power as supplied from an Arduino MEGA 2560. I have uploaded my VI that I am using to test the interaction between the Arduino and attached a picture of the test code (can't upload a .ino); this works for the most part except for my second VISA write function not being correctly read by the Arduino. I know that my VI is writing the data to the Arduino by using an indicator off the VISA Write VI return count parameter however the Arduino returns "1.00'\n'" when it should be returning the value as set by the gauge control on the front panel.
If anyone has any experience using two serial write functions with Arduino that would be very helpful as I believe that it may be because the String buffer is not properly clearing after the button read but I'm not sure since everything online says that the Serial.read() function removes the byte value from the buffer. Some of the code that I have tried to fix this has been commented out for an indication as to what I have tried.
Solved! Go to Solution.
03-11-2023 07:45 AM
It looks like you hae a race condition in your communications. In your Arduino code, you read until a 1 is read, send back a "1" and then immediately check for new data. But if the LabVIEW side hasn't even read the initial response yet and send the next packet, the Arduino will miss it due to the while(serial.available>0).
I think you are making the protocol too difficult. Have the Aduino just read for the RPM setting. If the is data, respond. If not, send updated data. On the LabVIEW side, only send the rpm when it changes.
You also should not need the Serial.flush() in there. It just slows your code down.
03-21-2023 11:42 AM
Thank you for explaining that to me; I am unsure however, if it was the race condition that was causing the incorrect output as after simplifying the VI and the Arduino code I was still unable to get the correct output. I ended up switching the string concatenation method from effectively .concat((char)Serial.read()) to rpmString = rpmString + String((char)Serial.read()) and this ended up working.
Again thank you for giving me some insight into how the program was working.