📄 wwwj.frm
字号:
TabIndex = 40
Top = 480
Width = 615
End
Begin VB.Menu shezhi
Caption = "设置(&s)"
Begin VB.Menu mac
Caption = "mac"
End
End
Begin VB.Menu duqu
Caption = "数据(&d)"
Begin VB.Menu dd
Caption = "readonly"
End
Begin VB.Menu genggai
Caption = "data"
End
End
Begin VB.Menu dakai
Caption = "XLS"
Begin VB.Menu opxls
Caption = "readonlyXLS"
End
Begin VB.Menu op1XLS
Caption = "dataXLS"
End
End
Begin VB.Menu right
Caption = "right"
Visible = 0 'False
Begin VB.Menu r1
Caption = "mac"
End
Begin VB.Menu r2
Caption = "readonly"
End
Begin VB.Menu r3
Caption = "readonlyXLS"
End
Begin VB.Menu r4
Caption = "data"
End
Begin VB.Menu r5
Caption = "dataXLS"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Base 1
Dim sent() As Byte '接收var中的值
'Dim oleExcel As Object
Dim a As Integer, plc As String, plc1 As String, jiaoyan As String
Public comnum As Integer
Dim oleExcel As Object
Private Sub main()
Load Form2
Form1.Show
End Sub
Private Sub form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button And vbRightButton Then
PopupMenu right '菜单名称为mnuFile
End If
End Sub
Private Sub Command3_Click()
Call ClearText
Combo1.SetFocus
End Sub
Private Sub Command4_Click()
Dim i As Integer
i = MsgBox("确认退出?", 1 + 256 + 4096, "提示")
If i = 2 Then Exit Sub
End
End Sub
Private Sub Command5_Click()
Dim i As Integer, s As String
s = Year(Date) & "年" & Month(Date) & "月" & Day(Date) & "日" & " " & Time
Adodc1.Recordset.MoveLast
Adodc1.Recordset.AddNew
For i = 1 To 48
Text12(96 - i).Text = Text12(i - 1)
' oleExcel.Worksheets("sheep1").Range("A(i)").Cells(1, 1) = Text12(96 - i).Text
Next i
Text2 = s
Adodc1.Recordset.MoveFirst
Command5.Enabled = False
End Sub
Private Sub Command6_Click()
Picture1.Visible = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unload Me
End Sub
Private Sub genggai_Click()
' Form1.Hide
Form2.Hide
Form3.Show
Form1.Hide
If MSComm1.PortOpen Then
MSComm1.PortOpen = False '打开通信端口
End If
End Sub
Private Sub dd_Click()
'
Form3.Hide
Form2.Show
Form1.Hide
End Sub
Private Sub Form_Load()
Dim i As Integer
comnum = InputBox("请输入串口号", "", "1")
Command5.Enabled = False
For i = 1 To 48
Text12(96 - i).DataField = i
Next
ClearText
Command2.Enabled = False
textenabled (0)
With MSComm1
'If .CommPort <> 1 Then
.CommPort = comnum '设置Com2为通信端口
.Settings = "9600,N,8,1" '设置通信端口参数 9600赫兹、无校验、8个数据位、1个停止位.(这里需要进一步说明的是:.Setting=”BBBB,P,D,S”。
'含义是:B:Baud Rate(波特率);P:Parity(奇偶);D:Data Bit;S:Stop Bit)
.InBufferSize = 1024 '设置缓冲区接收数据为1024字节
.OutBufferSize = 512
.InputMode = comInputModeText '设置数据接收模式为16进制形式
.InputLen = 1 '设置Input一次从接收缓冲读取字节数为1
.RThreshold = 1 '设置接收一个字节就产生OnComm事件
.OutBufferCount = 0 '清空发送缓冲区
.InBufferCount = 0 '滑空接收缓冲区
If Not .PortOpen Then
.PortOpen = True '打开通信端口
End If
End With
' MSComm1.Output = "e"
' DoEvents
' delay (1000)
' Call yanzheng
End Sub
Private Sub yanzheng()
Dim i As Integer
Do While (1 = 1)
' MSComm1.Output = "e"
' MSComm1.OutBufferCount = 0 '清空发送缓冲区
'delay (10000)
DoEvents
If jiaoyan = "ok" Then
Exit Do
Else:
i = MsgBox("取消退出程序", 1 + 48 + 0, "通信故障")
If i = 2 Then
Call Command4_Click
ElseIf i = 1 Then
Exit Do
' ElseIf i = 4 Then
' MSComm1.PortOpen = False
' Call Form_Load
End If
End If
Loop
End Sub
Private Sub Command1_Click() '设置完成
Dim i As Integer
Dim X, Y, z As Integer
If Check1.Value = 1 Then
If Option1.Value = True Then
If Option3.Value = True Then
plc = "08A0"
ElseIf Option4.Value = True Then
plc = "00A0"
End If
ElseIf Option2.Value = True Then
If Option3.Value = True Then
plc = "0820"
ElseIf Option4.Value = True Then
plc = "0020"
End If
End If
ElseIf Check2.Value = 1 Then
If Option1.Value = True Then
If Option3.Value = True Then
plc = "1880"
ElseIf Option4.Value = True Then
plc = "1080"
End If
ElseIf Option2.Value = True Then
If Option3.Value = True Then
plc = "1800"
ElseIf Option4.Value = True Then
plc = "1000"
End If
End If
ElseIf Check3.Value = 1 Then
If Option1.Value = True Then
If Option3.Value = True Then
plc = "0880"
ElseIf Option4.Value = True Then
plc = "0080"
End If
ElseIf Option2.Value = True Then
If Option3.Value = True Then
plc = "0800"
ElseIf Option4.Value = True Then
plc = "0000"
End If
End If
End If
plc1 = Text4.Text & Text5.Text & Text6.Text & Text9.Text & Text13.Text & Text14.Text
If Len(plc1) < 12 Then
MsgBox "请输入完整12位 MAC Add_Source(Hex) 地址", 48, "提示"
Text4.SetFocus
Exit Sub
End If
plc1 = plc1 & Text15.Text & Text16.Text & Text17.Text & Text18.Text & Text19.Text & Text20.Text
If Len(plc1) < 24 Then
MsgBox "请输入完整12位 MAC Add_Dest(Hex) 地址", 48, "提示"
Text15.SetFocus
Exit Sub
End If
MSComm1.Output = "a"
Call delay(100)
Label25.BackColor = &HFF& '灯
Command2.Enabled = True
Command2.SetFocus
' textenabled (False)
Picture1.Visible = False
MSComm1.OutBufferCount = 0 '清空发送缓冲区
MSComm1.InBufferCount = 0 '滑空接收缓冲区
Call qingkong
Call sentdate
a = 0
'Next i
genggai.Enabled = True
End Sub
Private Sub qingkong()
Dim i As Integer
For i = 0 To 47
Text12(i).Text = ""
Next i
End Sub
Private Sub Command2_Click()
Static i As Integer
If Not MSComm1.PortOpen Then
MSComm1.PortOpen = True '打开通信端口
End If
If i = 0 Then
Command2.Caption = "暂停"
Label25.BackColor = &HFF00&
Command5.Enabled = False
Timer1.Enabled = True
i = i + 1
MSComm1.InBufferCount = 0 '滑空接收缓冲区
genggai.Enabled = False
' a = 0
' Call qingkong
' MSComm1.Output = "b"
' MSComm1.Output = "c"
' MSComm1.OutBufferCount = 0
' mac.Enabled = False
a = 0
' Form2.Command2 = True
Else
Command2.Caption = "运行"
Label25.BackColor = &HFF&
Command5.Enabled = True
Timer1.Enabled = False
i = 0
MSComm1.InBufferCount = 0 '滑空接收缓冲区
MSComm1.Output = "c"
MSComm1.OutBufferCount = 0
' MSComm1.Output = "c"
mac.Enabled = True
genggai.Enabled = True
' Form2.Command2 = False
End If
End Sub
Private Sub mac_Click()
Picture1.Visible = True
textenabled (1)
Combo1.SetFocus
If Not MSComm1.PortOpen Then
MSComm1.PortOpen = True '打开通信端口
End If
genggai.Enabled = False
Combo1.SetFocus
End Sub
Private Sub MSComm1_OnComm()
' DelayTime ‘用来延续时间
Static j As Integer
Dim b As String
Static c As String
b = CStr(MSComm1.Input)
If j = 1 Then
For j = 0 To 47
Text12(j).Text = ""
Next j
End If
' DoEvents
' If jiaoyan <> "ok" Then
' If b = Chr(13) Then
' jiaoyan = c
'
' Print jiaoyan
' c = ""
' Else:
' c = c & (b)
' End If
' Else
If b = Chr(13) Then
a = a + 1
Else:
Text12(a).Text = Text12(a).Text & b
End If
' End If
If a = 48 Then
a = 0
MSComm1.OutBufferCount = 0
' MSComm1.InBufferCount = 0
j = 1
If Command1.Enabled = False Then MSComm1.Output = "b"
End If
End Sub
Private Sub sentdate()
Dim i As Integer
Dim s As String
'Print "s"
ReDim sent(3)
sent(1) = Combo1.Text
sent(2) = Combo2.Text
If Combo3.ListIndex = 1 Then
sent(3) = 2
Else
sent(3) = 1
End If
MSComm1.Output = sent
MSComm1.OutBufferCount = 0
ReDim sent(24)
s = plc1
s = UCase(s)
For i = 1 To 24
sent(i) = Asc(Mid(s, i, 1))
' Print sent(i);
Next i
MSComm1.Output = sent
MSComm1.OutBufferCount = 0
ReDim sent(10)
' Print
If Len(Text7) < 10 Then
Text7.Text = String(10 - Len(Text7), "0") & Text7.Text
End If
s = Text7.Text
s = UCase(s)
For i = 1 To 10
sent(i) = Asc(Mid(s, i, 1))
' Print sent(i);
Next i
MSComm1.Output = sent
MSComm1.OutBufferCount = 0
ReDim sent(10)
' Print
If Len(Text8) < 10 Then
Text8.Text = String(10 - Len(Text8), "0") & Text8.Text
End If
s = Text8.Text
s = UCase(s)
For i = 1 To 10
sent(i) = Asc(Mid(s, i, 1))
' Print sent(i);
Next i
MSComm1.Output = sent
MSComm1.OutBufferCount = 0
ReDim sent(4)
s = CStr(plc)
For i = 1 To 4
sent(i) = Asc(Mid(s, i, 1))
' Print sent(i);
Next i
MS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -