Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I keep a SerialPort connection open?

I am working with serial communication and I'm wondering whether I should keep the SerialPort open or not?

I'm creating a queue of commands and only one will be running at a time. Should I create a SerialPort and open/close it in each command, or should I have another class which holds the port open and is called from the commands? Or does it really matter?

like image 213
Max Schmeling Avatar asked Dec 14 '09 20:12

Max Schmeling


2 Answers

Keep it open. No point to have the overhead of opening and closing it.

like image 195
C. Ross Avatar answered Nov 20 '22 03:11

C. Ross


In addition to C. Ross's answer, keeping it open will prevent anything else from opening the SerialPort and blocking you later. I would suggest keeping it open.

like image 4
Dan Lorenc Avatar answered Nov 20 '22 03:11

Dan Lorenc