开发者

Should I keep a SerialPort connection open?

开发者 https://www.devze.com 2022-12-13 20:38 出处:网络
I am working with serial communication and I\'m wondering whether I should keep the SerialPort open or not?

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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号