C# GPS串口搜索器

C# GPS串口搜索器,c#,gps,windows-ce,windows-mobile-gps,C#,Gps,Windows Ce,Windows Mobile Gps,我尝试在平板电脑(Windows CE)上搜索GPS的串行端口 我知道这是在“COM 3”上,但我想让程序自己找到它。我的意思是在所有端口上运行一个循环(for)并搜索它 我的问题是,我需要写哪个“如果”来告诉程序“这是我的GPS端口” 谢谢大家。据我所知,Gps使用物理或虚拟串行com端口(即通过usb进行com)。由于一次只能有一个应用程序打开一个com端口,因此在搜索gps端口时,不应该有使用gps的程序 您已经给出了答案“所有端口上的循环(for)和serche for” 请注意,下面的

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

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

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


谢谢大家。

据我所知,Gps使用物理或虚拟串行com端口(即通过usb进行com)。由于一次只能有一个应用程序打开一个com端口,因此在搜索gps端口时,不应该有使用gps的程序

您已经给出了答案“所有端口上的循环(for)和serche for”

请注意,下面的示例是一个未经测试的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;
 }

据我所知,Gps使用物理或虚拟串行com端口(即通过usb的com)。由于一次只能有一个应用程序打开一个com端口,因此在搜索gps端口时,不应该有使用gps的程序

您已经给出了答案“所有端口上的循环(for)和serche for”

请注意,下面的示例是一个未经测试的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;
 }