06-09-2020 07:42 AM
Hello everybody,
At the moment i program a tool in Labview to interact with a Microcontroller. First of all the communication is not the Problem its possible to send a command and get an answer. My problem is if i send a command (for example ?) i have to tip it into the command box but my event structure react to any key on the board and switch to the default case and i dont know how to wait in the default case for the "Enter Command" to get in the case wich should start my normal interaction with the Microcontroller.
The "Enter", "Return" case is fine and give the correct answer.
At the moment i concentrate on the send command later i will change the response window. It should clear the content if a new command was send, at the moment every answer is listed in the response box.
I need some help because iam not so good in programming with Labview.
Solved! Go to Solution.
06-09-2020 08:17 AM
First, a shameless plug: VIWeek 2020/Proper way to communicate over serial
Now actual comments on your code:
1. You do not want the Key Down filter event (has a ? at the end of the name). Actually, you should just change it to Input: Value Change. That will make things simpler for you.
2. You really should NOT use the Bytes At Port to determine how many bytes to read from the port. You will run into all kinds of issues from de-synching with your messages. You should just use the Bytes At Port to check to see if there is any data (greater than 0). From there, it is based on your protocol. Go watch my presentation linked to above.
3. If you are checking for data quick enough, there is no need to have the read inside of yet another loop.
4. You might want to add a timeout to the Event Structure (50ms) and do the reading from the port in there.
06-15-2020 03:48 AM
Ok now i changed the bytes at Port only for the decision to read or not read.
The Write command is still a Problem. Because of the event structure it is waiting for a value change this is not a Problem but it never comes to the Case "Enter Return". If i change the value the Case structure always switch to Default.
06-15-2020 04:00 AM
Hi Chris,
@Chris202002 wrote:
The Write command is still a Problem. Because of the event structure it is waiting for a value change this is not a Problem but it never comes to the Case "Enter Return". If i change the value the Case structure always switch to Default.
What is the purpose of this Case structure? Why do you compare your string value with "Enter"/"Return"?
Why is there a wait inside the event case?
Why is there a wait in the while loop?
Why don't you use a Timeout event case?
06-15-2020 04:19 AM - edited 06-15-2020 04:27 AM
What is the purpose of this Case structure? Why do you compare your string value with "Enter"/"Return"?
Before i used the "Enter"/"Return" to empty the send command for the next command with the discard option
Why is there a wait inside the event case?
Hmm i dont need it yes i cleared it
Why is there a wait in the while loop?
You mean the 1000 ms in the corner? I tested to reduce timeouts but now i have the bytes at port decision for reading. I should delete it
Why don't you use a Timeout event case?
Now i use the timeout event case, thx
Is it possible to clear the input after sending? at the moment i need only one symbol to send
06-15-2020 05:58 AM - edited 06-15-2020 05:59 AM
Hi Chris,
@Chris202002 wrote:
Is it possible to clear the input after sending? at the moment i need only one symbol to send
Yes, sure!

Why don't you cleanup your code? Use more straight wires!
06-15-2020 06:32 AM - edited 06-15-2020 06:33 AM
Move your read routine into the Timeout event case and remove any other waits.
@Chris202002 wrote:
Is it possible to clear the input after sending? at the moment i need only one symbol to send
Use a Local Variable to write an empty string into your control.

06-15-2020 07:25 AM - edited 06-15-2020 07:27 AM
Thank you for your solution, it should be work but i suppose i have a problem with my microcontroller now. If i send a command it instantly disapear this is no problem but very often i get no response (sonetimes it works). Then i have to hardreset my controller and he works for a few commands then same procedure.
Tomorrow i will talk with the programmer of the microcontroller and ask him for the problem because i get no error messages or something like that.
06-16-2020 04:56 AM
Ok Now the Send command is pretty good. And i got my response every time. I had to delete the "end of line string" and use the automatically generated termination charakter.
My last Problem is the Response. At the moment i use the Feedback node to get the whole Message but every new message is added to the Response and the answer Terminal got longer and longer with every command.
Is it possible to clear the window with every new Send command?
and thx for the help and how does a kudo comment works?
06-16-2020 05:05 AM - edited 06-16-2020 05:06 AM
Hi Chris,
@Chris202002 wrote:
My last Problem is the Response. At the moment i use the Feedback node to get the whole Message but every new message is added to the Response and the answer Terminal got longer and longer with every command.
Is it possible to clear the window with every new Send command?
The string in the "answer terminal" gets longer because you are using a feedback node to collect all received data.
When you don't want to collect data then you don't need any feedback node!
When you want to clear the data only on "new send" then convert the feedback node to a shift register and wire it through all event cases. In the receive (aka timeout) event you can concat new data to the alreday collected data. In the send event you can clear the data in the shift register…
@Chris202002 wrote:
how does a kudo comment works?
There's the "star" icon below each message (left of the "x Kudos" counter): click it to give Kudos…