简体   繁体   中英

using a serial port in a DLL with VB.NET 2010

I am trying to buld a DLL in VB.NET 2010 that will be use to control a vending machine. Whin a call into the DLL to a function to open and setup the comport the first time its opens it just fine, but if a call into the DLL again it does not know that the port is open even if it is still open. I can check with another program and is shows the port is open and if I try to call into the DLL again to open the port I get an error that the port is already open. Any idea how to set this up so it will work.

I need to open and config the com port in one call that leaves it open and then in other call use the com port to talk the equipment in the machine without closing the com port untill it is required to close it.

You can use a static (shared) field with the list of the opened connection and check it before use the COM port.

Be sure that also if the application crashes, all the opened ports will be closed using the Dispose method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM