LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending an array of different data types over a serial connection

Hello,

 

I am interested in sending an array of various data types over a serial connection. I currently have what the bit structure of the data message is supposed to look like and now need to implement it in Labview. Any help would be greatly appreciated.

0 Kudos
Message 1 of 13
(4,066 Views)

You want to use NI-VISA to do the serial communication. VISA communication is via strings, so you need to convert to/from strings in order to transfer data.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 13
(4,063 Views)
An array can only contain a single data type so your question does not make much sense. Do you actually have a byte structure? Why don't you share it?
Message 3 of 13
(4,019 Views)

Hello,

 

Thank you for your reply. Here is an example of what my byte structure looks like:

 

Data Type                     Byte Number

 

Numeric                       0

Numeric                       1 - 4

Numeric                       5- 8

Boolean                       9 - 12

Enum                          13 - 16

 

This goes on for approximately 256 bytes. I need to send them in the order they are listed over a Serial connection. I will also need to read from an external non-National Instruments device through serial, which will have a different byte structure with the same Data Types.

 

Each variable is 4 bytes long, with there being a few status bytes at the very beginning being 1 byte.

 

Any help is appreciated.

 

Thank you.

 

0 Kudos
Message 4 of 13
(3,924 Views)

If the byte order is always the same, I would just make a cluster with all of the data and then use Flatten To String.  You can then send that string using the VISA Write.

 

For the read, I would do the same thing except read with the VISA Read and then Unflatten From String.


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 13
(3,911 Views)

Ok thank you. I am going to go with the flatten to String method. I have another question. I need to run a for loop that performs certain operations depending on the value of N, but after it runs an N number of times, I need it to reset the N to 0 and repeat this process. I think shift registers are the method I should use but I am not entirely sure of the syntax.

0 Kudos
Message 6 of 13
(3,878 Views)

@Scaz wrote:

Ok thank you. I am going to go with the flatten to String method. I have another question. I need to run a for loop that performs certain operations depending on the value of N, but after it runs an N number of times, I need it to reset the N to 0 and repeat this process. I think shift registers are the method I should use but I am not entirely sure of the syntax.


A For loop inside of a While loop? Specific operations based on the value of N would be a Case Structure with N wired to the selector. I think that's what you're getting at, but I can't be sure because your sentence structure could mean N different operations, or a single operation based on the value of N.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 7 of 13
(3,874 Views)

It would be a single operation based on the value of N.

0 Kudos
Message 8 of 13
(3,865 Views)

@Scaz wrote:

It would be a single operation based on the value of N.


Specific operations based on the value of N would be a Case Structure with N wired to the selector, all inside of a While loop. Use a shift register if you need the previous loop's values.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 9 of 13
(3,859 Views)

Ok, thank you. I understand that part. My question is, how do I continuously run this loop N number of times, resetting it back to 0 after each N times. I need to repeatly send data over a serial connection that sets certain fields to certain values depending on this N value. Each iteration is one message and after N number of times, it resets and repeats the process. Hopefully this clarifies.

0 Kudos
Message 10 of 13
(3,844 Views)