RS485 communication with a battery-pack

RS485 communication with a battery-pack

There isn't an automatic control of the 2 wire "echo" when using PRINT and GET.  The programmer must read the echo and discard those characters.

Use SETCOM(960081020' no xon/xoff

Don't set the 2-wire flag because that is only for Modbus.

This example will suppress the echoed characters.

' look for Echo of the sent string (12 characters)
WHILE TRUE
  WAIT UNTIL (TICKS <= 0OR (KEY #2)

  IF TICKS > 0 THEN
    GET #2, byte_in
    ' look for the first character $A5
    IF byte_in = $a5 THEN
      ' read in all the sent characters which are echoed on the 2 wire line
      FOR lc = 1 TO 11
        GET #2, byte_in ' read and discard the character
      NEXT lc
      EXIT_LOOP ' exit this while loop and start reading the reply
    ENDIF
  ELSE
    ' timed out with no valid data
    PRINT #5"RS485 error - timeout no echoed characters"
    byte_in = 500
  ENDIF
WEND