基于RS-232的VB通讯程序
来源:互联网 发布:淘宝出售假冒商品三次 编辑:程序博客网 时间:2024/05/16 08:22
Public bytreceivebyte() As Byte
Public intreceivelen As Integer
Public intput As Integer
Public strset As String
Public inttime As Integer
Public blnautosendflag As Boolean
Public blnreceiveflag As Boolean
Public intoutmode As Integer
Public strsend As String
Public bytsendbyte() As Byte
Public bytinput() As Byte
Public recopy As Integer
'发准备送模块
Private Sub Cmdsend_Click()
If Txtsend.Text = "" Then
List1.AddItem "发送缓冲区无数据"
Exit Sub
End If
frmmain.ctrMScomm.Output = Txtsend.Text '写入字节
End Sub
'关闭模块
Private Sub Cmdquit_Click()
Unload Me
End Sub
'串口初始化
Private Sub Form_Load()
ctrMScomm.CommPort = 1
ctrMScomm.Settings = "9600,N,8,1"
ctrMScomm.InputLen = 0
'端口打开
ctrMScomm.PortOpen = True
ctrMScomm.RThreshold = 1
ctrMScomm.SThreshold = 1
End Sub
'激发MSComm控件的OnComm事件,进行发送
Private Sub ctrMSComm_OnComm()
Select Case ctrMScomm.CommEvent
Case comEvReceive
'接受缓冲区里有字符的处理,即收到外来字符便显示
Dim intinputlen As Integer
If blnreceiveflag Then
If Not frmmain.ctrMScomm.PortOpen Then
frmmain.ctrMScomm.CommPort = intport
frmmain.ctrMScomm.Settings = strset
frmmain.ctrMScomm.PortOpen = True
End If
End If
frmmain.ctrMScomm.InputMode = comInputModeBinary
intinputlen = frmmain.ctrMScomm.InBufferCount
ReDim bytinput(intinputlen)
bytinput = frmmain.ctrMScomm.Input
Call inputmanage(bytinput, intinputlen)
Case comEvSend
'发送缓冲区里字符,显示有字符
List1.AddItem "发送缓冲区有数据"
End Select
End Sub
'文本写入,保存的处理
Public Sub inputmanage(bytinput() As Byte, intinputlenth As Integer)
Dim n As Integer
ReDim Preserve bytreceivebyte(intreceivelen + intinputlenth)
For n = 1 To intinputlenth
bytreceivebyte(intreceivelen + n - 1) = bytinput(n - 1)
Next n
intreceivelen = intreceivelen + intinputlenth
recopy = intinputlenth - 1
Call display
End Sub
'文本显示的处理
Public Sub display()
Dim i As Integer
For i = 0 To recopy
Txtreceive.Text = Txtreceive.Text & Chr(bytinput(i))
Next i
End Sub
- 基于RS-232的VB通讯程序
- 单片机与RS-232的串口通信+VB程序
- 一个基于API的VB.net串口通讯类
- 基于VB的串口通讯及其软件实现
- 基于TCP的通讯程序----基本框架
- VB与三菱40点PLC的通讯程序
- VB与PLC的通讯程序的程序,最常用的是VB
- 串口通讯—RS-232-C详解
- 串口通讯—RS-232-C详解
- 串口通讯—RS-232-C详解
- 串口通讯RS-232-C详解
- RS-232-C串口通讯协议解析
- 用VB编写基于控制台的程序
- 基于VB Winsock 控件的聊天程序
- [VB]RS和DBGrid的相关操作
- vb rs.recordCount=-1的解决办法
- vb rs.RecordCount返回0的原因
- RS-232、RS-422与RS-485的由来
- Asp.net 在DataGrid中使选中的页码变成突显的颜色
- Crystal报表论坛
- JNI入门
- MySQL查询优化技术讲座
- 祝福老婆今天晚上不要累坏了
- 基于RS-232的VB通讯程序
- 几个著名java开源缓存系统的介绍
- 用于MIDP的URLEncoder类
- Google进阶搜索(摘)
- 从资源文件中取图片
- 数据库连接池简介
- 可恶的控件
- "易表"软件强大但高估用户水平
- .NET系统学习----Globalization & Resources