?? frmmain.frm
字號:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmMain
BorderStyle = 1 'Fixed Single
Caption = "Basic Communications"
ClientHeight = 1155
ClientLeft = 2370
ClientTop = 2925
ClientWidth = 8205
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 1155
ScaleWidth = 8205
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton btnClear
Caption = "Clear"
Height = 285
Index = 2
Left = 7440
TabIndex = 7
Top = 480
Width = 615
End
Begin VB.CommandButton btnClear
Caption = "Clear"
Height = 285
Index = 1
Left = 7440
TabIndex = 6
Top = 120
Width = 615
End
Begin VB.TextBox txtResponse
BeginProperty Font
Name = "Times New Roman"
Size = 9
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 285
Left = 960
Locked = -1 'True
ScrollBars = 1 'Horizontal
TabIndex = 4
Top = 480
Width = 5655
End
Begin MSCommLib.MSComm MSComm1
Left = 6720
Top = 720
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = 0 'False
ParityReplace = 65
RThreshold = 1
End
Begin VB.CommandButton btnSend
Caption = "Send"
Height = 285
Index = 1
Left = 6720
TabIndex = 2
Top = 120
Width = 615
End
Begin VB.TextBox txtTextOut
BeginProperty Font
Name = "Times New Roman"
Size = 9
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 285
Left = 960
TabIndex = 1
Top = 120
Width = 5655
End
Begin MSComctlLib.StatusBar StatusBar1
Align = 2 'Align Bottom
Height = 255
Left = 0
TabIndex = 0
Top = 900
Width = 8205
_ExtentX = 14473
_ExtentY = 450
ShowTips = 0 'False
_Version = 393216
BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628}
NumPanels = 4
BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628}
Object.Width = 2117
MinWidth = 2117
Text = "Connected"
TextSave = "Connected"
EndProperty
BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628}
Object.Width = 1270
MinWidth = 1270
Text = "com1"
TextSave = "com1"
EndProperty
BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628}
Object.Width = 2258
MinWidth = 2258
Text = "9600 8N1"
TextSave = "9600 8N1"
EndProperty
BeginProperty Panel4 {8E3867AB-8586-11D1-B16A-00C0F0283628}
Object.Width = 1235
MinWidth = 1235
Text = "ASCII"
TextSave = "ASCII"
EndProperty
EndProperty
End
Begin VB.Label Label3
Caption = "Response:"
Height = 255
Left = 120
TabIndex = 5
Top = 480
Width = 855
End
Begin VB.Label Label2
Caption = "Output:"
Height = 255
Left = 120
TabIndex = 3
Top = 120
Width = 615
End
Begin VB.Menu mnuSettings
Caption = "&Settings"
Begin VB.Menu mnuPort
Caption = "&Port"
Begin VB.Menu mnuCom
Caption = "Com &1"
Checked = -1 'True
Index = 1
End
Begin VB.Menu mnuCom
Caption = "Com &2"
Index = 2
End
Begin VB.Menu mnuCom
Caption = "Com &3"
Index = 3
End
Begin VB.Menu mnuCom
Caption = "Com &4"
Index = 4
End
End
Begin VB.Menu mnuSpeed
Caption = "&Speed"
Begin VB.Menu mnuSpeedSel
Caption = "11&0"
Index = 0
End
Begin VB.Menu mnuSpeedSel
Caption = "&300"
Index = 1
End
Begin VB.Menu mnuSpeedSel
Caption = "&600"
Index = 2
End
Begin VB.Menu mnuSpeedSel
Caption = "&1,200"
Index = 3
End
Begin VB.Menu mnuSpeedSel
Caption = "&2,400"
Index = 4
End
Begin VB.Menu mnuSpeedSel
Caption = "&9,600"
Checked = -1 'True
Index = 5
End
Begin VB.Menu mnuSpeedSel
Caption = "14,400"
Index = 6
End
Begin VB.Menu mnuSpeedSel
Caption = "19,200"
Index = 7
End
Begin VB.Menu mnuSpeedSel
Caption = "28,800"
Index = 8
End
Begin VB.Menu mnuSpeedSel
Caption = "3&8,400"
Index = 9
End
Begin VB.Menu mnuSpeedSel
Caption = "56,000"
Index = 10
End
Begin VB.Menu mnuSpeedSel
Caption = "128,000"
Index = 11
End
Begin VB.Menu mnuSpeedSel
Caption = "256,000"
Index = 12
End
End
Begin VB.Menu mnuDataB
Caption = "&Data Bits"
Begin VB.Menu mnuDataBSel
Caption = "&4"
Index = 4
End
Begin VB.Menu mnuDataBSel
Caption = "&5"
Index = 5
End
Begin VB.Menu mnuDataBSel
Caption = "&6"
Index = 6
End
Begin VB.Menu mnuDataBSel
Caption = "&7"
Index = 7
End
Begin VB.Menu mnuDataBSel
Caption = "&8"
Checked = -1 'True
Index = 8
End
End
Begin VB.Menu mnuParity
Caption = "&Parity"
Begin VB.Menu mnuParitySel
Caption = "&Even"
Index = 0
End
Begin VB.Menu mnuParitySel
Caption = "&Mark"
Index = 1
End
Begin VB.Menu mnuParitySel
Caption = "&None"
Checked = -1 'True
Index = 2
End
Begin VB.Menu mnuParitySel
Caption = "&Odd"
Index = 3
End
Begin VB.Menu mnuParitySel
Caption = "&Space"
Index = 4
End
End
Begin VB.Menu mnuStop
Caption = "&Stop Bits"
Begin VB.Menu mnuStopSel
Caption = "&1"
Checked = -1 'True
Index = 0
End
Begin VB.Menu mnuStopSel
Caption = "1.&5"
Index = 1
End
Begin VB.Menu mnuStopSel
Caption = "&2"
Index = 2
End
End
End
Begin VB.Menu mnuView
Caption = "&View"
Begin VB.Menu mnuViewSel
Caption = "&Ascii"
Checked = -1 'True
Index = 0
End
Begin VB.Menu mnuViewSel
Caption = "&Hex"
Index = 1
End
End
Begin VB.Menu mnuConnect
Caption = "&Connect"
End
Begin VB.Menu mnuHelp
Caption = "&Help"
Begin VB.Menu mnuHelpSel
Caption = "&Basic Help"
Index = 0
End
Begin VB.Menu mnuHelpSel
Caption = "&About"
Index = 1
End
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Basic communications module
'Written by: M. Adam Davis
'Modified by Malcom Kemp 3/12/00
'
'This program will allow for the precise sending and receiving of characters
'to a communication port on the PC. You can sellect which port to use, and also
'select a bit rate speed for the port. You must "connect" from the menu to
'open the port. Then you can select to send either an ascii string, or a string
'of up to 12 hex characters. The characters are sent when the appropriate
'send button is pushed.
'
'The recieve string will escape non-pritable characters with the <x[x]>
'convention where xx represents the hex value of the character.
Option Explicit
Dim OutputAscii As Boolean
Dim InputString As String
Dim OutputString As String
Private Sub btnClear_Click(Index As Integer)
Dim i As Integer
Select Case Index
Case 1:
txtTextOut = ""
OutputString = ""
Case 2:
txtResponse = ""
InputString = ""
End Select
End Sub
Private Sub btnSend_Click(Index As Integer)
Select Case Index
Case 1 ' Send ascii string
send OutputString
End Select
End Sub
Sub send(txtin As String)
If MSComm1.PortOpen = True Then
MSComm1.Output = txtin
End If
End Sub
Function HexChar(strData As String) As Integer
Select Case strData
Case "0" To "9"
HexChar = Val(strData) - Val("0")
Case "a", "A"
HexChar = 10
Case "b", "B"
HexChar = 11
Case "c", "C"
HexChar = 12
Case "d", "D"
HexChar = 13
Case "e", "E"
HexChar = 14
Case "f", "F"
HexChar = 15
Case Else
HexChar = 0
End Select
End Function
Private Sub Form_Load()
Dim i As Integer
OutputAscii = True
For i = 1 To 2 ' Clear all input/output fields
btnClear_Click (i)
Next i
If Not ValidatePort Then
MsgBox "There are no available comm ports on this computer.", , "Commx"
End
End If
UpdateStatus
End Sub
Private Sub Form_Unload(Cancel As Integer)
If (MSComm1.PortOpen) Then
MSComm1.PortOpen = False
End If
End Sub
Private Sub mnuCom_Click(Index As Integer)
Dim i As Integer
Dim OldPort As Long
On Error Resume Next
With MSComm1
OldPort = .CommPort
If MSComm1.PortOpen Then
.PortOpen = False
.CommPort = Index
.PortOpen = True
If Err.Number <> 0 Then ' This should not happen...
MsgBox "Com" & Index & " is not available." & _
vbCrLf & Err.Description
Err.Clear
.CommPort = OldPort
Else
For i = 1 To 4
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -