Private Sub Q00_Click()
Q0_Value = &H1 ‘&H1是16进制的1,转换成八位二进制就是00000001,这是让Q0.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