Xmodem protocol.

Source: Internet
Author: User
Tags ack control characters error handling exception handling numeric numeric value file transfer protocol advantage

Abstract: This article describes the use of Xmomdem File Transfer Protocol programming, the design for the flash memory embedded system with the PC on the Super terminal software between the file transfer function, in the PC without the installation of special communications software, the implementation of the program in the board upgrade, The data in the Board customization and so on, to the site commissioning and maintenance to bring convenience. In addition, this paper also describes the communication software programming method based on the state matrix.
Keyword: XMODEM file download FSM status matrix

1 Design purpose and purpose
2 Xmodem Protocol Introduction
3 protocol layering and inter-layer interface
3.1 Protocol Layering
3.2 Interface between the link layer and the physical layer
3.3 Interface between the link layer and the application layer
4 Layered Protocol implementations
OS Platform for 4.1 protocol
4.2 Application Layer Software implementation
4.3 Link layer Software implementation
4.4 Physical Layer Software implementation
5 Software porting
6 Software Debugging methods

Reference documents

Appendix 1:xmodem List of exceptions for protocol communication
Appendix 2:xmodem Status Transfer tables for protocols
Appendix 3: List of source code files
Appendix 4: Full Source code

1 Design purpose and purpose
Embedded System program code is generally stored in flash memory or OTP memory, the latter is actually a one-time programmable eprom, low cost, suitable for large batches of product use, but the program can not be modified after writing, the advantage of using Flash is that the program is ready to replace the board, This feature is very convenient for on-site debugging and software upgrading and modification.
On the printed circuit board Flash programming There are several methods, the original method is to use the programmer, because to remove the chip, very inconvenient, there are some manufacturers of processors through the JTAG interface or serial connection to the PC (such as Philips P89C51RD), Processor internal Flash can be implemented in-board programming, but requires dedicated download programming software (typically provided by the chip manufacturer), unable to program flash outside the processor.
Program download using the XMODEM protocol is a common practice for many products, such as Cisco's router products, ISDN terminal products, which use the Windows-brought HyperTerminal software to transfer files without the need to install proprietary software. Simply add a break to the target board to implement the Xmodem protocol "diagram 1", it is easy to implement the program or data file download. In the following paragraphs, the implementation of the XMODEM protocol program is described.

Figure 1: The target Board program consists of two parts: downloading programs and Applications
2 Xmodem Protocol Introduction
Xmodem protocol "Document 1" is the first 2 computers through RS232 asynchronous serial port for file transmission protocol standard, compared to Ymodem,zmodem and other file Transfer Protocol, XMODEM protocol is simple, suitable for those memory limited occasions.
Xmodem file The sender of the file into a 128-byte fixed-length data block, each sending a block of data, waiting for each other to reply before sending the next data block, the data check using vertical accumulation and calibration, you can also use 16-bit CRC check. belongs to the simple Arq (automatic request retransmission) protocol, so it is also suitable for use in a 2-wire half-duplex RS485 network.

2.1 Terminology
Before specifically describing the specifics of the Xmodem agreement, we first give the term "Diagram 2", which is used in the protocol.
Term numeric meaning remarks
Decimal hexadecimal
SOH 1 01H Data block start
EOT 4 04H Send End
ACK 6 06H Acknowledgement response
NAK 15H does not recognize the response for CRC verification protocol software, this signal is replaced by the letter "C" (43H).
DLE 10H Abort data connection
x-on 11H Data transfer start when the speed of the two sides of the communication is inconsistent, the character can be used to adjust the communication speed, such as the receiver is too slow to cause the receiving buffer full, send "X-off" to the sender, so that the sender suspends the sending of data. The equivalent of a dsr,cts signal such as a RS232 interface.
X-off 13H Data Transfer stop
SYN 16H Sync
CAN 18H Undo Transfer
Chart 2:xmodem control character of the Protocol
Each abbreviation in the table above is also a character of the standard ASCII code, which needs to be used to express the state of the Protocol in the XMODEM protocol. And its basic meaning is as described in the table.

2.2 Data frame format and file decomposition
The XMODEM protocol transmits a data frame length of 132 bytes each, where the file data is 128 bytes, the other 4 bytes are the start flag, the block ordinal, the complement of the block ordinal, and the check byte. Where the start flag, block ordinal, block ordinal of the complement is at the beginning of the data block, check byte at the end of the data block, such as "Diagram 3":

Offset byte number name Description
Name Value (HEX)
0 1 SOH 01 start byte flag
1 1 Seq 1~ffh block Sequence number
2 1 cmpl ffh-seq block serial number complement
3 data? File content Data
131 1 csum? The vertical Add and verify 1:xmodem protocol allows the use of 2 checksum codes. 2: The check code is calculated only from 128 bytes of data, the head 3 bytes do not participate in the checksum operation.
2 CRC? 16-bit cyclic redundancy Check
Chart 3:xmodem protocol Data frame Format
If the file length is not an integer multiple of 128 bytes, the valid content of the last chunk is necessarily less than the frame length, and the remainder needs to be populated with other data, Xmodem recommends using the " Ctrl-z "(=26 (01aH)), in this case, how the receiver distinguishes between the contents of the file and the contents of the fill in that frame.
If the transmitted file is a text file that contains only letters, numbers, and symbols that can be displayed (for example, a C program source code file), then the recipient is distinguishable according to the content itself ("26" is not an ASCII code of letters or numbers), if it is a binary file (such as a program object code) of any numeric value, The receiver is unable to differentiate between the contents of the file and the padding.
Important: The XMODEM protocol does not guarantee that the receiver receives a file length that is exactly the same as the sender, and that the receiver receives a file data length that is always 128 bytes long, which is 1 to 127 bytes larger than the actual length of the file being sent. The extra content is located at the end of the file. This disadvantage of the
Xmodem protocol does not have a real impact on the program code that is used for embedded systems, and the processor does not execute the padding as code, as long as the program memory is sufficient enough to store all the data received. If the XMODEM protocol is used for database loading, the effects of extraneous content should be taken into account, and the database structure parameters such as database size, number of fields and number of records are included in the general standard database file, so the fill content is not treated as the database record itself.
Similarly, for a database of Chinese character libraries, downloading with the XMODEM protocol will not cause problems.

2.3 Check algorithm
The verification code is to send the data to carry out some kind of computation to obtain the code, in order to prevent the data in the transmission way some bit error, the various data communication protocol stipulation sender In addition sends the application data, but also sends the check code, but the data receiver then calculates the check code from the received application data according to the same algorithm, And compared with the sender to send the checksum, such as equal, only to think that the correct data received.
In the XMODEM protocol, vertical accumulation and/or CRC can be used, and the CRC-verified communication software automatically switches from CRC to Totalizer and checksum mode. In this application, we use vertical accumulation and validation.
The accumulate and check code is to accumulate all sent data and in bytes, keep its lowest byte as the check code, for example, 3 bytes of data sent is 255 (FFH), 5 (05h), 6 (06h), then:
1 1 1 1 1 1 1 1 FFH
0 0 0 0 0 1 0 1 05H
0 0 0 0 0 1 1 0 06H

1 0 0 0 0 1 0 1 0--0000 1010
After the high level is discarded, the cumulative and checksum codes are 0AH (10). In the example above, if the original data has changed on the way, such as FFH to feh,06h to 07H, 05H unchanged, then the receiver calculates the check code is:
Receive send
1 1 1 1 1 1 1 0 FEH <-FFH
0 0 0 0 0 1 0 1 05H <-05H
0 0 0 0 0 1 1 1 07H <-06H

1 0 0 0 0 1 0 1 0--0000 1010
The check code is also 0AH. It can be seen that when there are 2 changes in the data, the receiver calculates the check code is still consistent with the sender, this check method cannot detect the error of even bits.
The checksum of the XMODEM protocol only calculates 128 bytes of data in the data frame, and the head 3 bytes do not participate in the checksum operation.

2.4 Xmodem protocol Start-up
The XMODEM protocol begins with the file receiver issuing a "NAK" byte, and the file sender sends a data frame after it receives the signal, and both parties begin the normal communication process. When the file sender enters the Xmoden protocol, waits for the other party to send "NAK", if the wait time exceeds 60 seconds, then exits this communication "figure 4B".
After a "Nak" is issued by the receiver, if the other party has not sent the first data frame after 10 seconds, the "Nak" is sent repeatedly, the number of repetitions is allowed up to 10 times, and the first data block is still not received, exit this communication "figure 4A".

(A): The sender software is delayed for more than 100 seconds, causing the protocol not to start

(B): The receiver software delayed 60 seconds to send a "NAK" signal resulting in a failure to start the protocol

Figure 4 2 scenarios in which the XMODEM protocol cannot be started
In the application of the embedded system to download the software through the PC, the embedded system software is the file receiving party, and the PC Super Terminal software is the file sending party. According to the agreement, the embedded system communication software enters the XMODEM protocol state, the PC software must enter the protocol state within 100 seconds (that is, the Xmodem file transfer function that performs HyperTerminal), whereas the latter enters the protocol state first, the former must enter the protocol state within 60 seconds, obviously, This time lag is somewhat tense by manual operation. The solution only increases the startup wait time for the embedded system to load the software, and this modification does not cause ambiguity in the understanding of the Protocol.

Important note: In order to send and receive parties can more easily start the Xmodem protocol, in the design, will extend the embedded system download software startup delay time, in the following code, the delay time is changed to 600 seconds (10 minutes). or set the wait time to an infinite length, consistently emitting a "NAK" signal until the HyperTerminal software on the PC is running.

Normal transmission process of 2.5 Xmodem
"Figure 5" gives a normal xmodem communication between the sending and receiving parties in the communication process.

Figure 5: Error-Free File transfer process
After each data frame received by the file receiver, such as no checksum error, ordinal error, and so on, send an "ACK" character as the answer, the sender after receiving the reply to start sending the next character, so repeatedly, until the file content is delivered, the sender transmits the "EOT" character means that the transmission is complete, After the sender receives the "ACK" response again, the entire file transfer process is over.

2.6 Termination of the XMODEM protocol
In the process of communication, either side of the two sides if they want to abort this communication, can send the "can" character to each other, now many Xmodem protocol software requires the sending of 2 "can" characters to achieve,
The active abort communication of the Protocol software is usually initiated artificially, for example by pressing the "Cancel" button of the HyperTerminal software. or by dialing the code switch to control the embedded system download software exit communication.

Exception handling of 2.7 Xmodem protocol
In the communication process, there will always be a variety of anomalies, such as the sudden interruption of communication lines, one side of the machine power outage caused by the software to abort the execution, etc. communication software must be able to detect these errors and make reasonable processing. In the previous protocol start section has already covered the problem of error detection, Xmodem the error provisions are very detailed, a total of 8 cases, the agreement text does not explain how to cause, "Appendix 1" gives the possible reasons,
In the embedded system, the implementation code will be reduced, considering that the download software is usually operated by someone, or error handling is not considered. In this article, considering the integrity of the Protocol, the processing of various errors is considered.

2.8 CRC check and accumulate and check mode switching the
Xmodem protocol requires that the communication software that supports CRC verification can also support accumulation and checksum, so that it can communicate with software that only supports additive and checksum, and if the file receiver supports only additive and the sender can support CRC , the receiver sends the start signal as "NAK", and the sender automatically sends the data frame by adding and sending it after receiving it; if the receiver supports the CRC, and the sender supports the summation and the receiver first emits the letter "C" as the start signal, the receiver should ignore the signal and the sender will continue to send the signal "C" after 3 seconds. , a total of three times after the response has not been received, instead send a "NAK" signal, indicating the use of accumulation and means of communication.
If both sides of the communication use CRC verification, the above communication handshake signal "NAK" with the letter "C" instead, the other process ibid.
because the PC Super Terminal software supports CRC mode, the embedded system as the file receiver, as long as the sending "NAK" signal can make the other party automatically in accordance with the checksum mode of communication.

3 protocol layering and layer indirection
3.1 protocol Hierarchy
We divide the protocol code into 3 tiers: the physical layer, the link layer, and the protocol application layer. The physical layer is used to control the UART device, the link layer processes the Xmodem protocol, and the application layer is responsible for combining the received single 128-byte data block into a complete block of data and writing to the program memory buffer. This layering, as long as the program is ported to modify and hardware-related physical layer, application layer code, do not need to modify the implementation of the XMODEM Protocol link layer code. The
layer communicates with the layer through the message, the XMODEM protocol does not stipulate the hierarchical structure and the inter-layer message format, here unifies the link layer and the application layer between the link layer and the physical layer the message format unification stipulation as follows:
typedef struct {
int len;/* Message content length, which is the content bytes in message */
char mtype;/* Inter-tier message type, */
Char message[max_ Message_len];/* message content, filled in by the sending process */
} Mess Ageoflayer;
Considering that the Xmodem data frame is 132 bytes, the definition of the constant "Max_message_len" is 132 bytes, according to the OSI Standard, the inter-layer message primitive has data request, data indication, response, confirmed 4 types of "Literature 5". "Figure 7" gives a-party send data, B-party receive data when the inter-layer message type Figure 6: One-way data transfer between the inter-layer message order: ①②③④
Message is the data frame that hosts the actual data, the message 3,4 is the transmission process of the reply frame, indicating that the data has been correctly transmitted, it must be explained that In the sending data of the confirmation message 3 is not issued from the other side, the physical layer after sending out the data, immediately up a layer to send a confirmation message.
in real-world applications, it is necessary to define some control management messages in the context of the messages required for normal data transfer, and specify the types and roles of inter-tier messages.

3.2 Interface between the link layer and the physical layer
N Data Request: This message is used to send xmodem frame data to the physical layer, including 132 bytes of file data frame and Nak,ack,can single-byte signal frame, etc., download software just receive files, do not need to send 132 bytes of file data frame.
N Data confirm: The physical layer receives the link layer data request frame, sends to the UART buffer, waits for the send buffer to be empty, indicates that the byte data sends completes, sends the confirmation message to the link layer, after the link layer receives this message, can send the next byte, actually the physical layer transmission is a no connection, Verify that the message is not generated by the receiver, and that it does not indicate that the other party has received the data correctly, but only that it has sent the data. The physical layer protocol generally does not provide a transmission mechanism with a response.
N Data indication: The physical layer sends data to the link layer after the receive buffer is full.
In addition to the above 3 messages, there are 2 messages between the physical layer and the application layer:
N Start-up circuit: from the link layer to the physical layer, the physical layer after receiving the protocol will initialize the serial port.
N Circuit error: emitted by the physical layer to the link layer to report the physical layer errors during data transfer.
The "Data response" message is not used in this app.

3.3 Interface between the link layer and the application layer
There are two data transfer messages between the link layer and the application tier:
N Data block indicates that a XMODEM protocol frame (128 bytes) is received by the link layer and sent to the application layer after the application layer receives the data frame and writes to Flash memory (the PC version is written to the file).
N Block Response: The application layer receives a XMODEM data frame and writes a response signal to the link layer after the Flash memory (the PC version is written to the file). When the link layer receives a response, an "ACK" signal is sent to the file sender.
There are 3 other administrative control messages defined:
N protocol start: The application layer notifies the link layer to start the Xmodem protocol.
N Communication end: The link layer is sent to the application layer after receiving the EOT signal from the other, and after the application layer receives this message, it can be transferred to the application portal to execute the application.
N Communication abort: The link layer transmits the message to the application layer because of various conditions that cannot continue the Xmodem transmission, and after the application layer receives this message, it discards the received data and sends out a communication error indication.

4 Layered Protocol implementations
OS Platform for 4.1 protocol
In order to implement the layered protocol, using the non-preemptive operating system in document 4 as the software platform, each layer as a process.

4.2 Application Layer Software implementation
Embedded system download software only receive code files, for the protocol as a file sender of the processing code can not be written, the application layer of the task is to receive the link layer of the packet, according to the sequence of received packets written to the program memory, in the computer simulation implementation, we put the data in a buffer, the completion of writing to the file , use the WinDiff software and send a file for comparison to determine if the code is correct.
The role of the application layer's process initialization code is:
n Erase the Flash memory used by the program memory (in this case press 29f010 to write code).
N starts a 10-second timer and notifies the link layer to start the Xmodem protocol after 10 seconds.

Basic knowledge of the serial port 2006-8-28 11:24:40

Author: Oriental blog song June Gang song June Gang's personal home "big small"

Serial Port PIN diagram

The basic concept of serial communication:
1, what is the serial port.
2, what is RS-232.
3, what is RS-422.
4, what is RS-485.
5, what is a handshake.

1, what is the serial port
The serial port is the protocol for a very general device communication on a computer (not to be confused with the Universal Serial Bus Universal Serial bus or USB). Most computers contain two RS232-based serial ports. Serial port is also a common communication protocol for instrumentation equipment, and many GPIB-compatible devices also come with RS-232 ports. At the same time, serial communication protocol can be used to obtain data of remote acquisition device.

The concept of serial communication is very simple, the serial port bitwise (BIT) Send and receive bytes. Although it is slower than parallel communication by Byte (byte), the serial port can receive data with another line while sending data using one line. It is simple and enables long-distance communication. For example, when IEEE488 defines the parallel state of passage, the equipment line is usually not more than 20 meters, and the length of any two devices shall not exceed 2 meters, but for the serial port, the length can reach 1200 meters.

Typically, the serial port is used for the transmission of ASCII code characters. Communication is done using 3 wires: (1) ground, (2) sent, (3) received. Because the serial communication is asynchronous, the port can send data on one line and receive data on the other line at the same time. Other lines are used to shake hands, but are not required. The most important parameters of serial communication are baud rate, data bit, stop bit, and parity check. For two ports to pass, these parameters must match:

A, baud rate: This is a parameter that measures the speed of communication. It represents the number of bits transmitted per second. For example, 300 baud indicates that 300 bits are sent per second. When we refer to the clock cycle, we refer to the baud rate, for example, if the protocol requires a 4800 baud rate, then the clock is 4800Hz. This means that the sampling rate of the serial communication on the data line is 4800Hz. Usually the baud rate of the telephone line is 14400,28800 and 36600. The baud rate can be much larger than these values, but the baud rate is inversely proportional to the distance. The high baud rate is often used to place very close inter-instrument communication, the typical example being the communication of a GPIB device.

b, Data bits: This is the parameter that measures the actual data bits in the communication. When the computer sends a packet, the actual data is not 8-bit, and the standard values are 5, 7, and 8 bits. How to set up depends on the information you want to send. For example, the standard ASCII code is 0~127 (7-bit). The extended ASCII code is 0~255 (8-bit). If the data uses simple text (the standard ASCII code), then each packet uses 7 bits of data. Each package refers to a byte, which includes the start/stop bits, data bits, and parity bits. Since the actual data bit depends on the selection of the communication protocol, the term "package" refers to any communication situation.

C, stop bit: Used to represent the last one in a single package. Typical values are 1, 1.5, and 2 bits. Since the data is timed on the transmission line, and each device has its own clock, it is likely that there is a small difference between the two devices in the communication. So the stop bit is more than just the end of the transmission, and provides the opportunity for the computer to calibrate the clock synchronization. The more bits that apply to the stop bit, the greater the tolerance for different clock synchronizations, but the slower the data transfer rate.

D, parity bit: A simple method of error detection in serial communication. There are four methods of error detection: Occasional, odd, high and low. Of course, no check bit is also possible. For even and odd checks, the serial port sets the check bit (one after the data bit), using a value to ensure that the transmitted data has an even or odd logical high. For example, if the data is 011, for parity, the check bit is 0, and the number of bits that are logically high is an even number. If it is a parity check, the parity bit is 1, so there are 3 logical highs. High and low levels do not really check the data, simple set logic or low logic. This allows the receiving device to know the state of a bit, the opportunity to determine whether there is noise interfering with the communication or whether the transmission and reception of the data is not synchronized.

2, what is RS-232.
The RS-232 (ansi/eia-232 standard) is the serial connection standard on IBM-PC and its compatible machines. Can be used for many purposes, such as connecting the mouse, printer or modem, but also can be connected to industrial instruments and meters. For the improvement of drive and wiring, the transmission length or speed of RS-232 in practical applications often exceeds the standard value. RS-232 is limited to the PC serial port and the point-to-point communication between devices. RS-232 serial communication maximum distance is 50 feet.

/1 2 3 4 5/
/6 7 8 9/
The cross-section of a line that is connected from the computer.
RS-232 pin Function:

TXD (PIN 3): Serial data output
RXD (pin 2): Serial data input

Shake hands:
RTS (pin 7): Send data request
CTS (pin 8): Clear Send
DSR (PIN 6): Data Send ready
DCD (pin 1): Data carrier detection
DTR (pin 4): Data Terminal ready

GND (pin 5): Ground

RI (pin 9): Ringtone indication

3, what is RS-422.
The RS-422 (EIA rs-422-a Standard) is the serial connection standards for Apple's Macintosh computers. The RS-422 uses a differential signal to RS-232 the signal using a non-balanced reference. Differential transmission uses two wires to send and receive signals, compared to RS-232, which can better resist noise and have a longer transmission distance. Better noise resistance and further transmission distances in industrial environments are a big advantage.

4, what is RS-485.
The RS-485 (EIA-485 standard) is a RS-422 improvement because it increases the number of devices, from 10 to 32, and defines the electrical characteristics of the maximum number of devices to ensure sufficient signal voltages. With the ability to have multiple devices, you can use a single RS-422 port to establish a network of devices. Excellent noise and multi-device capability, serial connections Choose RS-485 when establishing a distributed device network for PC-connected, other data collection controllers, HMI or other operations in industrial applications. RS-485 is a superset of RS-422, so all RS-422 devices can be RS-485 controlled. The RS-485 can be used in serial traffic over a 4000-foot line.

DB-9 PIN Connection

/1 2 3 4 5/
/6 7 8 9/

The cross-section of a line that is connected from the computer.

Pin function of RS-485 and RS-422
Data: txd+ (pin 8), txd-(pin 9), rxd+ (pin 4), rxd-(pin 5)
Handshake: rts+ (pin 3), rts-(pin 7), cts+ (pin 2), cts-(pin 6)
Ground: GND (pin 1)

5, what is a handshake.
The RS-232 Pass mode allows simple connection of three lines: Tx, RX, and ground. However, for data transmission, both parties must use the same baud rate for the timing of the information. Although this approach is sufficient for most applications, this use is limited in cases where the receiver is overloaded. This requires the handshake function of the serial port. In this section, we discuss three of the most commonly used RS-232 handshake forms: software handshake, hardware handshake, and Xmodem.

A, software handshake: the first handshake we discussed is the software handshake. This is usually used in situations where the actual data is a control character, similar to how GPIB uses a command string. The required line is still three root: Tx,rx and ground, since the control character is not distinguished on the transmission line and the normal character, the function Setxmodem allows the user to enable or disallow the user to use two control characters Xon and Oxff. These characters are sent by the receiver in the communication, causing the sender to pause.
For example, suppose the sender sends data at high baud rate. In transit, the receiver discovers that the input buffer is full because the CPU is busy with other work. In order to temporarily stop the transmission, the receiver sends Xoff, the typical value is decimal 19, or hexadecimal 13, until the input buffer is empty. Once the receiver is ready to receive, it sends Xon, the typical value is decimal 17, which is hexadecimal 11, which continues to communicate. When the input buffer is half full, Labwindows sends the XOFF. In addition, if the Xoff transmission is interrupted, Labwindows will send Xoff when the buffer reaches 75% and 90%. Obviously, the sender must follow this code to ensure that the transmission continues.

b, hardware handshake: The second is the use of a hardware line handshake. Like TX and RX lines, rts/cts and DTR/DSR work together, one as the output and the other as input. The first set of lines is the RTS (Request to send) and the CTS (Clear to send). When the receiver is ready to receive the data, it sends a high RTS line indicating that it is ready, and if the sender is also ready, it is high CTS, indicating that it is about to send data. Another set of lines is DTR (data Terminal Ready) and DSR (data Set Ready). These are now mainly used for modem communication. Make the serial port and modem communicate their state. For example: When the modem is ready to receive data from the PC, it sets the high DTR line, which indicates that the connection to the telephone line has been established. Read the DSR line height and the PC starts sending data. A simple rule is that DTR/DSR is used to indicate system communication readiness, while rts/cts is used for the transmission of a single packet.

In Labwindows, the function Setctsmode enables or disables the use of a hardware handshake. If the CTS mode is enabled, Labwindows uses the following rules:
When the PC sends the data:
The RS-232 library must detect the CTS line height before it can send data.

When the PC receives data:
If the port is open and the input queue has empty receive data, the library function is set to high RTS and DTR.
If the input queue is 90% full, the library function puts the RTS low, but the DTR maintains the high level.
If the port queue is nearly empty, cry the number high RTS, but keep the DRT high.
If the port is closed, the library function is low RTS and DTR.

C,xmodem handshake: The last handshake discussed is called the Xmodem file Transfer protocol. This protocol is very common in modem communication. Although it is commonly used in modem communication, the XMODEM protocol can be used directly in other device communications that follow this protocol. In Labwindows, the actual Xmodem application is hidden from the user. As long as the PC and other devices use the Xmodem protocol, the Labwindows Xmodem function is used in the file transfer. Functions are Xmodemconfig,xmodemsend and xmodemreceive.

Xmodem uses protocols in the following parameters: Start_of_data, End_of_data, Neg_ack, Wait_delay, Start_delay, Max_tries, packet_size. These parameters require communication between the parties to determine that the standard Xmodem has a standard definition: However, the Xmodemconfig function can be modified to meet the specific needs. The way these parameters are used is determined by the character Neg_ack sent by the receiver. This notifies the sender that it is ready to receive data. It starts to attempt to send, has a timeout parameter start_delay, when the timeout attempt exceeds the max_ties number of times, or receives start_of_data sent by the receiver, the sender stops trying. If Start_of_data is received from the sender, the receiver reads the successor packet. The package contains the number of packages, the complement of the number of packages as the error check, the packet_size byte size of the actual packet, and further error checking the summation checksum value. After the data is read, the receiver calls Wait_delay and then sends a response to the sender. If the sender does not receive a response, it will resend the packet until it receives a response or exceeds the maximum number of max_tries. If the response has not been received, the sender notifies the user that the data transfer failed. Since the data must be sent in Pack_size bytes, when the last packet is sent, if the data is not enough to fill a packet, the ASCII code null (0) bytes will be populated later. This results in more data being received than the original data. Do not use Xon/xoff in xmodem cases, because the number of packets emitted by the Xmodem sender is likely to increase to the value of the Xon/off control character, resulting in a communication failure.


XMODEM protocol XMODEM Protocol
XMODEM Protocol is an asynchronous file transport protocol widely used in personal computer communications using a dial-up modem. This protocol transmits data in 128-byte chunks, and each block uses a checksum procedure for error detection. If the receiver's checksum about a block is the same as it does in the sender's checksum, the receiver sends an acknowledgement byte to the sender. However, this strategy of endorsing each block will lead to low performance, especially when there is a long propagation delay in the case of a satellite connection, the problem is even worse.
A protocol that uses cyclic redundancy checks for Xmodem is called XMODEM-CRC. Another is xmodem-1k, which transmits data in a 1024-byte piece. Zmodem is the most effective version of Xmodem, and it does not need to be recognized for each block. In fact, it simply requires that the damaged block be re-sent. Zmodem is very useful for packet-switched networks that are charged by block. There is no need to endorse loopback groupings to a large extent reducing the amount of traffic. The
Ymodem is also a xmodem implementation. It includes all the features of the xmodem-1k, plus the batch file transfer mode is added for sending a set of files during a single session.
Related entries: asynchronous communication asynchronous communication; communication communication; Modems modem.  


  XMODEM protocol consists mainly of a few things  
  1> basic  
  <SOH>   1   byte   <b lockno>   1   byte   <~BlockNo>   1   byte   <Data>     bytes & nbsp <Checksum>   1   byte  
    SOH   header Mark  
    BLOCKNO   Block No. ,   1-255  
    <~BlockNo>   block numbers are  
    data   length,   128byte, less ctrl_z top up  
    checksum:   arithmetic and  
    Hankshake sent by the receiving end,   transmit side The packet is answered and the receiving side responds to the received data (according to Chksum), either party can terminate the process  
  2>   Other types  
  XModem   CRC &nbs P Check and adopt CRC16,   handshake signal is not the same  
  XModem   1k       CRC16,   data length up to 1024byte, &NB Sp  
  XModem   1kg 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.