ArduinoModbusSlave
ArduinoModbusSlave copied to clipboard
linux modpoll
Hi,
i have following example on a atmega 4808 running and try with my linux usb-ftdi rs485 to read the registers.
include#define SLAVE_ID 33 // The Modbus slave ID, change to the ID you want to use. #define SERIAL_BAUDRATE 9600 // Change to the baudrate you want to use for Modbus communication. #define SERIAL_PORT Serial // Serial port to use for RS485 communication, change to the port you're using. // Comment out the following line if your not using RS485 #define RS485_CTRL_PIN PIN_PF6 // Change to the pin the RE/DE pin of the RS485 controller is connected to. // The position in the array determines the address. Position 0 will correspond to Coil, Discrete input or Input register 0. uint8_t analog_pins[] = {PIN_PD0, PIN_PD1, PIN_PD2}; // Add the pins you want to read as a Input register. uint8_t analog_pins_size = sizeof(analog_pins) / sizeof(analog_pins[0]); // Get the size of the analog_pins array #ifdef RS485_CTRL_PIN // Modbus object declaration Modbus slave(SERIAL_PORT, SLAVE_ID, RS485_CTRL_PIN); #else Modbus slave(SERIAL_PORT, SLAVE_ID); #endif void setup() { // Set the defined analog pins to input mode. for (int i = 0; i analog_pins_size || (address + length) > analog_pins_size) { return STATUS_ILLEGAL_DATA_ADDRESS; } // Read the analog inputs for (int i = 0; i on the linux machine not sure if the Parity is none but tried the other both as well
# mbpoll /dev/ttyUSB0 -m rtu -a 33 -r 1 -c 10 -b 9600 -P none -vv debug enabled debug enabled Set device=/dev/ttyUSB0 mbpoll 1.0-0 - FieldTalk(tm) Modbus(R) Master Simulator Copyright © 2015-2019 Pascal JEAN, https://github.com/epsilonrt/mbpoll This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; type 'mbpoll -w' for details. Opening /dev/ttyUSB0 at 9600 bauds (N, 8, 1) Set response timeout to 1 sec, 0 us Protocol configuration: Modbus RTU Slave configuration...: address = [33] start reference = 1, count = 10 Communication.........: /dev/ttyUSB0, 9600-8N1 t/o 1.00 s, poll rate 1000 ms Data type.............: 16-bit register, output (holding) register table -- Polling slave 33... Ctrl-C to stop) [21][03][00][00][00][0A][C2][AD] Waiting for a confirmation... ERROR Connection timed out: select Read output (holding) register failed: Connection timed out -- Polling slave 33... Ctrl-C to stop) [21][03][00][00][00][0A][C2][AD] Waiting for a confirmation... ERROR Connection timed out: select Read output (holding) register failed: Connection timed out ^C--- /dev/ttyUSB0 poll statistics --- 2 frames transmitted, 0 received, 2 errors, 100.0% frame loss everything was closed.maybe you can help me to understand what settings i need to use on the modpoll
many thanks
@yourSpace24 please add slave.setUnitAddress(SLAVE_ID 33) in setup() as per below, before the slave.begin(..)
setup()
{
slave.cbVector[CB_READ_INPUT_REGISTERS] = readAnalogIn;
// set slave id
slave.setUnitAddress(SLAVE_ID)
// Set the serial port and slave to the given baudrate.
SERIAL_PORT.begin(SERIAL_BAUDRATE);
slave.begin(SERIAL_BAUDRATE);
}