VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4350
ClientLeft = 60
ClientTop = 345
ClientWidth = 7800
LinkTopic = "Form1"
ScaleHeight = 4350
ScaleWidth = 7800
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdOpen
Caption = "Open"
Height = 315
Left = 4590
TabIndex = 4
Top = 3315
Width = 1230
End
Begin VB.CommandButton cmdSend
Caption = "Send"
Height = 330
Left = 5955
TabIndex = 2
Top = 3300
Width = 1245
End
Begin VB.ListBox ListRevive
Height = 1680
Left = 315
TabIndex = 1
Top = 1530
Width = 6900
End
Begin VB.TextBox txtSend
Height = 315
Left = 315
TabIndex = 0
Top = 795
Width = 4155
End
Begin MSCommLib.MSComm MSComm1
Left = 4920
Top = 630
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.Label lblSend
AutoSize = -1 'True
Caption = "Label1"
Height = 180
Left = 315
TabIndex = 3
Top = 1200
Width = 540
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdOpen_Click()
MSComm1.CommPort = 1
MSComm1.InputMode = comInputModeBinary
MSComm1.RThreshold = 1
MSComm1.PortOpen = True
MSComm1.RThreshold = 1
cmdOpen.Enabled = False
End SubPrivate Sub cmdSend_Click()
Dim OutByte() As Byte
Dim tmpstr As String
Dim i As Integer
If txtSend.Text = "" Then
MsgBox "请输入要发送的数据!", vbExclamation, "提示"
txtSend.SetFocus
End If
OutByte = StrConv(txtSend.Text, vbFromUnicode)
tmpstr = ""
For i = LBound(OutByte) To UBound(OutByte)
tmpstr = tmpstr & Hex(OutByte(i)) & " "
Next i
lblSend.Caption = tmpstr
MSComm1.Output = OutByte
End SubPrivate Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen Then MSComm1.PortOpen = False
End SubPrivate Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEventBreak '收到中断讯号
Case comEventCDTO '
Case comEventCTSTO
Case comEventDSRTO
Case comEventFrame
Case comEventOverrun '数据遗失
Case comEventRxOver '接收缓冲区漫溢
Case comEventRxParity '极性错误
Case comEventTxFull '传送缓冲区漫溢
Case comEventDCB '未预期错误
Case comEvCD
Case comEvCTS
Case comEvDSR
Case comEvRing
Case comEvReceive '收到字符
Dim InByte() As Byte
Dim i As Integer
Dim buf As String
InByte = MSComm1.Input
buf = ""
For i = LBound(InByte) To UBound(InByte)
buf = buf & Hex(InByte(i)) & " "
Next i
ListRevive.AddItem buf
Case comEvSend
Case comEvEOF
End Select
End Sub
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4350
ClientLeft = 60
ClientTop = 345
ClientWidth = 7800
LinkTopic = "Form1"
ScaleHeight = 4350
ScaleWidth = 7800
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdOpen
Caption = "Open"
Height = 315
Left = 4590
TabIndex = 4
Top = 3315
Width = 1230
End
Begin VB.CommandButton cmdSend
Caption = "Send"
Height = 330
Left = 5955
TabIndex = 2
Top = 3300
Width = 1245
End
Begin VB.ListBox ListRevive
Height = 1680
Left = 315
TabIndex = 1
Top = 1530
Width = 6900
End
Begin VB.TextBox txtSend
Height = 315
Left = 315
TabIndex = 0
Top = 795
Width = 4155
End
Begin MSCommLib.MSComm MSComm1
Left = 4920
Top = 630
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.Label lblSend
AutoSize = -1 'True
Caption = "Label1"
Height = 180
Left = 315
TabIndex = 3
Top = 1200
Width = 540
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdOpen_Click()
MSComm1.CommPort = 1
MSComm1.InputMode = comInputModeBinary
MSComm1.RThreshold = 1
MSComm1.PortOpen = True
MSComm1.RThreshold = 1
cmdOpen.Enabled = False
End SubPrivate Sub cmdSend_Click()
Dim OutByte() As Byte
Dim tmpstr As String
Dim i As Integer
If txtSend.Text = "" Then
MsgBox "请输入要发送的数据!", vbExclamation, "提示"
txtSend.SetFocus
End If
OutByte = StrConv(txtSend.Text, vbFromUnicode)
tmpstr = ""
For i = LBound(OutByte) To UBound(OutByte)
tmpstr = tmpstr & Hex(OutByte(i)) & " "
Next i
lblSend.Caption = tmpstr
MSComm1.Output = OutByte
End SubPrivate Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen Then MSComm1.PortOpen = False
End SubPrivate Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEventBreak '收到中断讯号
Case comEventCDTO '
Case comEventCTSTO
Case comEventDSRTO
Case comEventFrame
Case comEventOverrun '数据遗失
Case comEventRxOver '接收缓冲区漫溢
Case comEventRxParity '极性错误
Case comEventTxFull '传送缓冲区漫溢
Case comEventDCB '未预期错误
Case comEvCD
Case comEvCTS
Case comEvDSR
Case comEvRing
Case comEvReceive '收到字符
Dim InByte() As Byte
Dim i As Integer
Dim buf As String
InByte = MSComm1.Input
buf = ""
For i = LBound(InByte) To UBound(InByte)
buf = buf & Hex(InByte(i)) & " "
Next i
ListRevive.AddItem buf
Case comEvSend
Case comEvEOF
End Select
End Sub
解决方案 »
- 键列信息不足或不正确,更新影响到多行
- 新手关于程序登录的问题
- 我在用GetObject得到一个Excel文件时,报错:属性的使用无效!请帮忙!!
- 可否有语句强行跳出WHILE....WEND循环
- 求MSN的效果实现方法?
- 如何在 MSHFlexGrid 中显示 2 行标题?
- 我是vb 初学者,请帮助
- path=C:\Program Files\Samples\VB\..\Data\washington 请问data前面那个“..”代表什么?
- 用Jmail发送邮件不成功啊!!试了好多方法了,不成功啊,求大神指教---在线急求!
- 小女子刚学VB,想请教一下1.如何在导出的EXCEL表中修改后,更新到原来的ACCESS中;2.导出时如何让用户选择想要导出的字
- 历史记录功能的菜单怎么做,详细点!
- 在VB用winsock控件数组做winsock服务器比在VC++中用多线程做winsock服务器有什么缺点?
...
发送:
WScomm.ouput datastr接收:
WScomm.input datastr