LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview Communication tool for Microcontroller

Solved!
Go to solution

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.

0 Kudos
Message 1 of 10
(3,374 Views)

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.



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 2 of 10
(3,354 Views)

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.

0 Kudos
Message 3 of 10
(3,270 Views)

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?

Best regards,
GerdW


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

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

0 Kudos
Message 5 of 10
(3,260 Views)

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!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 10
(3,247 Views)
Solution
Accepted by Chris202002

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.



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
Download All
Message 7 of 10
(3,243 Views)

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.

0 Kudos
Message 8 of 10
(3,230 Views)

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?

0 Kudos
Message 9 of 10
(3,155 Views)
Solution
Accepted by Chris202002

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…

Best regards,
GerdW


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