⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form3.frm

📁 西门子ppi协议 vb程序 实现plc与上位机之间的通信
💻 FRM
📖 第 1 页 / 共 5 页
字号:
Sleep (50)
str_write(0) = &H68
str_write(1) = &H20
str_write(2) = &H20
str_write(3) = &H68
str_write(4) = &H2
str_write(5) = &H0
str_write(6) = &H7C
str_write(7) = &H32
str_write(8) = &H1
str_write(9) = &H0
str_write(10) = &H0
str_write(11) = &H0
str_write(12) = &H0
str_write(13) = &H0
str_write(14) = &HE
str_write(15) = &H0
str_write(16) = &H5
str_write(17) = &H5
str_write(18) = &H1
str_write(19) = &H12
str_write(20) = &HA
str_write(21) = &H10
str_write(22) = &H2
str_write(23) = &H0
str_write(24) = &H1
str_write(25) = &H0
str_write(26) = &H1
str_write(27) = &H84
str_write(28) = &H0
str_write(29) = &H0
str_write(30) = &H0
str_write(31) = &H0
str_write(32) = &H4
str_write(33) = &H0
str_write(34) = &H8

If button1.Value = True Then

str_write(35) = haha
Else: str_write(35) = haha
End If

For i = 4 To 35
    Temp_FCS = Temp_FCS + str_write(i)
    Next
str_write(36) = Temp_FCS Mod 256
str_write(37) = &H16
MSComm1.Output = str_write
Sleep (50)
str_val(0) = &H10
str_val(1) = &H2
str_val(2) = &H0
str_val(3) = &H5C
str_val(4) = &H5E
str_val(5) = &H16

MSComm1.Output = str_val

Timer1.Enabled = True

End Sub

Private Sub button8_Click()
Dim str_write(0 To 37) As Byte
Dim str_val(0 To 5) As Byte
Dim haha As Byte
Dim i As Integer
Dim Temp_FCS As Variant

MSComm1.RThreshold = 24
Timer1.Enabled = False
haha = q0 Xor &H1
Sleep (50)
str_write(0) = &H68
str_write(1) = &H20
str_write(2) = &H20
str_write(3) = &H68
str_write(4) = &H2
str_write(5) = &H0
str_write(6) = &H7C
str_write(7) = &H32
str_write(8) = &H1
str_write(9) = &H0
str_write(10) = &H0
str_write(11) = &H0
str_write(12) = &H0
str_write(13) = &H0
str_write(14) = &HE
str_write(15) = &H0
str_write(16) = &H5
str_write(17) = &H5
str_write(18) = &H1
str_write(19) = &H12
str_write(20) = &HA
str_write(21) = &H10
str_write(22) = &H2
str_write(23) = &H0
str_write(24) = &H1
str_write(25) = &H0
str_write(26) = &H1
str_write(27) = &H84
str_write(28) = &H0
str_write(29) = &H0
str_write(30) = &H0
str_write(31) = &H0
str_write(32) = &H4
str_write(33) = &H0
str_write(34) = &H8

If button1.Value = True Then

str_write(35) = haha
Else: str_write(35) = haha
End If

For i = 4 To 35
    Temp_FCS = Temp_FCS + str_write(i)
    Next
str_write(36) = Temp_FCS Mod 256
str_write(37) = &H16
MSComm1.Output = str_write
Sleep (50)
str_val(0) = &H10
str_val(1) = &H2
str_val(2) = &H0
str_val(3) = &H5C
str_val(4) = &H5E
str_val(5) = &H16

MSComm1.Output = str_val

Timer1.Enabled = True
Sleep (100)
End Sub

Private Sub button9_Click()
Dim str_write(0 To 37) As Byte
Dim str_val(0 To 5) As Byte
Dim haha As Byte
Dim i As Integer
Dim Temp_FCS As Variant

MSComm1.RThreshold = 24
Timer1.Enabled = False
haha = q1 Xor &H80
Sleep (50)
str_write(0) = &H68
str_write(1) = &H20
str_write(2) = &H20
str_write(3) = &H68
str_write(4) = &H2
str_write(5) = &H0
str_write(6) = &H7C
str_write(7) = &H32
str_write(8) = &H1
str_write(9) = &H0
str_write(10) = &H0
str_write(11) = &H0
str_write(12) = &H0
str_write(13) = &H0
str_write(14) = &HE
str_write(15) = &H0
str_write(16) = &H5
str_write(17) = &H5
str_write(18) = &H1
str_write(19) = &H12
str_write(20) = &HA
str_write(21) = &H10
str_write(22) = &H2
str_write(23) = &H0
str_write(24) = &H1
str_write(25) = &H0
str_write(26) = &H1
str_write(27) = &H84
str_write(28) = &H0
str_write(29) = &H0
str_write(30) = &H8
str_write(31) = &H0
str_write(32) = &H4
str_write(33) = &H0
str_write(34) = &H8

If button1.Value = True Then

str_write(35) = haha
Else: str_write(35) = haha
End If

For i = 4 To 35
    Temp_FCS = Temp_FCS + str_write(i)
    Next
str_write(36) = Temp_FCS Mod 256
str_write(37) = &H16
MSComm1.Output = str_write
Sleep (50)
str_val(0) = &H10
str_val(1) = &H2
str_val(2) = &H0
str_val(3) = &H5C
str_val(4) = &H5E
str_val(5) = &H16

MSComm1.Output = str_val

Timer1.Enabled = True

End Sub

Private Sub Command41_Click()
Form1.Show
Unload Form3
End Sub


Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,e,8,1"
MSComm1.InputLen = 0

MSComm1.InputMode = comInputModeBinary
MSComm1.PortOpen = True
End Sub

Private Sub MSComm1_OnComm()
Dim dis_array As String
Dim rcv_array() As Byte
Dim rcv_len As Long
Dim i As Integer
Dim qa As Byte
Dim qb As Byte
Dim qc As Byte
Dim qd As Byte
Dim qe As Byte
Dim qf As Byte
Dim qg As Byte
Dim qh As Byte
Dim qa1 As Byte
Dim qb1 As Byte
Dim qc1 As Byte
Dim qd1 As Byte
Dim qe1 As Byte
Dim qf1 As Byte
Dim qg1 As Byte
Dim qh1 As Byte
Dim Ia0 As Byte
Dim Ib0 As Byte
Dim Ic0 As Byte
Dim Id0 As Byte
Dim Ie0 As Byte
Dim If0 As Byte
Dim Ig0 As Byte
Dim Ih0 As Byte
Dim Ia1 As Byte
Dim Ib1 As Byte
Dim Ic1 As Byte
Dim Id1 As Byte
Dim Ie1 As Byte
Dim If1 As Byte
Dim Ig1 As Byte
Dim Ih1 As Byte
Dim Ia2 As Byte
Dim Ib2 As Byte
Dim Ic2 As Byte
Dim Id2 As Byte
Dim Ie2 As Byte
Dim If2 As Byte
Dim Ig2 As Byte
Dim Ih2 As Byte

rcv_array = MSComm1.Input
 rcv_len = UBound(rcv_array)
 If rcv_len = 32 Then


q0 = rcv_array(26)
q1 = rcv_array(27)
i0 = rcv_array(28)
i1 = rcv_array(29)
i2 = rcv_array(30)

'******q0 开关状态***************************************
qa = q0 And 128
If qa = 128 Then
button1.Value = True
End If

If qa = 0 Then
button1.Value = False
End If


qb = q0 And 64
If qb = 64 Then
button2.Value = True
End If

If qb = 0 Then
button2.Value = False
End If


qc = q0 And 32
If qc = 32 Then
button3.Value = True
End If
If qc = 0 Then
button3.Value = False
End If


qd = q0 And 16
If qd = 16 Then
button4.Value = True
End If

If qd = 0 Then
button4.Value = False
End If

qe = q0 And 8
If qe = 8 Then
button5.Value = True
End If

If qe = 0 Then
button5.Value = False
End If

qf = q0 And 4
If qf = 4 Then
button6.Value = True
End If

If qf = 0 Then
button6.Value = False
End If

qg = q0 And 2
If qg = 2 Then
button7.Value = True
End If

If qg = 0 Then
button7.Value = False
End If

qh = q0 And 1
If qh = 1 Then
button8.Value = True
End If

If qh = 0 Then
button8.Value = False
End If


'******q1 开关状态*****************************************
qa1 = q1 And 128
If qa1 = 128 Then
button9.Value = True
End If

If qa1 = 0 Then
button9.Value = False
End If


qb1 = q1 And 64
If qb1 = 64 Then
button10.Value = True
End If

If qb1 = 0 Then
button10.Value = False
End If


qc1 = q1 And 32
If qc1 = 32 Then
button11.Value = True
End If
If qc1 = 0 Then
button11.Value = False
End If


qd1 = q1 And 16
If qd1 = 16 Then
button12.Value = True
End If

If qd1 = 0 Then
button12.Value = False
End If

qe1 = q1 And 8
If qe1 = 8 Then
button13.Value = True
End If

If qe1 = 0 Then
button13.Value = False
End If

qf1 = q1 And 4
If qf1 = 4 Then
button14.Value = True
End If

If qf1 = 0 Then
button14.Value = False
End If

qg1 = q1 And 2
If qg1 = 2 Then
button15.Value = True
End If

If qg1 = 0 Then
button15.Value = False
End If

qh1 = q1 And 1
If qh1 = 1 Then
button16.Value = True
End If

If qh1 = 0 Then
button16.Value = False
End If
'********I0 开关状态*********************************************
Ia0 = i0 And 128
If Ia0 = 128 Then
button17.Value = True
End If

If Ia0 = 0 Then
button17.Value = False
End If


Ib0 = i0 And 64
If Ib0 = 64 Then
button18.Value = True
End If

If Ib0 = 0 Then
button18.Value = False
End If


Ic0 = i0 And 32
If Ic0 = 32 Then
button19.Value = True
End If
If Ic0 = 0 Then
button19.Value = False
End If


Id0 = i0 And 16
If Id0 = 16 Then
button20.Value = True
End If

If Id0 = 0 Then
button20.Value = False
End If

Ie0 = i0 And 8
If Ie0 = 8 Then
button21.Value = True
End If

If Ie0 = 0 Then
button21.Value = False
End If

If0 = i0 And 4
If If0 = 4 Then
button22.Value = True
End If

If If0 = 0 Then
button22.Value = False
End If

Ig0 = i0 And 2
If Ig0 = 2 Then
button23.Value = True
End If

If Ig0 = 0 Then
button23.Value = False
End If

Ih0 = i0 And 1
If Ih0 = 1 Then
button24.Value = True
End If

If Ih0 = 0 Then
button24.Value = False
End If
'*******I1 开关状态**************************************************
Ia1 = i1 And 128
If Ia1 = 128 Then
button25.Value = True
End If

If Ia1 = 0 Then
button25.Value = False
End If


Ib1 = i1 And 64
If Ib1 =

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -