如果你用得是串口,就可以用MSCOMM控件
解决方案 »
- 字符转16进制Ascii问题
- webBrowser控件的问题? 能否在 本身自己打开网页 而不是 弹出网页?
- 在VB中能不能定义宏?如果能那么该怎么定义。。
- 请问用VB如何在数据库MDB中使用 section 语句模糊查询,比如我要将所有名字中有“风”的人查到。比如:
- rst.Open "select * from aa", str, 3, 3中的两个“3”分别代表什么意思?
- 如何用sendmessage 触发窗体的菜单事件?两不同窗体哦!
- 两个非常简单的问题!
- 数据库如何保存声音文件?如解决,大量给分。
- 这里有做GIS的朋友么?能否推荐一两个好的GIS论坛
- VB能打开ACCESS2000的数据库吗?
- 报表
- 打印对齐问题????
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
点Open开始接受与发送