Classic Ladder and RS 485 Relay Switch - Hortensie/CNC_x_axis_linuxcnc_mesa_5i25_7i76 GitHub Wiki

My setup

Hardware:

  • USB To RS485 Converter Module - Link to store
  • 8 Channel DC 12V RS485 Relay Module Modbus RTU 485 Remote Control Switch - Link to store
  • How to check if usb converter is recognized on debian:

    lsusb

    Sample console output:

    Bus 002 Device 004: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter

    if you just plugged in USB device you can find path by using below command:

    sudo dmesg | awk '/tty/ && /USB/ {print "/dev/"$10}'|tail -1

    Then you can check details if it is conneted to USB0:

    udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB0)

    Lastly in my case i was still facing communication problems and I needed to change permissions to my port:

    sudo chmod 777 /dev/ttyUSB0

    NOTE: AFTER PC reboot above command might be disabled so you might set it permanently.

    Modbus communication setup, just example - works in my case. You might change speed or other params - depends on end device:
    All other parameters are defined in eg custom.clp file, example

    MODBUS_MASTER_SERIAL_PORT=/dev/ttyUSB0

    MODBUS_MASTER_SERIAL_SPEED=115200

    MODBUS_MASTER_SERIAL_DATABITS=8

    MODBUS_MASTER_SERIAL_STOPBITS=1

    MODBUS_MASTER_SERIAL_PARITY=0

    MODBUS_ELEMENT_OFFSET=0

    MODBUS_MASTER_SERIAL_USE_RTS_TO_SEND=0

    Modbus I/O register setup, in below case relay is set with slave id =2
    Sample ladder to test connection to first relay channel (1st Element). After 5 seconds we turn it on (%W0=256). After another 5 seconds we turn it off (%W0=512)
    ⚠️ **GitHub.com Fallback** ⚠️