summaryrefslogtreecommitdiff
path: root/tags/firmware/gen3/1.1/SanguinoMaster/RS485.h
blob: 14c8a778e68366dc7bc66306dc745e4126832aa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
unsigned long rs485_tx_count = 0;
unsigned long rs485_rx_count = 0;
unsigned long rs485_packet_count = 0;
unsigned long rs485_loopback_fails = 0;
unsigned long slave_crc_errors = 0;
unsigned long slave_timeouts = 0;

unsigned long serial_tx_count = 0;
unsigned long serial_rx_count = 0;
unsigned long serial_packet_count = 0;

void rs485_tx(byte b)
{
  rs485_tx_count++;

  Serial1.print(b, BYTE);

  //read for our own byte.
  long now = millis();
  long end = now + 10;
  int tmp = Serial1.read();
  while (tmp != b)
  {
    tmp = Serial1.read();
    if (millis() > end)
    {
      rs485_loopback_fails++;
#ifdef ENABLE_COMMS_DEBUG
      Serial.println("Loopback Fail");
#endif
      break;		
    }
  }
}

void serial_tx(byte b)
{
  serial_tx_count++;

  Serial.print(b, BYTE);
}