GPS串口搜索器

发布于 2024-10-08 00:24:25 字数 161 浏览 6 评论 0原文

我尝试在平板电脑 (Windows CE) 上搜索 GPS 的串行端口。

我知道这是在“COM 3”上,但我希望程序自己找到它。我的意思是在所有端口上循环运行(for)并搜索它。

我的问题是我需要写哪个“如果”来告诉程序“这是我的 GPS 端口”。

谢谢大家。

I try to search my serial port of my GPS on my tablet (Windows CE).

I know that this is on "COM 3" but I want the program to find this by itself. I mean run in a loop (for) on all ports and search for this.

My question is which "if" I need to write to tell the program "this is my GPS port".

Thank you all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听你说爱我 2024-10-15 00:24:25

据我所知,GPS 使用物理或虚拟串行 com 端口(即通过 USB 的 com)。由于一次只有一个应用程序可以打开 com 端口,因此在搜索 GPS 端口时不应有任何程序使用 GPS。

您已经给出了答案“在所有端口上循环(for)并搜索”。

请注意,下面的示例是未经测试的示例,说明其工作原理。请随意更新此 wiki 页面以修复可能的错误并添加缺失的功能。

 public string FindGpsPort()
 {
 foreach(string portname in System.IO.Ports.SerialPort.GetPortNames())
 {
      // using to make shure that the testport is closed after test
      using (SerialPort testport = new SerialPort(){PortName = portname})
      {
         // maybe neccessary to set baudrate, parity, ... of com port
         testport.Open(); 
         // to do if error or exception this is not the 
         // gps port or some software already uses the gps-port

         // to do: read some data from port and verify if it is GPS-Data
         // if valid return portname ; 
      }
 }
 // All com ports tried but not found. throw exception or return error code
 return null;
 }

Gps as i know works with a physical or virtual serial com port (ie com via usb). Since only one application can open a com port at a time there should be no program using gps while searching for the gps-port.

You already gave the answer "loop (for) on all ports and serche for".

Note the example below is an untested scetch how it could work. Feel free to update this wiki page to fix possible errors and add missing functionality.

 public string FindGpsPort()
 {
 foreach(string portname in System.IO.Ports.SerialPort.GetPortNames())
 {
      // using to make shure that the testport is closed after test
      using (SerialPort testport = new SerialPort(){PortName = portname})
      {
         // maybe neccessary to set baudrate, parity, ... of com port
         testport.Open(); 
         // to do if error or exception this is not the 
         // gps port or some software already uses the gps-port

         // to do: read some data from port and verify if it is GPS-Data
         // if valid return portname ; 
      }
 }
 // All com ports tried but not found. throw exception or return error code
 return null;
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文