problem communicating with TSX Momentum

H

Thread Starter

Henry

Hi Everybody
I’ve got a problem with communicating with a TSX Momentum – 171 CCC 780 10 IEC. (Modbus. rtu.) plc using visual basic. It works great with CONCEPT 2.5. Port 1 on both plc and computer. When I try to change a 4x register with vb it doesn’t work. I’ve connected the two computer port together to monitor the output. I got 161900149DB , all in same line. The program loaded into the plc reads Register 400401 (int.) then set output 1 to 16 hi, Respectfully. I’m trying to learn how to program plc then change their values using other languages. Currently I’m using Windows89 with (VB-3) and (VB-6)

comm1.CommPort = 1
comm1.CDTimeout = 0 'Carrier Detect time out.
comm1.CTSTimeout = 600 'Clear To Send time out
comm1.DSRTimeout = 600 ' Data Set Ready time out
comm1.DTREnable = True
comm1.Handshaking = 0
comm1.InBufferSize = 8192
comm1.InputLen = 0
comm1.NullDiscard = False
comm1.OutBufferSize = 8192
'comm1.ParityReplace = "?"
comm1.RThreshold = 1
comm1.RTSEnable = True ' request to send
comm1.Settings = "9600,e,8,1"
comm1.SThreshold = 1 'minimum characters --transmit buffer before control - CommEvent
comm1.CDHolding = True 'querying the state of Carrier Detect line
comm1.PortOpen = True ' number characters receive before communications control - CommEvent

address = 1 ‘Address = 1
Mode = 6 ‘ Mode = 6
RegistorLO = 1 ‘ Register = 400401
RegistorHI = 90
RegistorValueLO =0 ‘RegistorValue = 1
RegistorValueHI = 1

‘* * * CRC calculator * * *
crcsum# = &HFFFF&
crcshift# = &H0&
crcconst# = &HA001&
maxbyte = 6
For bytenum = 1 To maxbyte
Select Case bytenum
Case Is = 1: byt& = address
Case Is = 2: byt& = Mode
Case Is = 3: byt& = RegistorHI
Case Is = 4: byt& = RegistorLO
Case Is = 5: byt& = RegistorValueHI
Case Is = 6: byt& = RegistorValueLO
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 to comm. port * * *
comm1.Output = Hex(address) & Hex(Mode) & Hex(RegistorHI) & Hex(RegistorLO) & Hex(RegistorValueHI) & Hex(RegistorValueLO) & Hex(lower&) & Hex(upper&)

‘* * * * * * Read comm. Port * * * * *
For delay = 1 To 10000000: Next delay
Do: list2.AddItem comm2.Input
dud = DoEvents(): dum = dum + 1
If dum > 500 Then Exit Do
Loop
 
I'm not an expert and have only done modbus ascii mode in BASIC. I know message format and checksum calc changes for RTU. Did notice hi and lo order designations seem backwards to me though.

My comments marked with *****


> Hi Everybody
>Momentum – 171 CCC 780 10 IEC. (Modbus. rtu.)

***** RTU mode can be difficult with some software and hardware as timing is very critical. I've only used ascii before on my own coded basic drivers.

>I’ve connected the two computer port together to >monitor the output. I got 161900149DB , all in >same line.

***** somewhat irrelevent to RTU but, if using ascii mode the output for value 1 to register 400401 should be

:010601900001##

broken down as follows
: framing chr
01 address
06 function
01 register hi order
90 register lo order
00 data hi order
01 data lo order
## LRC checksum

Again in ASCII mode the following terms seem backwards to me

> RegistorLO = 1 ‘ Register = 400401
****** in ascii mode 01 is the HI order Byte or register HI

> RegistorHI = 90
****** in ascii mode 90 is the LO order Byte or Register LO


> RegistorValueLO =0 ‘RegistorValue = 1
> RegistorValueHI = 1

****** same thing for register values

Again none of my comments may be correct or applicable to RTU, I can't remember.

Once we got into VB we bought a canned 3rd party modbus driver from InGear. A bit expensive for one small app but can freely distribute runtime kernell in as many apps as you want.


Hope something helped
Reid
 
Top