cpubbs论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

LabVIEW+单片机学习套件全套教程资料下载[免费]LabVIEW论坛精华列表贴USB0816数据采集卡《LabVIEW宝典》
LabWindows/CVI论坛精华贴NET0816以太网数据采集卡RC0210远程设备授权系统 关闭关停锁定打开设备 户外分布式数据采集
NET1624低速高精度以太网数据采集卡WIFI0824SD无线WIFI网络数据采集卡脱机运行 SD存储 小尺寸微型 串口采集远程采集 安卓 手持移动采集 纪录仪
查看: 1537|回复: 0

一个简单的VB串口发送程序(源码)!

[复制链接]
发表于 2004-11-6 03:33:46 | 显示全部楼层 |阅读模式
'-----发送按钮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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|cpubbs论坛. ( 粤ICP备09171248号 )

GMT+8, 2025-5-4 15:30 , Processed in 0.657776 second(s), 7 queries , Gzip On, File On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表