『关闭窗口』
一个简单的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
一个简单的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
解决方案 »
- 求助:找控件属性。。。
- 好久不来,散分,据说标题要长,抢分的人就越多,不知道是不是这样,所以特来试一把。不知道现在抢分的人多不多,是不是要放假了,大家都在计划怎么爽歪歪呢?大家节日快乐
- 请教:希望高手帮我看看以下用于解密的代码属于什么算法
- 如何模拟输入用户名、密码来访问网络邻居?
- "Microsoft Layer for Unicode failed to initialize"这是什么错误?
- TIdFTPServer响应TIdFTP.List的问题
- 如何读取 ADODataset 中的值?
- MDI子窗口切换!
- 寻求好的计剩余时间方法
- 我新装的 2000个人版操作系统 在启动自动更新服务的时候 出了点问题 请各位帮帮我
- quickreport的打印问题1
- 关于DBGrid的应用
proceddure btnSendClick(Sender: TOBject);
var
DevNo: Char;
Buffer: Array of Char;
begin
DevNo := Char(StrToInt(Text3.Text));
SetLength(Buffer, 6);
Buffer[0] := Char(StrToInt(Text4.Text));
Case ComboBox2.ItemIndex of
0: Buffer[1] := #39;
1: Buffer[1] := #33;
2: Buffer[1] := #32;
end;
Buffer[2] := #ee;
Buffer[3] := #ee;
Buffer[4] := Char(StrToInt(ComboBox1.Text));
Buffer[5] := #ff;
Try
MSComm1.CommPort := 1;
MSComm1.Settings := ComboBox3.Text + ',M,8,2'
MSComm1.InputLen := 0;
MSComm1.PortOpen := true;
MSComm1.OutBufferCount := 0;
MSComm1.OutPut := DevNo;
MSComm1.PortOpen := False;
MSComm1.Settings := ComboBox3.Text + ',S,8,2'
MSComm1.OutBufferCount := 0
MSComm1.PortOpen := True
MSComm1.Output := Buffer;
MSComm1.PortOpen := False;
Text1.Text = '发送成功!'#13'发送至'#13'屏体,信息编号:" + Text4.Text + #13 + #13 + Text1.Text;
Except
Text1.Text = 'ERROR!请重新选择COM口!' + #13 + #13 + Text1.Text
end;
end;
StrPas(Buffer),不过不是这么简单,要先将Buffer按协议拆分开来再进行转换,主要还是看你的协议是怎么定的