LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading and writing data using Labview and Arduino via Serial VISA

Hello everyone,


I am now trying to use Labview to implement reading voltage data from a sensor on the analog port of an Arduino, then performing PID control, converting the output of the PID to a PWM signal and then returning it to the digital port of the arduino to control an electromagnet using visa write. Since I don't have the actual device yet, I can't verify that my program is correct. Now my question is how the VISA wiring should be done? Is my program connected correctly?

Lip

0 Kudos
Message 1 of 4
(357 Views)

Hi 9528,

 


@9528 wrote:

Now my question is how the VISA wiring should be done?

Is my program connected correctly?


To learn about serial communication using VISA you should watch this video.

 

To verify "correct connection" you need to debug your program. We cannot do this as long as you don't provide any code…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 4
(346 Views)

Hi GerdW,

 

Thanks for the reply, here's the code.

 

Best regards,

9528

0 Kudos
Message 3 of 4
(340 Views)

1. Do watch the video linked to above.  It will show you a lot of what you are doing wrong.

2. Do NOT use a False constant for the loop stop condition.  The loops will never stop, which means you are never doing any clean-up of the VISA resource.  Add a Stop button to your front panel and use it to stop your loop.

3. No need for the Sequence Structure.  Data Flow will dictate the run order.

4. DO NOT USE THE BYTES AT PORT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (still not enough emphasis).  I am assuming you are using the Serial.PrintLn() on the Arduino.  So just tell the VISA Read to read more bytes than you ever expect in a message and you will get the full value.

5. I do not see a need for the Producer/Consumer here.  Just do the read, process the value, and write the result back all in a single loop.

6. Due to the VISA Read waiting for a message, you do not need a wait in your loop.  The loop will iterate at the rate of the Arduino sending messages.

7. You should append a Line Feed to your message before writing it so that your Arduino can key off of the Line Feed to know when it has the full message.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 4
(295 Views)