📄 frmdio.frm
字号:
Height = 255
Index = 1
Left = 3600
TabIndex = 39
Top = 960
Width = 615
End
Begin VB.OptionButton optBit
Caption = "OFF"
Height = 255
Index = 0
Left = 2880
TabIndex = 38
Top = 960
Value = -1 'True
Width = 615
End
Begin VB.TextBox txtCh
Height = 315
Left = 2400
TabIndex = 34
Text = "0"
Top = 960
Width = 450
End
Begin VB.CommandButton cmdWriteBit
Caption = "Write Bit DO"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 120
TabIndex = 33
Top = 840
Width = 1335
End
Begin VB.TextBox txtWrite
Height = 375
Left = 2880
TabIndex = 26
Text = "0"
Top = 360
Width = 1215
End
Begin VB.CommandButton cmdWrite
Caption = "Write DO"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 120
TabIndex = 25
Top = 360
Width = 1335
End
Begin VB.Label Label9
Caption = "Output Value"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 1560
TabIndex = 40
Top = 480
Width = 1215
End
Begin VB.Label Label6
Caption = "Channel"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Left = 1560
TabIndex = 35
Top = 960
Width = 720
End
End
Begin VB.Frame Frame1
Caption = "Step 1: Open COM Port"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1575
Left = 30
TabIndex = 1
Top = 60
Width = 4245
Begin VB.CommandButton cmdClose
Caption = "Close COM"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 2280
TabIndex = 21
Top = 960
Width = 1455
End
Begin VB.CommandButton cmdOpen
Caption = "Open COM Port"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 480
Left = 240
TabIndex = 6
Top = 945
Width = 1665
End
Begin VB.TextBox txtPort
Height = 330
Left = 990
TabIndex = 3
Text = "1"
Top = 450
Width = 570
End
Begin VB.TextBox txtBaudrate
Height = 390
Left = 2805
TabIndex = 2
Text = "9600"
Top = 420
Width = 960
End
Begin VB.Label Label1
Caption = "COM Port"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Left = 90
TabIndex = 5
Top = 480
Width = 810
End
Begin VB.Label Label2
Caption = "BaudRate"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 270
Left = 1830
TabIndex = 4
Top = 510
Width = 825
End
End
Begin VB.CommandButton cmdExit
Caption = "Exit"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 450
Left = 960
TabIndex = 0
Top = 4080
Width = 1725
End
End
Attribute VB_Name = "frmDIO"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim iPort As Integer
Dim iCheckSum As Integer
Dim iTimeOut As Integer
Dim lBaudrate As Long
Private Sub cmdClose_Click()
Me.Caption = " COM " + Str(iPort) + " Closed !"
Close_Com (iPort)
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdOpen_Click()
Dim iRet As Integer
iPort = CInt(txtPort.Text)
lBaudrate = CLng(txtBaudrate.Text)
iRet = Open_Com(iPort, lBaudrate, 8, 0, 0)
If iRet Then
MsgBox "Open COM Port Error:" + Str(iRet), vbCritical, "Open COM"
Else
Me.Caption = " COM " + Str(iPort) + " Opened !"
End If
End Sub
Private Sub cmdRead_Click()
Dim iRet As Integer
Dim DIVal As Long
Dim DOVal As Long
Dim iSlot As Integer
Dim iTotalDI As Integer
Dim iTotalDO As Integer
Dim iAddress As Integer
Dim DIBitArr(0 To 31) As Byte
Dim DOBitArr(0 To 31) As Byte
iAddress = CInt(txtAddress.Text)
If optCheck(0).Value = True Then
iCheckSum = 0
Else
iCheckSum = 1
End If
iTimeOut = CInt(txtTimeout.Text)
If optModule(0).Value = True Then
iSlot = -1
Else
iSlot = CInt(txtSlot.Text)
End If
iTotalDI = CInt(txtTotalDI.Text)
iTotalDO = CInt(txtTotalDO.Text)
iRet = DCON_Read_DIO(iPort, iAddress, iSlot, iTotalDI, iTotalDO, iCheckSum, iTimeOut, DIVal, DOVal, DIBitArr(0), DOBitArr(0))
If iRet = 0 Then
txtDI.Text = Hex(DIVal)
txtDO.Text = Hex(DOVal)
Else
txtDI.Text = "Error" & Str(iRet)
txtDO.Text = "Error" & Str(iRet)
End If
End Sub
Private Sub cmdWrite_Click()
Dim iRet As Integer
Dim DOVal As Long
Dim iSlot As Integer
Dim iTotalDO As Integer
Dim iAddress As Integer
iAddress = CInt(txtAddress.Text)
If optCheck(0).Value = True Then
iCheckSum = 0
Else
iCheckSum = 1
End If
iTimeOut = CInt(txtTimeout.Text)
If optModule(0).Value = True Then
iSlot = -1
Else
iSlot = CInt(txtSlot.Text)
End If
iTotalDO = CInt(txtTotalDO.Text)
DOVal = CLng("&h" & txtWrite.Text)
iRet = DCON_Write_DO(iPort, iAddress, iSlot, iTotalDO, DOVal, iCheckSum, iTimeOut)
If iRet Then
MsgBox "Error Code" & Str(iRet), vbCritical, "Error"
End If
End Sub
Private Sub cmdWriteBit_Click()
Dim iRet As Integer
Dim iBitVal As Integer
Dim iSlot As Integer
Dim iTotalDO As Integer
Dim iChannelIndex As Integer
Dim iAddress As Integer
iAddress = CInt(txtAddress.Text)
If optCheck(0).Value = True Then
iCheckSum = 0
Else
iCheckSum = 1
End If
iTimeOut = CInt(txtTimeout.Text)
If optModule(0).Value = True Then
iSlot = -1
Else
iSlot = CInt(txtSlot.Text)
End If
iTotalDO = CInt(txtTotalDO.Text)
If optBit(0).Value = True Then
iBitVal = 0
Else
iBitVal = 1
End If
iChannelIndex = CInt(txtCh.Text)
iRet = DCON_Write_DO_Bit(iPort, iAddress, iSlot, iChannelIndex, iTotalDO, iBitVal, iCheckSum, iTimeOut)
If iRet Then
MsgBox "Error Code" & Str(iRet), vbCritical, "Error"
End If
End Sub
Private Sub Form_Load()
If optModule(0).Value = True Then
txtSlot.Enabled = False
txtSlot.Text = "-1"
Else
txtSlot.Enabled = True
txtSlot.Text = "0"
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Close_Com (iPort)
End Sub
Private Sub optModule_Click(Index As Integer)
If Index = 0 Then
txtSlot.Enabled = False
txtSlot.Text = "-1"
Else
txtSlot.Enabled = True
txtSlot.Text = "0"
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -