ICS TRIPLEX T8831工業(yè)自動化卡件
CRC-16算法本質(zhì)上將整個數(shù)據(jù)流(僅數(shù)據(jù)位;忽略開始、停止和奇偶校驗)視為一個連續(xù)的二進制數(shù)。該數(shù)字首先左移16位,然后除以特征多項式(11000000000101B)。除法的16位剩余部分被附加到傳輸?shù)哪┪?,首先是LSByte。如果沒有發(fā)生傳輸錯誤,則當(dāng)在接收機處用相同的多項式除時,包括CRC的結(jié)果消息將給出零余數(shù)。如果469 Modbus從設(shè)備接收到CRC-16計算指示錯誤的傳輸,則從設(shè)備不會對傳輸做出響應(yīng)。CRC-16錯誤表示錯誤接收了傳輸?shù)囊粋€或多個字節(jié),因此應(yīng)忽略整個傳輸,以避免469執(zhí)行任何錯誤操作。CRC-16計算是用于錯誤檢測的行業(yè)標(biāo)準方法。在沒有標(biāo)準CRC-16計算例程可用的情況下,這里包括一種算法來幫助程序員。主查詢消息:從屬地址:(1字節(jié))功能代碼:(1個字節(jié))數(shù)據(jù):(取決于功能代碼的可變字節(jié)數(shù))CRC:(2個字節(jié))從屬響應(yīng)消息:從屬位置:(1位字節(jié))功能碼:(1)字節(jié)數(shù)據(jù):(根據(jù)功能代碼的變化字節(jié)數(shù))CRC:(2字節(jié))GE Power Management 469 Motor Management Relay 6-3 6 COMMUNICATIONS 6.1 MODBUS COMMUNICATION 6 6.1.5CRC-16算法一旦完成以下算法,工作寄存器“A”將包含要傳輸?shù)腃RC值。注意,該算法要求特征多項式是反向位序的。特征多項式的MSbit被丟棄,因為它不影響余數(shù)的值。符號:-->數(shù)據(jù)傳輸A個16位工作寄存器,A個CRC 16位CRC-16結(jié)果i的A個高階字節(jié)的低階字節(jié),j個循環(huán)計數(shù)器(+)邏輯異或運算符N數(shù)據(jù)字節(jié)總數(shù)Di第i個數(shù)據(jù)字節(jié)(i=0到N-1)G 16位特征多項式=1010000000000001(二進制),MSbit被丟棄,位序反轉(zhuǎn)shr(x)右移運算符(x的LSbit被移位為進位標(biāo)志,“0”被移位為x的MSbit,所有其他位被右移一個位置)算法:1。FFFF(十六進制)-->A 2。0-->i 3。0-->j 4。Di(+)Alow-->Alow 5。j+1-->j6。shr(A)7。有行李嗎?否:轉(zhuǎn)至步驟8。是:G(+)A-->A并繼續(xù)。8.j=8嗎?否:轉(zhuǎn)到5。是:繼續(xù)。9.i+1-->i10。i=N?否:轉(zhuǎn)到3。是:繼續(xù)。11.-->CRC 6.1.6定時數(shù)據(jù)包同步由定時約束保持。接收設(shè)備必須測量接收字符之間的時間。如果經(jīng)過三個半字符的時間,沒有新的字符或數(shù)據(jù)包沒有完成,則必須重置通信鏈路(即所有從設(shè)備開始偵聽來自主設(shè)備的新傳輸)。因此,在9600波特時,大于3.5×1/9600×10=3.65 ms的延遲將導(dǎo)致通信鏈路復(fù)位.
The CRC-16 algorithm essentially treats the entire data stream (data bits only; start, stop and parity ignored) as one continuous binary number. This number is first shifted left 16 bits and then divided by a characteristic polynomial (11000000000000101B). The 16-bit remainder of the division is appended to the end of the transmission, LSByte first. The resulting message including CRC, when divided by the same polynomial at the receiver will give a zero remainder if no transmission errors have occurred. If an 469 Modbus slave device receives a transmission in which an error is indicated by the CRC-16 calculation, the slave device will not respond to the transmission. A CRC-16 error indicates than one or more bytes of the transmission were received incorrectly and thus the entire transmission should be ignored in order to avoid the 469 performing any incorrect operation. The CRC-16 calculation is an industry standard method used for error detection. An algorithm is included here to assist programmers in situations where no standard CRC-16 calculation routines are available. MASTER QUERY MESSAGE: SLAVE ADDRESS: (1 byte) FUNCTION CODE: (1 byte) DATA: (variable number of bytes depending on FUNCTION CODE) CRC: (2 bytes) SLAVE RESPONSE MESSAGE: SLAVE ADDRESS: (1 byte) FUNCTION CODE: (1 byte) DATA: (variable number of bytes depending on FUNCTION CODE) CRC: (2 bytes) GE Power Management 469 Motor Management Relay 6-3 6 COMMUNICATIONS 6.1 MODBUS COMMUNICATIONS 6 6.1.5 CRC-16 ALGORITHM Once the following algorithm is complete, the working register "A" will contain the CRC value to be transmitted. Note that this algorithm requires the characteristic polynomial to be reverse bit ordered. The MSbit of the characteristic polynomial is dropped since it does not affect the value of the remainder. Symbols: --> data transfer A 16 bit working register Alow low order byte of A Ahigh high order byte of A CRC 16 bit CRC-16 result i, j loop counters (+) logical EXCLUSIVE-OR operator N total number of data bytes Di i-th data byte (i = 0 to N-1) G 16 bit characteristic polynomial = 1010000000000001 (binary) with MSbit dropped and bit order reversed shr (x) right shift operator (the LSbit of x is shifted into a carry flag, a '0' is shifted into the MSbit of x, all other bits are shifted right one location) Algorithm: 1. FFFF (hex) --> A 2. 0 --> i 3. 0 --> j 4. Di (+) Alow --> Alow 5. j + 1 --> j 6. shr (A) 7. Is there a carry? No: go to step 8. Yes: G (+) A --> A and continue. 8. Is j = 8? No: go to 5. Yes: continue. 9. i + 1 --> i 10. Is i = N? No: go to 3. Yes: continue. 11. A --> CRC 6.1.6 TIMING Data packet synchronization is maintained by timing constraints. The receiving device must measure the time between the reception of characters. If three and one half character times elapse without a new character or completion of the packet, then the communication link must be reset (i.e. all slaves start listening for a new transmission from the master). Thus at 9600 baud a delay of greater than 3.5 × 1 / 9600 × 10 = 3.65 ms will cause the communication link to be reset