LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Continuously Read/Write Array To/From Serial Port

Hello,

 

I am looking for help to continuously read/write an array from the serial port. I have a script on an Arduino that continuously read/writes arrays from the serial port which will then execute particular commands depending on conditional statements.

 

Attached are what I have so far. It quasi works, but I am currently making two separate arrays it seems. I can read in arrays from the serial port just fine, writing arrays (editing 1 element) is where I am struggling. I can also write to single elements in an array (right side of front panel) but it won't show up on my read in (left side).

 

Example End Goal:

(1) Labview reads array continuously, elements being things such as (PWM_1, Temp_1, PWM_2, Temp_2) (need help)

(2) User can then write to the array to change elements such as PWM_1 (need help)

(3) This changed array will then be read by Arduino, executed, and sent back over serial to be updated by LabView (complete)

 

Thoughts?

 

Thank you,

Nathan

Download All
0 Kudos
Message 1 of 11
(2,130 Views)

This sounds like a homework assignment. You should at least post what code you have and what specific problems or question you have. No one here is going to write the code for you.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 11
(2,127 Views)

Ok...?

 

Please see above Mark.

 

Thanks,

Nathan

0 Kudos
Message 3 of 11
(2,118 Views)

Also the middle panel, "Command Terminal"  is something I was using earlier and can be ignored. Originally, I was using this area to write an integer (instead of complete arrays) to the Arduino which would then execute the command. 

0 Kudos
Message 4 of 11
(2,110 Views)

Why 2 reads,  and what is that feedback node supposed to be doing?


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 11
(2,109 Views)

The right most read is a byproduct of an old build where I was sending a single command (not an array) at a time. I should have deleted it, but I haven't. Shouldn't negatively affect anything. 

 

The feedback node iterates the array? But I'm not 100% sure, I only have it in there because that's how the example I found did it... 

0 Kudos
Message 6 of 11
(2,106 Views)

What is the protocol that the Arduino is expecting? You should have some documentation indicating what the Arduino is expecting to receive as well as what it is writing. Generally this data will be terminated with a line feed or some other termination character. Your reads and writes should include that. As configured now your read will read 1000 bytes or up to a line feed character, whichever happens first.

 

Do you have an example of the expected data from the Arduino?

 

Given that your front panel lists specific commands, how is each command formatted? Also, I doubt you want to continually write commands to the Arduino. I would think you only want to write the commands at specific times such as when you want to turn the laser on or off. You will continuously read for the status if the Arduino is indeed continually sending data. Or does it only send data in response to a command?



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 7 of 11
(2,102 Views)

I don't have a formal protocol in place yet, that's for later down the road. As of now, I serial.read() any integer or "-" sign and set that as a variable, X. I then go through conditionals that "turn on laser" (changes PWM to 100) if X == 71 for example.

 

After the conditions are complete, I then iterate through an array and serial.print the new values of the array. So if the Arduino receives the 71 command it changes an example array from (var1=1, var2=2, PWM=0) to (var1=1, var2=2, PWM=100). The print function sends it as 1,2,100 \n and then Labview breaks out the numbers using "," and restarts using \n.

 

Expected example data from Arduino: 3.3, 24.00, 255.00, 0.00 /n  (repeats continuously)

How each command was formatted: "71" *click write button* (no longer there, used to be to the left of Serial Read)

 

I do want to continuously write (unless there's a better way). This is because I am also using LabVIEW to process photo-detector data of the laser so that I can shut it off if things go poorly. 

 

Arduino is always sending data because it is reading temperature that needs to be seen on Labview. 

 

Hope that answers your questions,

Nathan

0 Kudos
Message 8 of 11
(2,067 Views)

Example expected data from Arduino: 3.3, 24.00, 255, 0 \n (continuously sending)

 

The commands can be ignored, that was from my first build. I would type in the command in a, now deleted, write terminal then click write. The Arduino would then read in the command and iterate through conditionals to execute it.

 

I do want to continuously write (unless there's a better way) because I am also using LabVIEW to process photo-detector data and turn the laser off if particular limits are met. 

 

Arduino continuously sends data because I want to monitor temperature.

 

Hope that answers your questions.

Nathan

0 Kudos
Message 9 of 11
(2,085 Views)

Do you actually want to write continually or only when certain conditions occur? What you basically need is a state machine to control your logic and your operations. One of the actions you would take every iteration would be to read data from the Arduino. Others would check your conditions and then take action (write a command to turn off the laser, for example) if a condition was met. Take a look at some of the example code for state machine or the producer/consumer pattern. This will help to control the logic of the application. 



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 10 of 11
(2,083 Views)