 
   Hardware:
   - Arduino MKR Zero
-  - Arduino MKR 485 shield (with 3 dip switch to off) 
-      -> RS signal to spy connect to Y and Z
+  - Arduino MKR 485 shield (dip switch set as : A/B resisotor to off, half/full to on and Y/Z resistor off)
+     -> RS signal to spy connect to A(+) and B(-)
 */
 
 #include <stdarg.h>

      // console stats
      serial_printf("stats: frame count %06d | error CRC %06d | exception %06d | too short %06d\r\n", rs_stat_frame_count, rs_stat_err_crc, rs_stat_err_exp, rs_stat_err_short);
    }
    else if (s_cmd.equals("baudrate") or s_cmd.equals("rate")) {
      uint32_t set_baudrate = s_arg.toInt();
      if (set_baudrate > 0) {
        rs_baudrate = set_baudrate;
        rs_eof_us = max(round((10.0 / rs_baudrate) * 3.5 * 1e6), 1);
        rs485_setup();
      }
      Serial.println("RS485: baudrate set to " + String(rs_baudrate) + " bauds, end of frame set to " + String(rs_eof_us) + " us");
    }
    else if (s_cmd.equals("eof")) {
      uint32_t set_eof = s_arg.toInt();
      if (set_eof > 0) {
        rs_eof_us = max(set_eof, 1);
        rs485_setup();
      }
      Serial.println("RS485: end of frame set to " + String(rs_eof_us) + " us");
    }
    // reset for next one
    cmd_rx_buf = "";

      s_arg.toLowerCase();
    }
    // check command
    if (s_cmd.equals("?") or s_cmd.equals("help")) {
      Serial.println("-------------------------------------------------------------------------------");
      Serial.println("dump           turn on dump mode (= display modbus frame as hexadecimal values)");
      Serial.println("end            turn off dump mode");
      Serial.println("stat           view current RS485 modbus stat (nb of frames, CRC errors....)");
      Serial.println("clear          clear current RS485 modbus stat");
      Serial.println("echo on        turn on command echo");
      Serial.println("echo off       turn off command echo");
      Serial.println("echo           display current status");
      Serial.println("auto           view autodetected serial baudrate");
      Serial.println("serial         view current RS485 params");
      Serial.println("rate 9600      set RS485 baudrate to 9600 bauds (auto update EOF)");
      Serial.println("parity even    set RS485 parity to even (other choice are none or odd)");
      Serial.println("eof 3500       set modbus EOF (end of frame) to 3500 us (= 3.5 ms)");
      Serial.println("-------------------------------------------------------------------------------");
    }
    else if (s_cmd.equals("echo")) {
      if (s_arg.equals("on")) {
