H
Hi Everybody
I’ve got a problem with communicating with a TSX Momentum – 171 CCC 780 10 plc using visual basic. It works great with CONCEPT 2.5. Port 1 on both plc and computer. But when I try to change a 4x register with vb. It doesn’t work, it seem like I’m not communicate. The [com-act] light stays off. Oncomm. comEvSend says OutBufferCount = 0 byte sent. The following is a short program I’m trying to send. (Windows 89) (Visual basic 6) Output in hex = 01 06 018F 0009 79 F9; setting register 400400 to 9. Also when sending the crc, do you first send the lower or upper? I’ve seen example in both ways::
* * * * * com port setting * * * * * * *
MSComm1.CommPort = 1:
MSComm1.Settings = "9600,e,8,1":
MSComm1.RThreshold = 32 ' String length :
MSComm1.InBufferCount = 0:
MSComm1.InputLen = 0:
MSComm1.DTREnable = -1 'True:
MSComm1.Handshaking = 3 'com/RTSxon/xoff:
MSComm1.NullDiscard = -1 'True:
MSComm1.RTSEnable = -1 'True:
MSComm1.InputMode = 1 ' binary:
MSComm1.PortOpen = True
'* * * * * * * plc value settings* * * * * * *
Address1 = 0
Address2 = 1
Mode1 = 0
Mode2 = 6
Registor1 = 0
Registor2 = 1
Registor3 = 8
Registor4 = 15
RegistorValue1 = 0
RegistorValue2 = 0
RegistorValue3 = 0
RegistorValue4 = 9
'* * * * crc calculator * * * * * * * * *
crcsum# = &HFFFF&
crcshift# = &H0&
crcconst# = &HA001&
maxbyte = 6
For bytenum = 1 To maxbyte
Select Case bytenum
Case Is = 1: byt& = Address1 & Address2
Case Is = 2: byt& = Mode1 & Mode2
Case Is = 3: byt& = Registor1 & Registor2
Case Is = 4: byt& = Registor3 & Registor4
Case Is = 5: byt& = RegistorValue1 &
RegistorValue2
Case Is = 6: byt& = RegistorValue3 &
RegistorValue4
End Select
byt& = byt& And &HFF&
crcsum# = (crcsum# Xor byt&) And &HFFFF&
For shift = 1 To 8
crcshift# = (Int(crcsum# / 2)) And &H7FFF&
If crcsum# And &H1& Then
crcsum# = crcshift# Xor crcconst#
Else
crcsum# = crcshift#
End If
Next shift
Next bytenum
lower& = crcsum# And &HFF&
upper& = (Int(crcsum# / 256)) And &HFF&
' * * * * * * * Send out to com port * * * * * **
MSComm1.Output = Hex(Address1) & Hex(Address2) & Hex(Mode1) & Hex(Mode2) & Hex(Registor1) & Hex
(Registor2) & Hex(Registor3) & Hex(Registor4) &
Hex(RegistorValue1) & Hex(RegistorValue2) & Hex
(RegistorValue3) & Hex(RegistorValue4) & Hex
(lower&) & Hex(upper&)
I’ve got a problem with communicating with a TSX Momentum – 171 CCC 780 10 plc using visual basic. It works great with CONCEPT 2.5. Port 1 on both plc and computer. But when I try to change a 4x register with vb. It doesn’t work, it seem like I’m not communicate. The [com-act] light stays off. Oncomm. comEvSend says OutBufferCount = 0 byte sent. The following is a short program I’m trying to send. (Windows 89) (Visual basic 6) Output in hex = 01 06 018F 0009 79 F9; setting register 400400 to 9. Also when sending the crc, do you first send the lower or upper? I’ve seen example in both ways::
* * * * * com port setting * * * * * * *
MSComm1.CommPort = 1:
MSComm1.Settings = "9600,e,8,1":
MSComm1.RThreshold = 32 ' String length :
MSComm1.InBufferCount = 0:
MSComm1.InputLen = 0:
MSComm1.DTREnable = -1 'True:
MSComm1.Handshaking = 3 'com/RTSxon/xoff:
MSComm1.NullDiscard = -1 'True:
MSComm1.RTSEnable = -1 'True:
MSComm1.InputMode = 1 ' binary:
MSComm1.PortOpen = True
'* * * * * * * plc value settings* * * * * * *
Address1 = 0
Address2 = 1
Mode1 = 0
Mode2 = 6
Registor1 = 0
Registor2 = 1
Registor3 = 8
Registor4 = 15
RegistorValue1 = 0
RegistorValue2 = 0
RegistorValue3 = 0
RegistorValue4 = 9
'* * * * crc calculator * * * * * * * * *
crcsum# = &HFFFF&
crcshift# = &H0&
crcconst# = &HA001&
maxbyte = 6
For bytenum = 1 To maxbyte
Select Case bytenum
Case Is = 1: byt& = Address1 & Address2
Case Is = 2: byt& = Mode1 & Mode2
Case Is = 3: byt& = Registor1 & Registor2
Case Is = 4: byt& = Registor3 & Registor4
Case Is = 5: byt& = RegistorValue1 &
RegistorValue2
Case Is = 6: byt& = RegistorValue3 &
RegistorValue4
End Select
byt& = byt& And &HFF&
crcsum# = (crcsum# Xor byt&) And &HFFFF&
For shift = 1 To 8
crcshift# = (Int(crcsum# / 2)) And &H7FFF&
If crcsum# And &H1& Then
crcsum# = crcshift# Xor crcconst#
Else
crcsum# = crcshift#
End If
Next shift
Next bytenum
lower& = crcsum# And &HFF&
upper& = (Int(crcsum# / 256)) And &HFF&
' * * * * * * * Send out to com port * * * * * **
MSComm1.Output = Hex(Address1) & Hex(Address2) & Hex(Mode1) & Hex(Mode2) & Hex(Registor1) & Hex
(Registor2) & Hex(Registor3) & Hex(Registor4) &
Hex(RegistorValue1) & Hex(RegistorValue2) & Hex
(RegistorValue3) & Hex(RegistorValue4) & Hex
(lower&) & Hex(upper&)