描述:
代码如下:
‘驱动全站仪指令
Dim Str As String = Chr(1) & "C067 ETX" & Chr(13) & Chr(10)
Dim Strl As String = Chr(4) & Chr(13) & Chr(10)
’*****************************************************************************
Dim GuanCeZhi As String
Dim Cont As Integer
Dim StrBits As Byte()
Dim sp As New SerialPort
'端口参数设置
sp.PortName = ComboBox1.Text
sp.StopBits = StopBits.One
sp.BaudRate = Val(ComboBox2.Text)
sp.DataBits = 8
sp.Parity = 0
sp.WriteBufferSize = 500
sp.ReadBufferSize = 5000
sp.WriteTimeout = 1000
sp.Open() '打开串口
'数据通信
Try
If sp.IsOpen = False Then sp.Open()
Label4.Text = "蓝牙已连接"
Cont = System.Text.Encoding.UTF8.GetByteCount(Str)
StrBits = System.Text.Encoding.UTF8.GetBytes(Str)
'发送请求,向串口写
sp.Write(StrBits, 0, Cont)
'从串口输入缓冲区读取测量数据
GuanCeZhi = sp.ReadLine
TextBox1.Text = GuanCeZhi
'********************************************
'处理测量数据
'********************************************
Cont = System.Text.Encoding.UTF8.GetByteCount(Strl)
StrBits = System.Text.Encoding.UTF8.GetBytes(Strl)
'回馈信息
sp.Write(StrBits, 0, Cont)
Catch
'Label4.Text = "蓝牙未连接"
' MsgBox("数据传送失败!")
If sp.IsOpen = True Then
sp.Close()
End If
End Try
‘***********************************************************
PDA执行以上代码后,全站仪未有测量反应,请问以上代码有什么问题?