refactor code and add escape to rs485 data.