LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabView serial communication issue

Solved!
Go to solution

Hello,

I've encountered an issue with my LabVIEW code. I'm attempting to communicate with an external device that requires serial communication. To achieve this, I've been utilizing the write/read functions. The frame I need to send is as follows:


00x16 00x16 00x16 00x16 00x10 00xFF 00x22 00x00 00x00 00xA7 00x5F 00xF5

It's a 12-byte frame represented in hexadecimal. However, since the write/read function only accepts STR data, I convert it to STR and send the following:


1616161610FF220000A75FF5

Unfortunately, when attempting to communicate with my device, I'm not receiving any response. Additionally, LabVIEW indicates that 24 bytes have been sent, despite sending only 12. It seems that each digit of the hexa representation has been interpreted as a byte.

 

I'm unsure how to resolve this issue. Has anyone encountered a similar problem?

 

Thank you for your help.

0 Kudos
Message 1 of 28
(1,246 Views)

Please define all acronyms, for example what is "STR" in your context?

 

  • What happens if you set your string to hex display before entering the values?
  • What is the datatype of "00x16 00x16 00x16 00x16 00x10 ..." (formatted string? U8 array set to hex format? something else?) and why are there two 00 for each set?
  • Why not show us you code to remove all the ambiguities?
0 Kudos
Message 2 of 28
(1,244 Views)

Most serial communication issues can be solved by watching this video: VIWeek 2020/Proper way to communicate over serial

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 28
(1,237 Views)

@MinHolly  ha scritto:
...

It's a 12-byte frame represented in hexadecimal. However, since the write/read function only accepts STR data, I convert it to STR and send the following:


1616161610FF220000A75FF5

Unfortunately, when attempting to communicate with my device, I'm not receiving any response. Additionally, LabVIEW indicates that 24 bytes have been sent, despite sending only 12. It seems that each digit of the hexa representation has been interpreted as a byte.


You are probably sending the sequence "1616161610FF220000A75FF5" as a 24-characters ASCII string (that is, 24 bytes).

One way to prepare the frame is to build it as a U8 (unsigned byte) array, then typecast it to a string.

Please post your code so that we can help you more.

 

 

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 4 of 28
(1,210 Views)

@MinHolly wrote:

Hello,

I've encountered an issue with my LabVIEW code. I'm attempting to communicate with an external device that requires serial communication. To achieve this, I've been utilizing the write/read functions. The frame I need to send is as follows:


00x16 00x16 00x16 00x16 00x10 00xFF 00x22 00x00 00x00 00xA7 00x5F 00xF5

It's a 12-byte frame represented in hexadecimal. However, since the write/read function only accepts STR data, I convert it to STR and send the following:


1616161610FF220000A75FF5

Unfortunately, when attempting to communicate with my device, I'm not receiving any response. Additionally, LabVIEW indicates that 24 bytes have been sent, despite sending only 12. It seems that each digit of the hexa representation has been interpreted as a byte.

 

I'm unsure how to resolve this issue. Has anyone encountered a similar problem?

 

Thank you for your help.


This is a common cause for confusion with the serial functions.

 

It sounds like you need to send a sequence of bytes. You can do that using this function: https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/functions/byte-array-to-string.html.

 

What you are probably doing is sending a ASCII encoded hex string rather than the actual hex values.

 

See attached.

0 Kudos
Message 5 of 28
(1,192 Views)