现在已经在装载窗口时对串口进行了初始化:Private Sub Form_Load()
Mscomm1.CommPort = 1
Mscomm1.PortOpen = True
MSComm1.Settings = "9600,n,8,1"
Mscomm1.OutBufferCount = 0
MSComm1.InBufferCount = 0
MSComm1.InputMode = 1
MSComm1.InputLen = 5
MSComm1.RThreshold = 5
End Sub
发送指令各处理数据部分程序该怎样入手呢?
Mscomm1.CommPort = 1
Mscomm1.PortOpen = True
MSComm1.Settings = "9600,n,8,1"
Mscomm1.OutBufferCount = 0
MSComm1.InBufferCount = 0
MSComm1.InputMode = 1
MSComm1.InputLen = 5
MSComm1.RThreshold = 5
End Sub
发送指令各处理数据部分程序该怎样入手呢?
解决方案 »
- 知道输入框句柄怎么向输入框里输入想要的文字
- 使用*.exe.manifest后遇到的问题
- SETUP FACTORY的默认目录怎么改。
- ■■■■■■用vb+access时 不用装access 就能用ado访问,请问vb+sql时,只拷贝两个数据库文件行吗?
- 请教高手!如何从一个得到五笔的码
- 文本框限制数据类型时小键盘不可用如何解决?
- dbcontrols(泰山__抛砖引玉)!能否email一份纸牌类游戏的源代码?
- 哪里有下载sp5?
- 怎么让在键盘按“A”系统认为是“B”呢???????
- 我已经将richtextbox的scrollbars属性设为3-rtfboth了,为什么没有水平滚动条?
- 如何删除SQL Server2000中某个数据表中所有数据
- 请问如何获取CreateObject()出来的变量的事件?
Dim a() As Byte
Dim b() As LongPrivate Function CheckSum(aBytes As Byte) '检验和
Dim i As Integer, Sum As Integer
Sum = 0
For i = 0 To aBytes - 1
Sum = Sum + a(i)
Next i
CheckSum = Sum Mod 256
End FunctionPrivate Sub StopAll() '全部停止
ReDim a(5) As Byte
a(0) = 2
a(1) = txtID.Text
a(2) = 14
a(3) = 0
a(4) = 0
a(5) = CheckSum(5)
MSComm1.Output = a
Do While (MSComm1.OutBufferCount <> 0)
Loop
Call showdata
For i = 0 To 1000000
Next i
a(0) = 2
a(1) = txtID.Text
a(2) = 1
a(3) = 0
a(4) = 0
a(5) = CheckSum(5)
MSComm1.Output = a
Do While (MSComm1.OutBufferCount <> 0)
Loop
Call showdata
End SubPrivate Sub Form_Load()
On Error GoTo err
txtAddress.Text = 255
txtSpeed.Text = 180 MSComm1.CommPort = 3
MSComm1.Settings = "4800,n,8,1"
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End Iferr:
End SubPrivate Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen Then
MSComm1.PortOpen = False
End If
End Sub
Private Sub cmdUp_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) '上
ReDim a(5) As Byte a(0) = 2
a(1) = txtID.Text
a(2) = 14
a(3) = 0 '水平方向速度为0
a(4) = txtSpeed.Text
a(5) = CheckSum(5)
MSComm1.Output = a '设置速度
Do While (MSComm1.OutBufferCount <> 0)
Loop
a(0) = 2
a(1) = txtID.Text
a(2) = 1
a(3) = 4
a(4) = 0
a(5) = CheckSum(5)
MSComm1.Output = a '设置上
Do While (MSComm1.OutBufferCount <> 0)
Loop
End SubPrivate Sub cmdUp_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
StopAll
End SubPrivate Sub cmdLeft_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) '左
ReDim a(5) As Byte
a(0) = 2
a(1) = txtID.Text
a(2) = 14
a(3) = txtSpeed.Text
a(4) = 0 '垂直方向速度为0
a(5) = CheckSum(5)
MSComm1.Output = a '设置速度
Do While (MSComm1.OutBufferCount <> 0)
Loop a(0) = 2
a(1) = txtID.Text
a(2) = 1
a(3) = 2
a(4) = 0 '垂直方向速度为0
a(5) = CheckSum(5)
MSComm1.Output = a '设置左
Do While (MSComm1.OutBufferCount <> 0)
LoopEnd SubPrivate Sub cmdLeft_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
StopAll
End SubPrivate Sub cmdRight_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) '右
ReDim a(6) As Byte a(0) = 2
a(1) = txtID.Text
a(2) = 14
a(3) = txtSpeed.Text
a(4) = 0 '垂直方向速度为0
a(5) = CheckSum(5)
a(6) = 0
MSComm1.Output = a '设置速度
Do While (MSComm1.OutBufferCount <> 0)
Loop a(0) = 2
a(1) = txtID.Text
a(2) = 1
a(3) = 1
a(4) = 0
a(5) = CheckSum(5)
a(6) = 0
MSComm1.Output = a '设置右
Do While (MSComm1.OutBufferCount <> 0)
LoopEnd SubPrivate Sub cmdRight_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
StopAll
End SubPrivate Sub cmdDown_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) '下
ReDim a(5) As Byte
a(0) = 2
a(1) = txtID.Text
a(2) = 14
a(3) = 0 '水平方向速度为0
a(4) = txtSpeed.Text
a(5) = CheckSum(5)
MSComm1.Output = a '设置速度
Do While (MSComm1.OutBufferCount <> 0)
Loop a(0) = 2
a(1) = txtID.Text
a(2) = 1
a(3) = 8
a(4) = 0
a(5) = CheckSum(5)
MSComm1.Output = a '设置下
Do While (MSComm1.OutBufferCount <> 0)
LoopEnd SubPrivate Sub cmdDown_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
StopAll
End Sub
Private Sub Timer1_Timer()
MSComm1.Output = a
End Sub