#serial_network_programming
#serial_protocol
#serial_port_interface
In a typical network, each node has an assigned address and each message contains
the address of the recipient. On receiving a message, a node must detect
the address to determine whether to process or ignore the message.
A node address is a value unique to the node and can be any number of bits.
Some networks use addresses that correspond to ASCII codes.
If there are fewer than 128 nodes, you don't need 8 bits to specify the node and
can get the most use out of a transmitted byte by assigning extra bits to other
uses. For example, in a 16-node network, bits 0–3 can specify the node number,
with bits 4–7 holding a command or other information.
$
One challenge in sending addresses is that the nodes have to distinguish
between addresses and other information. For example, imagine a network
where each transmitted message begins with a byte containing the address of
the recipient. On recognizing its address, a node knows that the bytes that follow
are intended for it.
If Node 05h receives the byte 03h followed by 05h, how does Node 05h know
whether the second byte is part of a message meant for another node or an
address that begins a new message?
There are several ways to distinguish between addresses and other data:
• The addresses can use a reserved set of values that messages never use.
• The network can define a message format that specifies where the address is stored in messages.
• Communications can dedicate one data bit to indicate whether the other
data bits contain an address or data.
8
:
Reserving a set of values for use only as addresses makes it easy to distinguish addresses from data with the limitation that messages can't uses the reserved values for other purposes. If the messages contain text characters (which can include characters for numerals),
network addresses can use any values that don't represent characters. For
example, if the messages use only US ASCII (codes 0–127), addresses can use the values 128–255.
If the messages contain binary data, one solution is to send the data in ASCII Hex format as described in Chapter 2. Because ASCII Hex can represent any binary value using just 16 codes, plenty of codes remain for use as addresses.
$3
Many network protocols define a message format with the address and other information in assigned locations in the message.
For example, an 8-byte message might consist of an address byte followed by seven message bytes. On receiving a byte, a node examines the value to see if it matches the node's address. If it's a match, the node reads and acts on the seven bytes that follow, then waits for another address byte to examine. If the address doesn't match, the node counts but otherwise ignores the seven bytes that follow.
With this method, every node has to detect every byte sent, if only to know
when the message is finished. A node that misses a byte for any reason won't detect the correct address bytes in future messages.
!
To make it easier to detect addresses, a protocol can define values that indicate Start of Transmission and End of Transmission. A node that gets lost can then recover on the next Start of Transmission code. Conventional values are 02h (Control+B) for Start of Transmission and 03h (Control+C) for End of Transmission. Some networks use other characters such as ":" or "$". These values are then unavailable for other uses, so using dedicated codes is useful mainly for communications that send data as plain text.
A message format can also define a field that indicates the length of the data that follows, and receiving nodes can use this value to determine when a message ends.
0
A header is information that uses a defined format and appears at the beginning of a message or other block of data. The header typically consists of a series of
fields, with each field having a defined size and location. The information
included in a header can vary. A header might include some or all of these
items:
• Start-of-communication code.
• Address of the receiving node.
• Address of the sending node.
• Length of the data that follows the header.
• Checksum or other value used for error detection.
• Description of the type of data that follows.
• Time and date information.
)"4
Another option for distinguishing between addresses and data uses a 9-bit format.
Bit 8 (the ninth bit) indicates whether bits 0–7 contain data (0) or an
address (1). Not all UARTs support the 9-bit format. The longer words in 9-bit data mean that communications are slightly more sensitive to mismatches in the rates at the transmitting and receiving ports. Messages that consist of only
US ASCII text can use seven data bits for a text character and the eighth bit to indicate address or data.
you can find part 1 of network programming lecture in link below:
• serial network programming #serial #serial...