LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem reading data from arduino with visa read

Solved!
Go to solution
Highlighted

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
(202 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
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

0 Kudos
Message 2 of 28
(185 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
(181 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
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

0 Kudos
Message 4 of 28
(177 Views)

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

0 Kudos
Message 5 of 28
(171 Views)

Hi Reiza,

 

just try it!

(After cleaning up the whole VI!)

Best regards,
GerdW
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

Message 6 of 28
(165 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
(161 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.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 8 of 28
(145 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
(140 Views)

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

0 Kudos
Message 10 of 28
(133 Views)