An RS-485 Network
if (response.StartsWith(":"))
{
if (response.Substring(1, 1) == node)
{
switch (command)
{
case "1":
Console.WriteLine(
"write_byte command acknowledged.");
break;
case "2":
Console.WriteLine("read_byte response data: " +
response.Substring(2, 2));
break;
}
}
}
}
$ ##
A secondary node reads all incoming bytes looking for the “:” character that
indicates the start of a message. On receiving “:”, the node can check the
address right away or wait to receive a LF code. In the first approach, the node
reads the next received byte to find out if it matches the node’s address. If the
byte matches, the node stores the data that follows the address up to a LF and
then acts on the received command. If the byte doesn’t match the address, the
node ignores any received data up to the next “:”. In the second approach, the
node stores data that follows any “:” up to a LF. After receiving a LF, the node
examines the received address and acts on the received command only if the
address matches. The code that follows uses the second approach.
#5
The example firmware for network communications includes a task loop and
routines that implement delays and convert between ASCII Hex and binary
data.