03-08-2019 07:26 PM - edited 03-08-2019 07:27 PM
Hello, I have looked at all the NI examples on serial ports and a lot of other forum posts; I can't find anyone that has written a program where the serial port is not opened when the program starts, then within the program are able to open and close the port however many times they want without closing the main program. The program I'm creating will be compiled to an EXE and ran in the field and needs to talk to multiple sensors that plug in via usb and operate as virtual serial ports. I would like the user to be able to run the program, then choose serial ports based on what is available in windows and open them one by one. I have figured out how to open the program then open the serial port, but I can't quite figure out how to close it, then re-open it. I have something like this:
I've seen so many different ways people do serial ports in LabVIEW that my brain hurts. I know this code could be cleaner and I will clean it up after I figure out this open/close goal. If anyone wants to recommend a completely different way to accomplish(structure wise)... go for it; I'll try and re-post.
Solved! Go to Solution.
03-09-2019 04:33 AM
03-09-2019 06:38 AM
Look into the Queued Message Handler. The idea being that you have a loop that does nothing but handle the communications with a single device. You can send it messages via a queue to do whatever (open, close, query, etc.) Then your main loop can just be a simple loop with an Event Structure in it that does nothing but send messages around based on user inputs. For display purposes, I like to use User Events for having your serial port loop send updates to the GUI event loop.
04-16-2019 04:34 PM
OK,, I am definitely going to look into Queued Message Handler as I'm seeing that in other more complicated examples like the Modbus Master/Slave examples,, but for now I got this working like I want for opening/closing the serial port. It works great, thank god for being able to re-call the VISA serial even after the port is open, and the VISA close even after the port is closed. Now my only problem is handling the read timeout error. All work great unless I don't get a response from the arduino. I want to be able to trap this error and display a "No Response" indicator to the user. I've seen examples with switches, cases, but this is the simplest I've seen and I want it to work so bad. Can anyone tell me if this should work like I suspect:
04-18-2019 07:41 PM
Ok I figured out that I had the error code to match in the wrong input, I needed to use "exception code", I feel stupid now. I'm able to display the timeout by using the simple error handler vi with no dialog specified. Then I clear that error only after the flat sequence with the general error handler so I can get any other errors that might arise. I'm amazed every day at how many ways there are to accomplish any task. I'll leave this here as my final post b/c it's working as I intended now.