I am attempting to control a device using MODBUS RTU and the ModbusRtuMasterV2_PcCOM in Twincat 3. I have properly configured the device with the correct com port and KL6xx1 mode emulation. However, I am encountering difficulties in getting the device to respond to register writes. Although the command 01 10 00 F6 00 02 04 01 01 ff 6c bd functions as expected within a MODBUS master program, I am facing challenges when trying to send the same command using the provided code in Twincat. I am seeking suggestions on how to resolve this issue. Are there specific configurations that need to be adjusted or is there an error in the code provided below? Code snippet: 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 snippet: 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=> );
Is theExecuteparameter being provided with a rising edge as required?
In a discussion with drbitboy, the importance of providing a rising edge to theExecuteparameter was emphasized. Have you ensured this requirement is met? It is worth noting that toggling Enable_Write now results in a MODBUSERROR_CRC. Interestingly, there seems to be no communication activity detected when observing with a scope or checking the indicator lights on the USB to RS485 converter. All settings such as COM port, Baudrate, stopbits, parity, and databits are confirmed to be correctly configured. The InData, OutData, SerStatus, and SetCrtl are linked, and the COM port appears to be occupied as access from other software is restricted while TwinCat is active.
Is it possible to establish a connection between the COM port utilized by the ModbusRtuMasterV2_PcCOM block for data transmission and another PC's COM port in order to monitor the data being transmitted? If the other PC is set up to operate as a Modbus Slave, you should be able to observe the incoming data flow.
drbitboy inquired about the possibility of connecting the COM port where the ModbusRtuMasterV2_PcCOM block is sending data to another PC's COM port to monitor the transmitted data. By running a Modbus Slave on the other PC, you should be able to observe the incoming data flow. Despite attempting the suggestions with an additional USB converter, the data transmission remains undetectable. Experimenting with the COM devices as master connected to Twincat did not yield any results either. However, configuring one as master and the other as slave using a different program successfully showed data transmission to the motor.
Kroket mentioned that although trying different USB converters and configurations, there was no data transmission detected when using Modbus RTU. It seems that the motor is the slave in this one-master, one-or-more-slaves network. By using a PC program as a Modbus master and ensuring correct wiring, data can be successfully read from and written to the motor Modbus slave. It's important to note that Modbus masters do not communicate with each other, only with slaves. To troubleshoot further, consider using a PC program as a Modbus slave connected to the Twincat Modbus master to compare request bytes. This comparison can help diagnose any issues and determine the next steps. Additionally, it is essential to confirm whether Modbus RTU is being used over RS-232 or RS-485 for this application. Hopefully, with these steps, successful data transmission can be achieved.
It sounds like you're really close to getting it working, but some common issues with Modbus in TwinCAT could be related to the timing of your `Enable_Write` signal—make sure that it's set to `TRUE` just before your `WriteRegs` call and reset afterwards. Also, double-check that the data format in `Data_Write` matches what the device expects; sometimes an endianness mismatch can cause problems. If everything looks good in your code, it might also be worth testing with a different quantity to see if the device is sensitive to size or format changes. Don't forget to check the device's documentation for any specific requirements as well!
It sounds like you're on the right track with your setup, but have you double-checked the configuration of the Modbus parameters on both the device and Twincat? Make sure that the unit ID, baud rate, stop bits, and parity match between your master and the slave device. Also, ensure that the `Enable_Write` flag is set to TRUE before executing the write command; otherwise, it won't send the data. If everything looks good, it might help to look at the specific Modbus error codes returned in `MbErrorID` for more context on the issue. Sometimes, using a bus monitor tool can also reveal communication problems that aren’t immediately visible in your code. Good luck!
✅ Work Order Management
✅ Asset Tracking
✅ Preventive Maintenance
✅ Inspection Report
We have received your information. We will share Schedule Demo details on your Mail Id.
Answer: Answer: Ensure that the configurations of the device, COM port, and KL6xx1 mode emulation are correctly set up. Check the code for any errors in addressing or data formatting that may be causing the issue.
Answer: Answer: Double-check the code for any errors in parameter values such as UnitID, Quantity, MBAddr, and Timeout. Verify that the data being sent matches the expected format and size for the device you are trying to control.
Answer: Answer: Start by verifying the physical connections and settings of the device, COM port, and Twincat configuration. Check for any error messages or response codes returned by the device. Review the code for any syntax errors or incorrect parameters that may be hindering communication.
Join hundreds of satisfied customers who have transformed their maintenance processes.
Sign up today and start optimizing your workflow.