LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read Array from Serial

I am able to write to elements in an array but am having an issue reading. Can anyone take a look at my attached .vi and give me some feedback?

 

Thanks,

Nathan

0 Kudos
Message 1 of 13
(2,837 Views)

Hi najossmith,

 

I am able to write to elements in an array but am having an issue reading. Can anyone take a look at my attached .vi and give me some feedback?

There are a lot of issues, not just the array reading…

Why do all your controls miss their label? NEVER delete the label!

Why do you insert to an existing array all the time?

Why do you need a second loop to send that string again and again to your device?

Why do you typecast your array to string? Why do you typecast the received string back to an array?

Does the formatting of the sent and received string correspond to the requirement of the device connected to your serial port?

See this:

check.png

Best regards,
GerdW


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

What exactly is your issue?  What is not happening that should be?  What is happening that shouldn't be?

 

I do see an issue with your code in that most of your controls don't have any labels.  Every control and indicator should have a label to give it a name.  You can choose to hide the label on the front panel if you want to, but they should be named.  That is why your local variable has a question mark.

 

Also, why are you using individual scalar controls to write to an array that is a control?  Because your array control is empty, the Replace Array Element has nothing to replace and you are left with an empty array.

0 Kudos
Message 3 of 13
(2,826 Views)

Correct, the formatting has to do with the device on the other end. 

 

I attempted to build what you posted, but I am still not getting that values I am writing to show up in the read array. I have it attached if you could take a took.

 

Thanks,

Nathan

0 Kudos
Message 4 of 13
(2,805 Views)

Should happen: I write into the array attached to the Write and it then shows up in the array connected to the Read.

 

What is happening that shouldn't: The read array stays grayed out.

 

Adding labels didn't fix my problem and your last issue is resolved by populating the array right after I start the program.

 

Thoughts on how to get the Read to pickup the write?

 

Thanks,

Nathan 

0 Kudos
Message 5 of 13
(2,803 Views)

Hi Nathan,

 

Correct, the formatting has to do with the device on the other end. 

So what is that device? Manufacturer? Type/model?

Any relevant documentation? Did you read it's manual?

Can you describe the string format expected by that device?

 

I attempted to build what you posted, but I am still not getting that values I am writing to show up in the read array. I have it attached if you could take a took.

So you attached your VI from your first post again.

Without any of our suggestions taken.

Still no labels, still that nonsens ReplaceArrayElement, still that nonsense loop…

 

Thoughts on how to get the Read to pickup the write?

Read the manual of your external device.

Which string format does it expect?

Which string format is used for the answer of that device?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 13
(2,801 Views)

I attached the wrong .vi, sorry about that, here is the corrected one.

 

The other end will just be an Arduino, I can set it up to read/write anything so I'm less worried about that part. I just need to prove to myself that I can write an array on LabVIEW and then read it over the serial port.

 

Example End goal:

LabVIEW writes array (255,3.3, 0, 0) over serial

Arduino reads array and executes the command.

Arduino updates array to (255, 3.3, 24.12, 1.4)

LabVIEW reads updated array

(loops continuously)

0 Kudos
Message 7 of 13
(2,795 Views)

So does this latest VI work or not?

 

I don't have a serial port to funnel the data through at the moment.  Or a serial loop back adapter.  But  the array to string and string to array functions seem to work like they should.

0 Kudos
Message 8 of 13
(2,785 Views)

It doesn't, but I am told that I can't read and write the same array all within LV without an external device setup in between? If that's the case, I need to setup my Arduino to send out an array first.

0 Kudos
Message 9 of 13
(2,781 Views)

You are sending an array out of the serial port, you are trying to read the array in from the serial port.

 

What do you have in between right now to turn the array back around from the transmit pins to the receive pins?  What is connected to your serial port?

0 Kudos
Message 10 of 13
(2,779 Views)