LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial communication

Hi all,

This is the first time I am using an external hardware and set up serial communication in place. I have attached an image here, where the user can enter the input and should get a response. Microcontroller coding has been done properly. The following code works but I am not getting any response back. Do y'all think the below code is correct?

0 Kudos
Message 1 of 14
(731 Views)

As always, we cannot debug images because a lot of important information is missing (eg. what's in the other cases of the case and event structures, why is there a timeout event AND a loop wait? Why is there no event for the stop button? Where do the partially hidden wires connect? Is the string control multiline or limited to single line? Should the user entry be terminated with special characters? etc. etc.). Attaching the actual VI is most helpful.

 

The use of "Bytes at port" is typically suspect. A good place to start is Tim's presentation here.

 


@ms6 wrote:

Microcontroller coding has been done properly.


There are many ways to do it "properly". What is the expected format of the commands and response? Number of bytes? Termination characters, etc. etc. Can you give the full specifications?

0 Kudos
Message 2 of 14
(711 Views)

Hi ms6,

 


@ms6 wrote:

Do y'all think the below code is correct?


No, it is not correct!

Placing a wait function (to wait for 1000ms) in parallel to an event structure is nonsense. Especially when the event structure is set to wait at max 50ms (I hope there is a hidden timeout event)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 14
(689 Views)

I have added the Vi here..

0 Kudos
Message 4 of 14
(635 Views)

Also, I have programmed a simple echo program in the microcontroller. So, if I input 'a' i should get response 'a a' 

0 Kudos
Message 5 of 14
(632 Views)

CORRECTION:

Microcontroller's flow: If i input a word or a letter, it will respond back with the first letter. 

In the attached image, I get the desired response but with an error. I am unsure as to why I am getting this error.. (Also attaching the VI). Also, sometimes I don't get a response for the input that I enter..

Download All
0 Kudos
Message 6 of 14
(618 Views)

I am also getting the following error: (attached)

0 Kudos
Message 7 of 14
(604 Views)

@ms6 wrote:

 

Microcontroller's flow: If i input a word or a letter, it will respond back with the first letter. 


That's a suboptimal protocol! When does your uC know that it received the entire word? The "ok" you send could theoretically send like this: "o", 10 seconds of waiting, "k". Never ever will happen?? No! It's unlikely indeed but not impossible. Nothing about RS-232 guarantees that the individual bytes are always sent immediately after each other. Windows may start moving the first byte to the serial device driver, then a super important DMA interrupt occurs, grabbing control exclusively to itself and your serial port is idling waiting for the next byte.

Your uC sees the o, waits some short time, decides: Ohh that apparently was it, lets return the "o" and then the "k" arrives later and it decides, ohh another message, lets return the "k".

And your LabVIEW return waiting for the initial "o" is out of sync with your controller as it sent an extra "k" that your LabVIEW program never expected. Instead you send "goodbey" read the response back and read "k".

 

If you define a protocol you have to choose between these three choices:

 

1) use a termination character (sequence) such as <carriage return> (\r) that indicates that the command and response is finished. Here you can use the default termination character handling that VISA provides.

2) Make the messages fixed size, that way your controller knows to always wait for n characters before trying to interpret the command, and your communication program knows that your controller always will send m characters.

3) use a fixed size header that indicates the number of variable sized bytes that will follow.

Rolf Kalbermatter
My Blog
Message 8 of 14
(593 Views)

@ms6 wrote:

I am also getting the following error: (attached)


Screenshot%202024-01-16%20at%204.52.43%E2%80%AFPM

 

Can you point out the "error" you see on this picture? All I see is hardware configuration.

0 Kudos
Message 9 of 14
(541 Views)

I attached the wrong image, correct one is here...

0 Kudos
Message 10 of 14
(513 Views)