LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read Serial Data from Arduino using labview VISA?

Solved!
Go to solution

Hello everyone.

i want to write data that i take from serial port ( Arduino ) in to Excel file.

so i need to know how to do that.

i put picture of data that is in serial port and how must be saved in excel file.

so please let me know how i program it in labview.

really thanks for your help.

Download All
0 Kudos
Message 101 of 143
(2,844 Views)

Search the example finder and the forum for examples on how to read a serial port.

Spoiler
And if the examples show the use of the "Bytes at Port" property node, ignore that part.  Bytes at Port is the wrong thing to use 99% of the time.  If your serial data has carriage returns or line-feeds which it looks like it does, then you should enable the termination character and read a sufficiently large number of bytes.

Search the example finder and the forum for examples on how to write to an Excel file.  Do you want to write to an actual Excel file?  Or is writing to a text file that Excel can import okay?

Message 102 of 143
(2,838 Views)

If your sketch is using the println() command you already have a carriage return and newline termination characters built right in. As RavensFan said skip using bytes at port and just set up your read in a while loop led with configure serial port vi set to 9600 baud and com3. Basically mimic what the Arduino serial monitor settings are. When you run your vi make sure the arduino serial monitor is closed. 

Now Using LabVIEW 2019SP1 and TestStand 2019
Message 103 of 143
(2,832 Views)

Thank you for your answer. i just write it in excel file.

i searched to many example but couldn't take good result.


@RavensFan

 

0 Kudos
Message 104 of 143
(2,827 Views)

Thank you for your answer.

yes i use Serial.print()can you put here one example like what you say.

thanks

0 Kudos
Message 105 of 143
(2,826 Views)

Just a quick pointer - note that you wrote "Serial.print(...)" and the earlier post specified "Serial.println(...)"

 

The difference is in the presence of an automatic termination character from the Arduino, which is probably what you're missing to make your code work as RavensFan and GovBob suggested.

 

Edit: I read more carefully and noticed you don't seem to currently have any code. An example that probably fits the ideas being suggested can be found via the Example Finder (Help > Find Examples...) and searching for "VISA Serial" then selecting Simple Serial.vi.

If you were looking for something more modern/simple, I'd suggest using the "Configure VISA Serial Port" VI for the beginning part of the VI.

I'll post an example if I don't run out of edit time.


GCentral
Message 106 of 143
(2,822 Views)

this is program i made. but it is not working like i want. i means i cant see records in excel file and every time i run program just it make to many excel file opened ( empty ).

0 Kudos
Message 107 of 143
(2,821 Views)

Thanks for uploading code. I guess you can ignore most of my previous message.


Some ideas/comments on your VI:

  • If you use println in the Arduino sketch, you can lose the bytes at port node, and just set the Bytes to Read input to a 'large' value, longer than whatever you might read in one line (e.g 20, 50, 100...)
  • You should then at least see values in the Read Buffer
  • Why are you using Build Array, then Array to Spreadsheet string? Isn't the output in that situation the same as just wiring straight through (you only have one character there)
  • The same is probably true in your bottom leg - you have multiple characters there, but unless there is a tab in the string (the 10 characters from 16->25), the output is the same as the input
  • In the top leg, you're reading a 1 digit number and using the Fract/Exp String conversion. Use the Decimal String version instead.
  • "Numeric" is only given a value in case "2". Is that what you want?
  • You're writing to effectively an array of booleans - using an actual array would make it easier to read (and you could remove the case structure)
  • There's some reshaping and checking for linebreaks going on at the end - I can't work out what that should do without some example input - any chance you could provide some if you think that might not be behaving how you'd like (if you're sure it works, feel free to just say so)
  • When you dispose of the Report, you're not saving the report (false by default) and you're not closing. I'm not sure what the behaviour is there, but I'd try setting the Save boolean to true.

Good luck!


GCentral
Message 108 of 143
(2,815 Views)

>the number 1 or 2 or .... is OK. because i want to see just witch RFID reader worked and return it to LED blinking.

two problem i have:

1- when i run program i just want to read data that come from Serial.print(). but when i record it in labview, it start to record empty and my data together. so i will have to much unusable data.

i just need when i put ID card near RFID reader, have data like ( Reader:1, ID: sff33rfgfd)

2 - i want to record number 1,2,3,... in on excel column and ID in another column. that i can know witch ID card used from Witch Reader.)

0 Kudos
Message 109 of 143
(2,804 Views)

Your first problem is addressed by using a termination character (like with println), and then removing any timeouts from the read. You can also remove the Wait. Be careful regarding the LED flashing - it will show the previously scanned reader's light whilst waiting.

 

The second issue can be addressed by your string parsing - if they always follow a ":" character, consider using that if the lengths might change. If you're sure you'll never have 10 readers, or change the formatting of the strings, then a constant is fine. Hopefully some rearrangement of the string parsing with regards to the bullet points above might help you get a clearer output.


GCentral
Message 110 of 143
(2,799 Views)