09-07-2023 02:52 PM
Solved! Go to Solution.
09-07-2023 05:13 PM
Take a look at my answer to this question here.
Also watch this video: VIWeek 2020/Proper way to communicate over serial
09-08-2023 12:58 AM
Hi CM_N,
@CM_N wrote:
Need a help to separate the data coming from the VISA read vi so that I can display temp and ultrasonic values separately.
void loop() {// put your main code here, to run repeatedly:Serial.println(hc.dist()); // return curent distance in serialdelay(60);// temperature readfloat t = dht.readTemperature();Serial.println(t);
I see two options:
Why is there a wait between both acquisitions?
09-10-2023 07:14 AM
Hi GredW,
Thank you for your reply.
I tried the first option and I am using 'scan from string' function to separate data but the data read is not coming in the fix order it is jumping in between output one to three. Is there any way I read data in fix order? I can't use indicator like ("ultra" + hc.dist()). I am reading data in (hc.dist,tempvalue) this format which I want to process to indicate different output.
Delay mention in the code is for sensor to process the data.
Again thanks a lot for your help and support.
09-10-2023 07:53 AM
@CM_N wrote:
Hi GredW,
Thank you for your reply.
I tried the first option and I am using 'scan from string' function to separate data but the data read is not coming in the fix order it is jumping in between output one to three. Is there any way I read data in fix order? I can't use indicator like ("ultra" + hc.dist()). I am reading data in (hc.dist,tempvalue) this format which I want to process to indicate different output.
Delay mention in the code is for sensor to process the data.
Again thanks a lot for your help and support.
Post all of your code, LabVIEW and Arduino. My guess is you are not properly using the termination character.
09-10-2023 09:46 AM
Hi,
I appreciate for help me out in this. I have attached the files below please have a look. Also, as you can see in the code it is separating the only then serial is read in a particular sequency but it randomised when the program is stopped and start again meaning sometime I read temperature value first or " , " string and if you keep restarting the program then sometime it read data as intended (ultra , temp).
The Arduino code is mention below.
09-10-2023 08:33 PM - edited 09-10-2023 08:36 PM
On the Arduino side:
Why is the delay between the measurements? I would expect a delay to be after both measurements.
On the LabVIEW side:
1. Remove the wait. VISA Read will limit the loop rate by waiting for the data to come in.
2. Replace VISA Open with VISA Configure Serial Port. This way we make sure the settings are correct. It looks like the defaults will work for your situation, so you only need to wire up the VISA resource.
3. Your string format for the Scan From String should be "%f , %f" (without the quotes). This will tell the function to look for a floating point number, followed by a space, a comma, and another space, then then another floating point number.
4. What you are telling the VISA Read to read may not be enough bytes to read. I would increase that to something more like 100 just to make sure the termination character is read.
5. You really should stop your loop if there is an error.
With all that said, here is how I would clean up your VI.
09-11-2023 03:18 AM
Hi Crossrulz,
Thanks for you help. I tried the code but scan from string is giving me the error mentioned below I guess this may be because I have a " , " in my string.
Possible reason(s):
LabVIEW: (Hex 0x1) An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @.
One more guidance I would appreciate is that I if I want to use switch case in such a way the if Boolean is true it will read temperature and ultrasonic data and if false it will read humidity data. However, when I am trying to that in lab view the "scan from string" in function from both cases are reading data for output 1. I have mentioned the code below and attached the vi file too.
Thanks again for your help.
09-12-2023 04:23 AM
Hello Everyone,
Since I have figured out way to separate the data coming out of a serial port. I thought it would be good idea to post the solution so that if someone is struggling can review it and work a way around it. It might not be the effective way and I am sure, there are many more different ways to deal with it but this method works too.
So, In the labview code I am toggling Boolean manually as there is push button on the device which toggle the Serial print reading and sensors and didn't want to write any command to the Arduino and just want to read serial coming from it and lab view. Hence, I have but a Boolean such that if the push button is pressed on device, user have to manually turn Boolean true or false accordingly in labview to get appropriate reading.
Hope this helps.
09-12-2023 04:49 AM - edited 09-12-2023 04:49 AM
Hi CM,
@CM_N wrote:
So, In the labview code I am toggling Boolean manually as there is push button on the device which toggle the Serial print reading and sensors and didn't want to write any command to the Arduino and just want to read serial coming from it and lab view. Hence, I have but a Boolean such that if the push button is pressed on device, user have to manually turn Boolean true or false accordingly in labview to get appropriate reading.
So the solution is to have your user to press two buttons instead of just one - and curse you if they forgot to press the 2nd button on your UI…
Wouldn't it be much easier (better, more safe, user-friendly, …) to implement a slightly different message format on your Arduino sketch and parse that message with your LabVIEW tool automatically???