Im a new user on Super PLC. Currently Im using FMD1616-10 to controlling slave device Autonics Temperature Controller TK4M with RS485.
The slave device can communicating with Modbus RTU Protocol.
The slave device ID is 1.
Im trying to access temperature value in that device. The address of present value is 03E8H, with function 04.
Im using the hard code from an example in this forum.
this is my code
Function first_setSETPROTOCOL 3,1
Function read_autonicsA = &H03
B = &HE8
N = &H0A
FOR I = 0 TO 1
Z = INCOMM(3)
NEXT
call read_modbus
Function read_modbus' This function implements MODBUS RTU function 04 using the INCOMM and
' OUTCOMM commands.
' The address to be read is in A
' The number of channel to be read is in N
' The data are returned in DM[201] to DM[201+N]
' DM[101] to DM[200] are used by this function
DM[101] = &H01 ' node address of slave
DM[102] = &H04 ' function 04
DM[103] = A ' upper 8 bit of address
DM[104] = B ' lower 8 bit of address
DM[105] = &H00 ' upper 8 bit of count
DM[106] = N ' lower 8 bit of count
X = CRC16 (DM[101],6) & &HFFFF ' compute the CRC16 of DM[101] to DM[106]
DM[107] = X / 256 ' upper 8 bit of CRC16
DM[108] = X & &HFF ' lower 8 bit of CRC16
FOR I = 1 to 8 ' send out the MODBUS RTU command in binary
OUTCOMM 3, DM[100+I]
NEXT
delay (10) ' delay for a while to wait for response
DM[111] = 0
TIMERPV[1] = 10 ' if the timer counts down, the loop is exited
WHILE DM[111] <> &H01 ' wait for response and store first byte
DM[111] = INCOMM (3)
IF TIMERPV[1] = 0
SETLCD 4,1, "NO RESPONSE "
RETURN
ENDIF
ENDWHILE
FOR I = 1 to N ' assuming small number of read data
DM[111+I] = INCOMM (3)
IF DM[111+I] < 0 GOTO @5: ENDIF
NEXT
@5 FOR I = 1 to N ' convert two bytes into one 16-bit word.
DM[200+I] = DM[112+I*2]*256+DM[113+I*2]
NEXT
in ladder diagram, on first row, there is a normally open button that can be executed once on starting the system, that activating function first_set
on second row, there is clock that triggering read_autonics every 1 second.
but that doesnt work at all. i checked the system with on-line monitoring and DM[111] just contain -1 in decimal and FFFFFFFF in hex.
any suggestion would be accepted! many thanks and regards
Taufiq Sunar