繁体   English   中英

GPS串口搜索器

[英]GPS serial port searcher

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

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

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

谢谢你们。

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

您已经给出了答案“在所有端口上都为(循环),并为””。

请注意,下面的示例是未经测试的scetch的工作方式。 随时更新此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;
 }

暂无
暂无

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

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