vb6.0或vba用ppi协议怎么让s7-200的q0.1或q0.0置1,具体怎么写?
===================================
更新,谢谢楼下各位大侠们的回复,问题已经解决。在这留个记号,给有同样疑问的朋友们,以下是按PPI协议编写的一小段VBA程序,是把数据写入QB0存储器,使Q0.7~Q0.0口得到不同的状态。至于怎么从S7-200里读数据,网上有很多介绍的,百度一下即可。在楼下我也转载一些我从网上查到的资料供大家参考。(以下程序用S7-200仿真模拟软件\IASIMU107B测试过,能正常使用,但还没有在S7-200上测试,等测试完如有变化再更新):
Private Sub Q00_Click()
Q0_Value = &H1 ‘写给像我一样的PLC菜鸟:&H1是16进制的1,转换成八位二进制就是00000001,这是让Q 0.0=1;如果让Q0.1=1,则=&H2(八位二进制00000010);让Q0.2=1,则=&H4(八位二进制00000100);让Q0.1和Q0.0同时=1,则=&H3(八位二进制00000011);这个值可以是&H0~&HFF中的任意一个值,使Q0.7~Q0.0得到得到不同的状态
Write_Q0 (Q0_Value)
End Sub
Sub Write_Q0(ByRef Q0_Value)
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
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) = &H82
str_write(28) = &H0
str_write(29) = &H0
str_write(30) = &H0 ' 如果是改写Q0.x,这个地方就=&H0;如果是改写Q1.x,这个地方就是=&H8
str_write(31) = &H0
str_write(32) = &H4
str_write(33) = &H0
str_write(34) = &H8
str_write(35) = Q0_Value 'QB的值,也就是Q0.x或Q1.x的状态
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
End Sub
Private Sub UserForm_Initialize()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,e,8,1"
MSComm1.InputLen = 0
MSComm1.RThreshold = 24
MSComm1.InputMode = comInputModeBinary
MSComm1.PortOpen = True
End Sub
楼主最近还看过