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: 

Send array of numbers through serial port - Write VISA

Hi, I am facing a problem and I have been many hours trying to solve it but no luck. Well first of all, I have implemented a PID on arduino and everything works good. During real time execution, I am being able to send 6 parameters throught the serial monitor(kp,ki,kd,setpoint, MODE, Manual_Control). I am sending it with spaces between each other, for example: 1.2 2.74 0.4 -45 0 0 . Well you can see this in the first image I uploaded. Using that way, everything works fine.

 

Now, my objective is to send those parameters through labview using the serial port. I have researched a lot and finally did my labview program, but it doesnt work. For example, if i send 1.2 2.74 0.4 -45 0 50 (its in manual mode and im sending a 50% to the motor), the arduino receives 100%. This also happens for example if i send 20, 30 etc... Well I have thought that maybe it can´t be sent the way I did it and I need a conversion to another code or something. If you don´t understand something of the code let me know!!

 

I would like to send the parameters only once each time I click a botton. I am not really sure if I have done it the right way too...

 

Well I am uploading the file and pictures of the front panel and block of diagram.

 

I hope someone can help me out to solve this....

Thanks!!

0 Kudos
Message 1 of 8
(5,414 Views)

1 picture was missing, here it go.

0 Kudos
Message 2 of 8
(5,410 Views)

Hi killernur,

 

when you want to send new data only once you click that button you should use a latching operation mode for that button!

 

I recommend to use a format string like "%#f" to match the example string shown in that Arduino picture…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 8
(5,400 Views)

You don't have the VISA Resource wired between the Case Structure and the While Loop's shift register.


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 8
(5,399 Views)

I took the liberty of cleaning up your VI.  Somethings that will help you a lot:

  1. Try to keep the wires clean.  It makes things a lot more readable and makes it easier to find stupid mistakes.
  2. Use the Event Structure to react to button presses.

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 5 of 8
(5,383 Views)

Hey, thanks both that was good. I am uploading the new block diagram picture. However, I am not sure if this will be working so tomorrow I will test it and give you a feedback.  If you have anything more to contribute, it will be welcomed.

 

Well, I also did a VI for reading from serial port and it worked well. My idea for tomorrow is to have reading and writing in the same VI. I thought of having the reading part at 5ms and the writing part at 100ms for example, as it is not necessary a continously write(I will only send a write when I click WRITE botton). So the idea was to make 2 while loops.

 

Do you think this is possible? Do you have any suggestions so I can avoid mistakes tomorrow?

 

Thanks again and here I am uploading the Reading file with its picture.

Download All
0 Kudos
Message 6 of 8
(5,373 Views)

As long as your Arduino is sending the termination character at the end of the message, change the number of bytes to read to something rediculously high, like 100.  The VISA Read will stop when it finds the termination character.

 

You also don't need the loop timer when you are reading.  The VISA Read will limit the loop rate enough for you.

 

When you make the two loops, put the Stop Button's terminal in the read loop.  The Event Structure will get the value change event to stop the write loop and the terminal value will stop the read loop.

 

For the parsing of the read data, you could wire in a 1D Array of doubles into the SpreadSheet String To Array function's type.  Then you will get a 1D Array out and the Index Array will become a lot simpler.  You can expand the Index Array to show 2 elements.  Leave the index inputs unwired and you will get your two values out (defaults to index 0, then 1, etc.).


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 7 of 8
(5,324 Views)

i have a problem in my code 
i want to send numeric array contain of 500*10^3 element when i send i have error message memory is full
i want a way to make asynchronous 
and send this array by use USB to TTL

0 Kudos
Message 8 of 8
(3,720 Views)