Problem communicating with a TSX Momentum

H

Thread Starter

Henry

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&)
 
J
Assuming you are trying to talk to your Momentum with Modbus-RTU, I think there are few concepts you have yet to embrace regarding binary data transmission:

1) You need a datascope. Generally, the comm light on a Modicon box turns on when a valid Modbus message is transcieved. It is not an indication that data is being received.

2) Binary data and XON/XOFF are incompatible. ^Q and ^S are valid binary bytes and cannot be used for flow control at the same time.

3) Binary data and NullDiscard are incompatible. 0 is a valid binary character.

5) There is only ONE way to order the CRC, see the "Modbus Protocol Reference Guide" at "www.modicon.com":http://www.modicon.com . Any variation you have seen comes from the internal byte order in the words of a specific machine, not by the transmission order. See 1) and repeat until done.

Jay Kirsch
 
S

Sergio Toledano

The CRC is wrong, the correct value is 79 DB,
first you send MSB and then LSB (unlike register and value order). Check your CRC calc routine, there is something wrong.
best regards
eng. Sergio Toledano
Sucromer SA de CV
e-mail:[email protected]
 
<P>Thank you for the information. Now for a update. The CRC calculator works OK. I found some problems 10 minutes after l send that document. I was sending a LO and HI byte for both address and mode. (0000 0000 0000 0001)-(0000 0000 0000 0110)
I’ve corrected that and the modem settings. But it’s still no go. The program in the plc takes a REAL NUMBER from register 400400 then sends the appropriate output 1 to 16 HI. I’m begin to suspect the drivers or win 98. Let you know in a day or 2. Included is my binary calculator if you can find a use for it.</P>
<PRE>
'* * * * * * * * Clean up
For T = 1 To Len(perimeters)
V = Mid(perimeters, T, 1)
Select Case V
Case Is = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
v10 = v10 & V
End Select
Next
If Val(v10) > 65535 Then End
'* * * * * * Digit 1
If v10 >= 4096 Then v1 = v10 / 4096 Else v1 = 0
If v10 >= 4096 Then ValueHex1 = v10 \ 4096 Else ValueHex1 = 0
For Z = 1 To 4
Select Case Z
Case Is = 1
If v1 >= 8 Then binary1 = binary1 & "1" Else binary1 = binary1 & "0"
If v1 >= 8 Then v10 = v10 - 32768
If v1 >= 8 Then v1 = v1 - 8
Case Is = 2
If v1 >= 4 Then binary1 = binary1 & "1" Else binary1 = binary1 & "0"
If v1 >= 4 Then v10 = v10 - 16384
If v1 >= 4 Then v1 = v1 - 4
Case Is = 3
If v1 >= 2 Then binary1 = binary1 & "1" Else binary1 = binary1 & "0"
If v1 >= 2 Then v10 = v10 - 8192
If v1 >= 2 Then v1 = v1 - 2
Case Is = 4
If v1 >= 1 Then binary1 = binary1 & "1" Else binary1 = binary1 & "0"
If v1 >= 1 Then v10 = v10 - 4096
If v1 >= 1 Then v1 = v1 - 1
End Select
Next Z
'* * * * * * Digit 2
If v10 >= 256 Then v2 = v10 / 256 Else v2 = 0
If v10 >= 256 Then ValueHex2 = v10 \ 256 Else ValueHex2 = 0
For Z = 1 To 4
Select Case Z
Case Is = 1
If v2 >= 8 Then binary2 = binary2 & "1" Else binary2 = binary2 & "0"
If v2 >= 8 Then v10 = v10 - 2048
If v2 >= 8 Then v2 = v2 - 8
Case Is = 2
If v2 >= 4 Then binary2 = binary2 & "1" Else binary2 = binary2 & "0"
If v2 >= 4 Then v10 = v10 - 1024
If v2 >= 4 Then v2 = v2 - 4
Case Is = 3
If v2 >= 2 Then binary2 = binary2 & "1" Else binary2 = binary2 & "0"
If v2 >= 2 Then v10 = v10 - 512
If v2 >= 2 Then v2 = v2 - 2
Case Is = 4
If v2 >= 1 Then binary2 = binary2 & "1" Else binary2 = binary2 & "0"
If v2 >= 1 Then v10 = v10 - 256
If v2 >= 1 Then v2 = v2 - 1
End Select
Next Z
For HI = 0 To 255
If Len(Hex(HI)) = 1 Then Hi1 = "0" & Hex(HI) Else Hi1 = Hex(HI)
If Hi1 = Hex(ValueHex1) & Hex(ValueHex2) Then Exit For
Next
'* * * * * * Digit 3
If v10 >= 16 Then v3 = v10 / 16 Else v3 = 0
If v10 >= 16 Then ValueHex3 = v10 \ 16 Else ValueHex3 = 0
For Z = 1 To 4
Select Case Z
Case Is = 1
If v3 >= 8 Then binary3 = binary3 & "1" Else binary3 = binary3 & "0"
If v3 >= 8 Then v10 = v10 - 128
If v3 >= 8 Then v3 = v3 - 8
Case Is = 2
If v3 >= 4 Then binary3 = binary3 & "1" Else binary3 = binary3 & "0"
If v3 >= 4 Then v10 = v10 - 64
If v3 >= 4 Then v3 = v3 - 4
Case Is = 3
If v3 >= 2 Then binary3 = binary3 & "1" Else binary3 = binary3 & "0"
If v3 >= 2 Then v10 = v10 - 32
If v3 >= 2 Then v3 = v3 - 2
Case Is = 4
If v3 >= 1 Then binary3 = binary3 & "1" Else binary3 = binary3 & "0"
If v3 >= 1 Then v10 = v10 - 16
If v3 >= 1 Then v3 = v3 - 1
End Select
Next Z
'* * * * * * Digit 4
If v10 >= 1 Then v4 = v10 / 1 Else v4 = 0
If v10 >= 1 Then ValueHex4 = v10 \ 1 Else ValueHex4 = 0
For Z = 1 To 4
Select Case Z
Case Is = 1
If v4 >= 8 Then binary4 = binary4 & "1" Else binary4 = binary4 & "0"
If v4 >= 8 Then v10 = v10 - 8
If v4 >= 8 Then v4 = v4 - 8
Case Is = 2
If v4 >= 4 Then binary4 = binary4 & "1" Else binary4 = binary4 & "0"
If v4 >= 4 Then v10 = v10 - 4
If v4 >= 4 Then v4 = v4 - 4
Case Is = 3
If v4 >= 2 Then binary4 = binary4 & "1" Else binary4 = binary4 & "0"
If v4 >= 2 Then v10 = v10 - 2
If v4 >= 2 Then v4 = v4 - 2
Case Is = 4
If v4 >= 1 Then binary4 = binary4 & "1" Else binary4 = binary4 & "0"
If v4 >= 1 Then v10 = v10 - 1
If v4 >= 1 Then v4 = v4 - 1
End Select
Next Z
For LO = 0 To 255
If Len(Hex(LO)) = 1 Then Lo1 = "0" & Hex(LO) Else Lo1 = Hex(LO)
If Lo1 = Hex(ValueHex3) & Hex(ValueHex4) Then Exit For
Next
List1.AddItem perimeters
List1.AddItem "CRC hi = " & Hex(HI) & " lo = " & Hex(LO)
List1.AddItem "binary = " & binary1 & " " & binary2 & " - " & binary3 & " " & binary4
List1.AddItem "ValueHex = " & ValueHex1 & " " & ValueHex2 & " - " & ValueHex3 & " " & ValueHex4
List1.AddItem ""
</PRE>
 
A

Andrzej Sokulski

Hi Henry
Don't set handshaking for communication with TSX Momentum.

Set only::

MSComm1.CommPort = 1:
MSComm1.Settings = "9600,e,8,1":
MSComm1.InputLen = 0:
MSComm1.PortOpen = True

For CRC You can use my VB fuction:

Function CRC_16(OutputString As String) As String
Dim Generator, CRC As Long
Dim i As Integer, j As Integer, Length As Integer
Dim Bit As Boolean
Dim Temp As Byte
Length = Len(OutputString)
CRC = 65535
Generator = 40961

For i = 1 To Length
Temp = Asc(Mid(OutputString, i, 1))
CRC = CRC Xor Temp
For j = 1 To 8
Bit = CRC And 1
CRC = CRC \ 2
If Bit = True Then
CRC = CRC Xor Generator
End If
Next j
Next i
CRC_16 = Chr(CRC Mod 256) & Chr(CRC \ 256)
End Function

Best Regards
Andrzej Sokulski
 
The output statment should read something like this, then it works (Thank A Lot) hope you can use the binary cal.

MSComm1.Output = chr(Address1) & chr(Address2) & chr(Mode1) & chr(Mode2) & Hex(Registor1) & & & & &

Henry
 
Top