掃描裝置上的GPS是哪一個COM
在"在PDA上開發GPS的程式問題這篇文章中,有提到要如何去看GPS是在哪一個COM Port上面;一般來說有兩個方式,一個是自己去掃描,另一種方式就是借助別人的軟體去看了;下面這邊我做了一個簡單的掃描程式,有興趣的朋友可以參考看看
Imports System.IO.Ports
Imports System.Text
Public Class Form1
Dim strPortName As String = ""
Dim strTmp As String = ""
Dim B(199) As Byte
Dim intReturn As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.BaudRate = 4800
SerialPort1.DataBits = 8
SerialPort1.Handshake = Handshake.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Parity = Parity.None
SerialPort1.ReadTimeout = 2500
For Each s As String In SerialPort.GetPortNames
SerialPort1.PortName = s
Try
SerialPort1.Open()
Threading.Thread.Sleep(200)
intReturn = SerialPort1.Read(B, 0, B.Length)
If intReturn > 0 Then
strTmp = Encoding.ASCII.GetString(B, 0, intReturn)
If strTmp.IndexOf("$GP") >= 0 Then
strPortName = SerialPort1.PortName
TextBox1.Text = strTmp
End If
End If
SerialPort1.Close()
Catch ex As Exception
If SerialPort1.IsOpen Then SerialPort1.Close()
End Try
Next
End Sub
End Class
留言