ICS TRIPLEX T8831工業(yè)自動(dòng)化卡件
CRC-16算法本質(zhì)上將整個(gè)數(shù)據(jù)流(僅數(shù)據(jù)位;忽略開始、停止和奇偶校驗(yàn))視為一個(gè)連續(xù)的二進(jìn)制數(shù)。該數(shù)字首先左移16位,然后除以特征多項(xiàng)式(11000000000101B)。除法的16位剩余部分被附加到傳輸?shù)哪┪玻紫仁荓SByte。如果沒有發(fā)生傳輸錯(cuò)誤,則當(dāng)在接收機(jī)處用相同的多項(xiàng)式除時(shí),包括CRC的結(jié)果消息將給出零余數(shù)。如果469 Modbus從設(shè)備接收到CRC-16計(jì)算指示錯(cuò)誤的傳輸,則從設(shè)備不會(huì)對(duì)傳輸做出響應(yīng)。CRC-16錯(cuò)誤表示錯(cuò)誤接收了傳輸?shù)囊粋€(gè)或多個(gè)字節(jié),因此應(yīng)忽略整個(gè)傳輸,以避免469執(zhí)行任何錯(cuò)誤操作。CRC-16計(jì)算是用于錯(cuò)誤檢測(cè)的行業(yè)標(biāo)準(zhǔn)方法。在沒有標(biāo)準(zhǔn)CRC-16計(jì)算例程可用的情況下,這里包括一種算法來幫助程序員。主查詢消息:從屬地址:(1字節(jié))功能代碼:(1個(gè)字節(jié))數(shù)據(jù):(取決于功能代碼的可變字節(jié)數(shù))CRC:(2個(gè)字節(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值。注意,該算法要求特征多項(xiàng)式是反向位序的。特征多項(xiàng)式的MSbit被丟棄,因?yàn)樗挥绊懹鄶?shù)的值。符號(hào):-->數(shù)據(jù)傳輸A個(gè)16位工作寄存器,A個(gè)CRC 16位CRC-16結(jié)果i的A個(gè)高階字節(jié)的低階字節(jié),j個(gè)循環(huán)計(jì)數(shù)器(+)邏輯異或運(yùn)算符N數(shù)據(jù)字節(jié)總數(shù)Di第i個(gè)數(shù)據(jù)字節(jié)(i=0到N-1)G 16位特征多項(xiàng)式=1010000000000001(二進(jìn)制),MSbit被丟棄,位序反轉(zhuǎn)shr(x)右移運(yùn)算符(x的LSbit被移位為進(jìn)位標(biāo)志,“0”被移位為x的MSbit,所有其他位被右移一個(gè)位置)算法:1。FFFF(十六進(jìn)制)-->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í)數(shù)據(jù)包同步由定時(shí)約束保持。接收設(shè)備必須測(cè)量接收字符之間的時(shí)間。如果經(jīng)過三個(gè)半字符的時(shí)間,沒有新的字符或數(shù)據(jù)包沒有完成,則必須重置通信鏈路(即所有從設(shè)備開始偵聽來自主設(shè)備的新傳輸)。因此,在9600波特時(shí),大于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