?? mscomm.frm
字號:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form FrmMscomm1
Caption = "MSComm"
ClientHeight = 1755
ClientLeft = 2280
ClientTop = 2040
ClientWidth = 5655
LinkTopic = "Form1"
ScaleHeight = 1755
ScaleWidth = 5655
Begin MSCommLib.MSComm MSComm1
Left = 240
Top = 120
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.CommandButton cmdDispaly
Caption = "顯示"
Height = 375
Left = 2160
TabIndex = 3
Top = 1320
Width = 1515
End
Begin VB.CommandButton cmdClear
Caption = "清除"
Height = 375
Left = 4080
TabIndex = 2
Top = 1320
Width = 1365
End
Begin VB.CommandButton cmdTest
Caption = "測試"
Height = 375
Left = 120
TabIndex = 1
Top = 1320
Width = 1515
End
Begin VB.TextBox txtStatus
Height = 1155
Left = 0
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 0
Top = 0
Width = 5625
End
End
Attribute VB_Name = "FrmMscomm1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub cmdClear_Click()
Me.txtStatus = ""
End Sub
' 顯示調制調解器連接信息
Private Sub cmdDispaly_Click()
Dim Msg As String
Msg = IIf(MSComm1.CDHolding, "有載波信號", "無載波信號") & vbCrLf _
& IIf(MSComm1.CTSHolding, "Clear TO Send:傳輸可以進行", "不允許傳輸數據") & vbCrLf _
& IIf(MSComm1.DSRHolding, "數據終端準備好", "終端未準備好")
txtStatus.Text = txtStatus.Text & vbCrLf & Msg
End Sub
' 測試使用調制調解器進行傳輸
Private Sub cmdTest_Click()
Dim buffer As Variant
With MSComm1
If .PortOpen = True Then
MsgBox "端口已經打開"
Exit Sub
End If
.CommPort = 2 ' 設置并打開端口
.Settings = "9600,N,8,1"
.PortOpen = True
' 發送一個字符串
buffer = "Test"
.Output = buffer
End With
End Sub
' 獲得發生的通訊事件或錯誤信息
Private Sub MSComm1_OnComm()
Dim Msg As String
Select Case MSComm1.CommEvent ' 錯誤
Case comEventBreak
Msg = "收到中斷"
Case comEventCDTO
Msg = "載波檢測超時"
Case comEventCTSTO
Msg = "CTS超時"
Case comEventDSRTO
Msg = "DSR超時。"
Case comEventFrame
Msg = "幀錯誤"
Case comEventOverrun
Msg = "數據丟失。"
Case comEventRxOver
Msg = "接收緩沖區溢出。"
Case comEventRxParity
Msg = "Parity 錯誤。"
Case comEventTxFull
Msg = "傳輸緩沖區已滿。"
Case comEventDCB
Msg = "獲取DCB時意外錯誤"
Case comEvCD
Msg = "CD 線狀態:" & IIf(MSComm1.CDHolding, "調制解調器正在聯機", "無聯機")
Case comEvCTS
Msg = "CTS 線狀態變化:" & IIf(MSComm1.CTSHolding, "傳輸可以進行", "傳輸不允許進行")
Case comEvDSR
Msg = "DSR 線狀態變化:" & IIf(MSComm1.CTSHolding, "數據終端準備好", "數據終端沒有準備好")
Case comEvRing
Msg = "Ring Indicator 變化。"
Case comEvReceive
Msg = "收到" & MSComm1.RThreshold & "個字符"
Case comEvSend
Msg = "傳輸緩沖區有" & MSComm1.SThreshold & "個字符"
Case comEvEOF
Msg = "輸入數據流中發現EOF字符"
End Select
Me.txtStatus = Me.txtStatus & vbCrLf & Msg
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -