01-14-2024 10:30 PM
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?
01-15-2024 12:44 AM - edited 01-16-2024 10:57 PM
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?
01-15-2024 01:38 AM
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)…
01-15-2024 04:38 PM
I have added the Vi here..
01-15-2024 04:43 PM
Also, I have programmed a simple echo program in the microcontroller. So, if I input 'a' i should get response 'a a'
01-15-2024 07:55 PM
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..
01-15-2024 11:54 PM
I am also getting the following error: (attached)
01-16-2024 02:57 AM - edited 01-16-2024 03:00 AM
@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.
01-16-2024 09:35 AM
@ms6 wrote:
I am also getting the following error: (attached)
Can you point out the "error" you see on this picture? All I see is hardware configuration.
01-16-2024 07:43 PM
I attached the wrong image, correct one is here...