10-01-2023 11:23 AM
Sorry for asking this simple question, but I have an arduino program which receive serial input, I want a case where I can press a button in labview and the string "g","s" etc. is sent to the serial monitor for arduino to read. I am stuck in the process of creating such a vi. I would appreciate if there is any help, here is my vi for attachment, thanks.
10-02-2023 07:59 AM
Is the Arduino also sending data out through this serial connection? If not, a simple look with an Event Structure would suffice.
10-02-2023 08:02 AM
No, the arduino serial monitor is just receiving strings (Serial read) from labview, no two way communication is needed
10-02-2023 09:27 AM
Use a while loop, put an event structure, add an case to handle value change event for the button, implement the VISA write to send the string.
Note: do initialize and close the VISA session outside the loop and do only VISA write inside the event handler.
10-02-2023 10:23 AM
Thank for the help, but I come up with an event structure with a button for different string to send, such as GO for "g", STOP for "s", but it seems like the arduino does not receive the string when the button is latched. Any support would be appreciated.
10-02-2023 11:03 AM
Move that "Close" outside of the While loop. Remember that the event structure will execute exactly one state each time it's called. The While loop will then repeat "stuff inside it". Basically, you enter the While loop and wait on a button event. When that event happens, the Event structure executes that case and is done. In your case, you call the VISA Close function, then the While loop executes again, which lets your Event structure respond to a new event, then you repeat.
Either put the VISA Open and Close inside each frame of the Event structure (so each Event will open the function, send the data, then close the port), or put both *outside* the Event structure so it opens the port, handles all the data, then closes it when you're done. Either method has its own use case, but for your situation I'd do the latter (put VISA Open and Close outside the structure).