wince下利用serialport通信无法触发datareceived事件怎么解决,Windows下是可以通信的

天呐,他还在输出 2017-08-31 03:04:05


SerialPort1.BaudRate = 9600 'BMS波特率
SerialPort1.PortName = "COM1" 'BMS串口
SerialPort1.DataBits = 8 '数据位
SerialPort1.StopBits = 1 '停止位
SerialPort1.Parity = IO.Ports.Parity.None '校验位
Timer1.Interval = 3000
Timer1.Enabled = True
SerialPort1.ReceivedBytesThreshold = 1 '事件触发频率,每收到1个字节长度数据即出发接收事件
SerialPort1.Open()
If SerialPort1.IsOpen = True Then
StatusLabel.Text = "串口已连接"
StatusLabel.ForeColor = Color.Blue
End If

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ReDim sendbuff(7)
Try
SerialPort1.Write(sendbuff, 0, sendbuff.Length)‘在这个位置程序就停止了
Threading.Thread.Sleep(1000) '添加的延时
SerialPort1.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
'触发接收事件
Sub Sp_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Me.Invoke(New EventHandler(AddressOf Sp_Receiving)) '调用接收数据函数
End Sub
...全文
901 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
解决了,程序没问题。别人的硬件出错了。难受。。。
91program 2017-08-31
  • 打赏
  • 举报
回复
WinCE 下 Basic 没有用过,但 C 下类似于 SerialPort1.PortName = "COM1" 'BMS串口 需要修改为: SerialPort1.PortName = "COM1:" 'BMS串口 多一个冒号。
  • 打赏
  • 举报
回复
命令包没有发送出去,但是Windows下是可以发送的。程序都是一样的。

19,519

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
  • 嵌入开发(WinCE)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧