I'm trying to control a device via MODBUS RTU and the ModbusRtuMasterV2_PcCOM in Twincat 3. I've configured a device with the right com port and KL6xx1 mode emulation. However I can't get the device to react to a registers write. While the command: 01 10 00 F6 00 02 04 01 01 ff 6c bd works within a MODBUS master program. I'm using the following code withing Twincat to try to send the same command. Does anyone have suggestions on how to get this working? Is it something I need to configure or is it something wrong in the code below?
Code:
PROGRAM MAIN
VAR
MotorMaster: ModbusRtuMasterV2_PcCOM;
Mb_ID: BYTE := 1;
MbRead_Quanti: WORD;
MbRead_Addr: WORD;
Data_Read: ARRAY[1..10] OF INT;
Enable_Read: BOOL;
Data_Write: ARRAY[0..3] OF BYTE := [16#01, 16#01, 16#FF, 16#FF];
Enable_Write: BOOL;
MbError: BOOL;
MbErrorID: Tc2_ModbusRTU.MODBUS_ERRORS;
MbWrite_Quanti: WORD := 2;
MbWrite_Addr: BYTE := 246;
END_VAR
Code:
MotorMaster.WriteRegs(
UnitID:= Mb_ID,
Quantity:= MbWrite_Quanti,
MBAddr:= MbWrite_Addr,
cbLength:= SIZEOF(Data_Write),
pMemoryAddr:= ADR(Data_Write),
Execute:=Enable_Write,
Timeout:= T#1S,
Error=> MbError,
ErrorId=> MbErrorID,
cbRead=>
);