简体   繁体   English

rxtx com端口

[英]rxtx com port

I am using rxtx api to read data from a GPS device over a com port. 我正在使用rxtx api通过com端口从GPS设备读取数据。 Right now I'm finding the correct com port by reading a config file and looking for the port listed. 现在,我通过读取配置文件并查找列出的端口来找到正确的com端口。 The problem that I'm having is that if the device is unplugged the com port could change then the user has to know to change the config file. 我遇到的问题是,如果拔下设备的com端口,则可能会更改,那么用户必须知道要更改配置文件。 I wrote an app similar to this in c# and was able to list the windows device name instead of the com port and I cycled through the com ports until the device name matched the name in the config file. 我用c#编写了一个与此类似的应用程序,并且能够列出Windows设备名称而不是com端口,然后循环浏览com端口,直到设备名称与配置文件中的名称匹配为止。 Using that method nothing in the config file has to change even if the com port being used changes. 使用该方法,即使正在使用的com端口发生更改,配置文件中的内容也无需更改。 Is there a way to do that with the rxtx api? 有没有办法用rxtx api做到这一点?

Thanks in advance! 提前致谢!

If anyone is interested... 如果有人感兴趣...

I created a windows service in C# that monitors a socket. 我用C#创建了一个监视套接字的Windows服务。 If a client connects to that socket the service gathers port name, and device id that is on that port and sends the data in a string over the com port the client can then parse apart the string to get the data it needs. 如果客户端连接到该套接字,则该服务将收集端口名称和该端口上的设备ID,并通过com端口以字符串形式发送数据,然后客户端可以将字符串解析为所需的数据。

In my case the string being passed is: "ACPI\\PNP0501 *PNP0501 ,COM1 ,PCI\\VEN_8086&DEV_29B7&SUBSYS_02111028&REV_02 PCI\\VEN_8086&DEV_29B7&SUBSYS_02111028 PCI\\VEN_8086&DEV_29B7&CC_070002 PCI\\VEN_8086&DEV_29B7&CC_0700 ,COM3 ,USB\\Vid_067b&Pid_2303&Rev_0400 USB\\Vid_067b&Pid_2303 ,COM5" 在我的情况正在传递的字符串是: “ACPI \\ PNP0501 * PNP0501,COM1,PCI \\ VEN_8086&DEV_29B7&SUBSYS_02111028&REV_02 PCI \\ VEN_8086&DEV_29B7&SUBSYS_02111028 PCI \\ VEN_8086&DEV_29B7&CC_070002 PCI \\ VEN_8086&DEV_29B7&CC_0700,COM3,USB \\ Vid_067b&Pid_2303&Rev_0400 USB \\ Vid_067b&Pid_2303,COM5”

When I parse it I can see that ACPI\\PNP0501 *PNP0501 is the device id for COM 1, there are three device id's for COM3, and two device ids on COM5. 当我解析它时,我可以看到ACPI \\ PNP0501 * PNP0501是COM 1的设备ID,其中COM3有3个设备ID,而COM5有2个设备ID。

This may not be the best way to handle this but it is good enough for my needs and it saved me from JNI. 这可能不是解决此问题的最佳方法,但它足以满足我的需求,并且使我脱离了JNI。 :) :)

CommPortIdentifier.getPortIdentifiers lists all ports in the system that are usable by the Javacomm API. CommPortIdentifier.getPortIdentifiers列出系统中Javacomm API可用的所有端口。 Iterate through them to find the port your device is connected to. 遍历它们以查找设备所连接的端口。

If you want to get the name associated with the device on the COM port (particularly if a driver is installed to provide it), you'll have to do so with a smidge of the dreaded Java->Native Interface to talk to the Windows APIs that gather this information. 如果要在COM端口上获取与设备关联的名称(特别是如果安装了驱动程序以提供设备名称),则必须使用一些令人恐惧的Java-> Native Interface才能与Windows对话收集此信息的API。 C# is nice, in that this information is gathered and provided to you, but in Java you have to go this extra step. C#很不错,因为该信息已收集并提供给您,但是在Java中,您必须执行此额外步骤。

Windows Function Discovery may prove useful. Windows Function Discovery可能有用。 I'm not certain exactly what API provides this functionality. 我不确定究竟哪个API提供了此功能。

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

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