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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem reading data from arduino with visa read

Solved!
Go to solution

hello, I'm Reiza

I really need a help for my last project. I have to control arm robot Dobot Magician with arduino mega and use labview as the interface. I have to doing a communication serial with labview to sending real time posisition of my arm robot. I do it by using visa read to read serial data from arduino, but the visa read buffer can't always read the data. When I run serial monitor in Arduino, the posisition data is sent normally but when I used the labview, the data won't updated real time, the data changed until I pressed a button in my interface few times. Anyone can tell me how to solved this problem ? I'm very new in labview and I really need some help. I'll attach my program below

 

thank you

0 Kudos
Message 1 of 28
(3,061 Views)

Hi Reiza,

 

get rid of that event structure to solve your problem…

 

And rework the whole VI to eliminate all those race conditions!

(Most of that VI is silly, from that CPU-hogging additional loop to using BytesAtPort…)

Best regards,
GerdW


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

thank you for your response, but I dont really get it what I supposed to do. The event structure that I used is just for sending serial data to controlling the Dobot and nothing wrong with that, the Dobot can controlled. The problem is the labview can read data from arduino

 

0 Kudos
Message 3 of 28
(3,040 Views)

Hi Reiza,

 

The event structure that I used is just … and nothing wrong with that

That event structure is actually blocking your loop because there is no timeout set.

That's why you have to " press a button in my interface few times"!

Best regards,
GerdW


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

so if I set the timeout in the event structure, it will be ok ? 

0 Kudos
Message 5 of 28
(3,030 Views)

Hi Reiza,

 

just try it!

(After cleaning up the whole VI!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 28
(3,024 Views)

If I gonna change the VI to send command with serial data via visa write, what method that will you suggest to me for my VI ?

0 Kudos
Message 7 of 28
(3,020 Views)

@Reiza wrote:

If I gonna change the VI to send command with serial data via visa write, what method that will you suggest to me for my VI ?


I would start by having a good look at the Producer/Consumer and Queued Message Handler.  The idea is to break up your code into multiple loops that talk with each other through Queues.  This will modularize your code into simple chucks that do 1 specific thing.  I would have a GUI loop, Logging loop, Data Processing loop, and an Instrument Communications loop.  You can very easily get rid of all of your local variables this way, which will makes things A LOT more efficient and easier to understand.


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
Message 8 of 28
(3,004 Views)

you're right, the problem is in event structure's time out and I find another problem. I assume that visa write and visa read can't work in the same time. In my program, when I set the timeout, visa read looks like waiting for the visa write's timeout and the problem is visa write and visa read have to work in the same time in my program. So what should I do next ? 

0 Kudos
Message 9 of 28
(2,999 Views)

can I use visa duplicate session to make visa read and write work at the same time ?

0 Kudos
Message 10 of 28
(2,992 Views)