简体   繁体   English

在带有VB.NET 2010的DLL中使用串行端口

[英]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. 我试图在VB.NET 2010中构建一个DLL,该DLL将用于控制自动售货机。 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. 将对DLL的调用鸣叫到一个函数,以在第一次打开该端口时将其打开就很好了,但是如果再次对DLL进行调用,即使端口仍然处于打开状态,它也不知道该端口是否处于打开状态。 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. 我可以检查另一个程序,并显示端口已打开,如果我尝试再次调用DLL来打开端口,则会收到错误消息,表明该端口已打开。 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. 我需要在一个使其保持打开状态的呼叫中打开并配置com端口,然后在另一个呼叫中使用com端口在不关闭com端口的情况下与机器中的设备通话,直到需要将其关闭为止。

You can use a static (shared) field with the list of the opened connection and check it before use the COM port. 您可以在打开的连接列表中使用静态(共享)字段,并在使用COM端口之前对其进行检查。

Be sure that also if the application crashes, all the opened ports will be closed using the Dispose method. 确保即使应用程序崩溃,也将使用Dispose方法关闭所有打开的端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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