一个简单的VB串口发送程序(源码)!2005-09-23 12:26:00
【评论】
【打印】
【字体:大 中 小】
本文链接:http://blog.pfan.cn/iamben250/5153.html
一个简单的VB串口发送程序(源码)! |
'-----发送按钮Click事件子程序----------- Private Sub Fasong_Click() Dim JIHAO(0) As Byte ’机号 Dim head_data(4) As Byte ’5 Byte控制字 Dim end_data(0) As Byte '1 Byte 结束字 JIHAO(0) = Val(Text3.Text) head_data(0) = Val(Text4.Text) head_data(2) = &HEE 'TIMH head_data(3) = &HEE 'TIML head_data(4) = Val(Combo1.Text) 'INMOD end_data(0) = &HFF If Combo2.Text = "增加" Then head_data(1) = &H99 If Combo2.Text = "清空" Then head_data(1) = &H33 If Combo2.Text = "删除" Then head_data(1) = &H32 Ready = 0: ErrCount = 0 On Error GoTo ERRORCOM ’打开错误处理 '---------------------------------------------------------- If com1.value Then MSComm1.CommPort = 1 'Use com1 If com2.value Then MSComm1.CommPort = 2 'Use com2
MSComm1.Settings = FORM1.Combo3.Text + ",M,8,2" '设定波特率和置校验和位为1 MSComm1.InputLen = 0 ' MSComm1.PortOpen = -1 'Open the port MSComm1.OutBufferCount = 0 MSComm1.Output = JIHAO ‘发送机号 MSComm1.PortOpen = False ’关闭串口 MSComm1.Settings = FORM1.Combo3.Text + ",S,8,2" '设定波特率和置校验和位为空 MSComm1.OutBufferCount = 0 MSComm1.PortOpen = True MSComm1.Output = head_data MSComm1.Output = Text2.Text MSComm1.Output = end_data MSComm1.PortOpen = False Text1.Text = "发送成功!" + Chr(13) & Chr(10) + "发送至" + Text3.Text + "屏体," + "信息编号:" + Text4.Text + Chr(13) & Chr(10) + Chr(13) & Chr(10) + Text1.Text GoTo comend ERRORCOM: Text1.Text = "ERROR!请重新选择COM口!" + Chr(13) & Chr(10) + Chr(13) & Chr(10) + Text1.Text comend: On Error GoTo 0 End Sub | |
阅读(5840) | 评论(0)
版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!
评论