HD系列通訊協(xié)議D-SERIES Protocol-EN_第1頁(yè)
HD系列通訊協(xié)議D-SERIES Protocol-EN_第2頁(yè)
已閱讀5頁(yè),還剩7頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、 COMMUNICATION PROTOCOLINTERFACERS-485, RS-232BAUD RATE2400, 4800, 9600, 19200, 38400 bpsDATA FRAMEData Bits8,ParityNone,Start bit = 1,Stop bit = 10B0 B1 B2 B3 B4 B5 B6 B711 Start bit1 Stop bitDATA FORMATModBus Protocol RTU ModeRTU Request:Read command0 x03Func- AddressCountCRC16Stationtion(MSB LSB)

2、(MSB LSB)(LSB MSB)NumberStation Number: 00H1FHAddress: 0000H0100HCount: Number of DataCRC16: Cyclical Redundancy CheckRTU Response:Read command0 1 2 3 4 5 6 7 80 x03Func- BytetionData1Count (MSB LSB)Data2.(MSB LSB)CRC16Station(LSB MSB)NumberStation Number: 00H1FHAddress: 0000H0100HByte Count: Number

3、 of Data BytesCRC16: Cyclical Redundancy Check1 RTU Request:Write command0 1 2 3 4 5 6 70 x06Func- AddressData(MSB LSB)CRC16Stationtion(MSB LSB)(LSB MSB)NumberStation Number: 00H1FHAddress: 0000H00B6HCRC16: Cyclical Redundancy CheckRTU Response:Write command0 1 2 3 4 5 6 70 x06Func- AddressData(MSB

4、LSB)CRC16Stationtion(MSB LSB)(LSB MSB)NumberStation Number: 00H1FHAddress: 0000H00B6HCRC16: Cyclical Redundancy CheckCOMMUNICATION EXAMPLESRTU Request:Read commandRead PV from station 1Station number: 01HFunction: 03HAddress MSB: 01HAddress LSB: 00HCount MSB: 00HCount LSB: 01HCRC16 LSB: 85HCRC16 MSB

5、: F6H0 1 2 3 4 5 6 70 x01 0 x85 0 xF6Func- AddressCountCRC16Stationtion(MSB LSB)(MSB LSB)(LSB MSB)Number2 RTU Response:Read commandResponse PV 100.0 from D-Series station 1Station number: 01HFunction: 03HByte count: 02HData MSB: 03HData LSB: E8HCRC16 LSB: B8HCRC16 MSB: FAH0 1 2 3 4 5 60 xB8 0 xFAFun

6、c- BytetionData1Count (MSB LSB)CRC16Station(LSB MSB)NumberRTU Request:Write commandWrite SV 100.0 to D-Series station 1Station number: 01HFunction: 06HAddress MSB: 00HAddress LSB: 02HData MSB: 03HData LSB: E8HCRC16 LSB: 28HCRC16 MSB: B4H0 x01 0 x06 0 x00 0 x02 0 x030 xE8 0 x28 0 xB4Func- AddressData

7、(MSB LSB)CRC16Stationtion(MSB LSB)(LSB MSB)Number3 RTU Response:Write commandResponse request command from D-Series station 1Station number: 01HFunction: 06HAddress MSB: 00HAddress LSB: 02HData MSB: 03HData LSB: E8HCRC16 LSB: 28HCRC16 MSB: B4H0 1 2 3 4 5 6 70 x01 0 x06 0 x00 0 x02 0 x030 xE8 0 x28 0

8、 xB4Func- AddressData(MSB LSB)CRC16Stationtion(MSB LSB)(LSB MSB)Number4 ADDRESS INDEXPARA ADDR PARA ADDR PARA ADDR0100H0000H0001H0002H0003H0004H0005H0006H0007H0008H0009H000AH000BH000CH000DH000EH000FH0010H0011H0012H0013H0014H0015H0016H0017H0018H0019H001AH001BH001CH001DH001EH001FH0020H0021H0022H0023H0

9、024H0025H0026H0027H0028H0029H002AH002BH002CH002DH002EH002FH0030H0031H0032H0033H0034H0035H0036H0037H0038H0039H003AH003BH003CH003DH003EHO1HSAO003FH0040H0041H0042H0043H0044H0045H0046H0047H0048H0049H004AH004BH004CH004DH004EH004FH0050H0051H0052H0053H0054H0055H0056H0057H0059H005AH005BH005CH005DH005EH005FH

10、O2LSO2HSt1SSd2OutLAtCt2t1Ont1ESt1oFSSvt2Ont2ESt2oFStAtPvStwAitPiddPHbALbALbdA2LSA2HSbAudAddrLEv1LEv2LEv3LvSLL1P1d1HSt1AtoFOutmO1LS5 PARA ADDR PARA ADDR PARA ADDRL1i1L1d1L1ArL1P2L1i20060H0061H0062H0063H0064H0065H0066H0067H0068H0069H006AH006BH006CH006DH006EH006FH0070H0071H0072H0073H0074H0075H0076H0077

11、H0078H0079H007AH007BH007CH007DH007EH007FHtS1Sv2tP2tS2Sv3tP3tS3Sv4tP4tS4Sv5tP5tS5Sv6tP6tS6Sv7tP7tS7Sv8tP8tS81-21-31-41-51-61-71-81-91-101-110080H0081H0082H0083H0084H0085H0086H0087H0088H0089H008AH008BH008CH008DH008EH008FH0090H0091H0092H0093H0094H0095H0096H0097H0098H0099H009AH009BH009CH009DH009EH009FH0

12、0A0H00A1H00A2H00A3H00A4H00A5H00A6H00A7H00A8H00A9H00AAH00ABH00ACH00ADH00AEH00AFH00B0H00B1H00B2H00B3H00B4H00B5H00B6HL1d2L2P1L2i1L2d1L2ArL2P2L2i2L2d2L3P1L3i1L3d1L3ArL3P2L3i2L3d2L4P1L4i1L4d1L4ArL4P2L4i2L4d2SEGTimEEndSSv1tP16 CRC GenerationThe Cyclical Redundancy Check (CRC) field is two bytes, containin

13、g a 16bit binary value. TheCRC value is calculated by the transmitting device, which appends the CRC to the message. Thereceiving device recalculates a CRC during receipt of the message, and compares the calculatedvalue to the actual value it received in the CRC field. If the two values are not equa

14、l, an error results.The CRC is started by first preloading a 16bit register to all 1s. Then a process begins of applyingsuccessive 8bit bytes of the message to the current contents of the register. Only the eight bits ofdata in each character are used for generating the CRC. Start and stop bits, and

15、 the parity bit, do notapply to the CRC.During generation of the CRC, each 8bit character is exclusive ORed with the register contents.Then the result is shifted in the direction of the least significant bit (LSB), with a zero filled into themost significant bit (MSB) position. The LSB is extracted

16、and examined. If the LSB was a 1, theregister is then exclusive ORed with a preset, fixed value. If the LSB was a 0, no exclusive OR takesplace.This process is repeated until eight shifts have been performed. After the last (eighth) shift, the next8bit character is exclusive ORed with the registers

17、current value, and the process repeats for eightmore shifts as described above. The final content of the register, after all the characters of themessage have been applied, is the CRC value.A procedure for generating a CRC is:Load a 16bit register with FFFF hex (all 1s). Call this the CRC register.E

18、xclusive OR the first 8bit byte of the message with the loworder byte of the 16bit CRCregister, putting the result in the CRC register.Shift the CRC register one bit to the right (toward the LSB), zerofilling the MSB. Extract andexamine the LSB.(If the LSB was 0): Repeat Step 3 (another shift).(If t

19、he LSB was 1): Exclusive OR the CRCregister with the polynomial value A001 hex (1010 0000 0000 0001).Repeat Steps 3 and 4 until 8 shifts have been performed. When this is done, a complete 8bitbyte will have been processed.Repeat Steps 2 through 5 for the next 8bit byte of the message. Continue doing

20、 this until allbytes have been processed.The final content of the CRC register is the CRC value.When the CRC is placed into the message, its upper and lower bytes must be swapped asdescribed below.7 Placing the CRC into the MessageWhen the 16bit CRC (two 8bit bytes) is transmitted in the message, th

21、e low-order byte will betransmitted first, followed by the high-order byte.For example, if the CRC value is 1241 hex (0001 0010 0100 0001):Data Data Data DataCRCLo CRCHi41 12CRC Byte SequenceCalculation algorithm of the CRC 16Move to the right CRC16NoYesCRC16 XOR POLY CRC 16NoYesNoENDXOR = exclusive

22、 orN = number of information bitsPOLY = calculation polynomial of the CRC 16 = 1010 0000 0000 0001(Generating polynomial = 1 + x2 + x 15 + x 16)In the CRC 16, the 1st byte transmitted is the least significant one.8 Example of CRC calculation (frame 02 07)CRC register initializationXOR 1st character1

23、111 1111 1111 11110000 0000 0000 00101111 1111 1111 1101FFFF0002FFFD7FFEA001DFFF6FFFA001CFFE67FF33FFA00193FE49FF24FFA00184FE427F213FA001813EMove 1 0111 1111 1111 1110|11010 0000 0000 00011101 1111 1111 1111Move 2 0110 1111 1111 1111|11010 0000 0000 00011100 1111 1111 1110Move 3 0110 0111 1111 1110|0

24、Move 4 0011 0011 1111 1111|11010 0000 0000 0001Flag to 1, XOR polynomialFlag to 1, XOR polynomial1001 0011 1111 1110Move 5 0100 1001 1111 1111|0Move 6 0010 0100 1111 1111|11010 0000 0000 00011000 0100 1111 1110Move 7 0100 0010 0111 1111|0Move 8 0010 0001 0011 1111|11010 0000 0000 00011000 0001 0011

25、11101000 0001 0011 11100000 0000 0000 01111000 0001 0011 1001813E00078139409CA001E09D704EA001D04F6827A001C82664133209A0019208490428421241XOR 2nd characterMove 1 0100 0000 1001 1100|11010 0000 0000 00011110 0000 1001 1101Move 2 0111 0000 0100 1110|11010 0000 0000 00011101 0000 0100 1111Move 3 0110 10

26、00 0010 0111|11010 0000 0000 00011100 1000 0010 0110Move 4 0110 0100 0001 0011|0Move 5 0011 0010 0000 1001|11010 0000 0000 00011001 0010 0000 1000Move 6 0100 1001 0000 0100|0Move 7 0010 0100 1000 0010|0Move 8 0001 0010 0100 0001|0Most significant least significant The CRC 16 of the frame is then: 41

27、129 An example of a C language function performing CRC generation is shown on the following pages.All of the possible CRC values are preloaded into two arrays, which are simply indexed as thefunction increments through the message buffer.One array contains all of the 256 possible CRC values for the

28、high byte of the 16bit CRC field, andthe other array contains all of the values for the low byte.Indexing the CRC in this way provides faster execution than would be achieved by calculating a newCRC value with each new character from the message buffer.Note This function performs the swapping of the

29、 high/low CRC bytes internally. The bytes arealready swapped in the CRC value that is returned from the function.Therefore the CRC value returned from the function can be directly placed into the message fortransmission.The function takes two arguments:unsigned char *puchMsg ;A pointer to the messag

30、e buffer containingbinary data to be used for generating the CRCunsigned short usDataLen ; The quantity of bytes in the message buffer.The function returns the CRC as a type unsigned short.CRC Generation Function Using C Languageunsigned short CRC16(puchMsg, usDataLen)unsigned char *puchMsg ; /* mes

31、sage to calculate CRC upon */unsigned short usDataLen ; /* quantity of bytes in message */unsigned char uchCRCHi = 0 xFF ; /* high byte of CRC initialized */unsigned char uchCRCLo = 0 xFF ; /* low byte of CRC initialized */unsigned uIndex ; /* will index into CRC lookup table */while (usDataLen) /*

32、pass through message buffer */uIndex = uchCRCHi *puchMsgg+ ; /* calculate the CRC */uchCRCHi = uchCRCLo auchCRCHiuIndex ;uchCRCLo = auchCRCLouIndex ;return (uchCRCHi 8 | uchCRCLo) ;10 High-Order Byte Table/* Table of CRC values for highorder byte */static unsigned char auchCRCHi = 0 x00, 0 xC1, 0 x8

33、1, 0 x40, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x00, 0 xC1, 0 x81,0 x40, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x01, 0 xC0,0 x80, 0 x41, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x01,0 xC0,

34、 0 x80, 0 x41, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x01, 0 xC0, 0 x80, 0 x41,0 x00, 0 xC1, 0 x81, 0 x40, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x00, 0 xC1, 0 x81,0 x40, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x01,

35、0 xC0,0 x80, 0 x41, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x01,0 xC0, 0 x80, 0 x41, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x00, 0 xC1, 0 x81, 0 x40,0 x00, 0 xC1, 0 x81, 0 x40, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x01, 0 xC0, 0 x80, 0 x41, 0

36、x00, 0 xC1, 0 x81,0 x40, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x01, 0 xC0,0 x80, 0 x41, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x01,0 xC0, 0 x80, 0 x41, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x00, 0 xC1, 0 x81, 0 x4

37、0, 0 x01, 0 xC0, 0 x80, 0 x41,0 x00, 0 xC1, 0 x81, 0 x40, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x00, 0 xC1, 0 x81,0 x40, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x01, 0 xC0,0 x80, 0 x41, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x00, 0 xC1, 0 x81,

38、 0 x40, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x01,0 xC0, 0 x80, 0 x41, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x00, 0 xC1, 0 x81, 0 x40, 0 x01, 0 xC0, 0 x80, 0 x41,0 x00, 0 xC1, 0 x81, 0 x40, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x01, 0 xC0, 0 x80, 0 x41, 0 x00, 0 xC1, 0 x81,0 x40;Low-Order Byte Table/* Table of CRC values f

39、or loworder byte */static char auchCRCLo = 0 x00, 0 xC0, 0 xC1, 0 x01, 0 xC3, 0 x03, 0 x02, 0 xC2, 0 xC6, 0 x06, 0 x07, 0 xC7, 0 x05, 0 xC5, 0 xC4,0 x04, 0 xCC, 0 x0C, 0 x0D, 0 xCD, 0 x0F, 0 xCF, 0 xCE, 0 x0E, 0 x0A, 0 xCA, 0 xCB, 0 x0B, 0 xC9, 0 x09,0 x08, 0 xC8, 0 xD8, 0 x18, 0 x19, 0 xD9, 0 x1B,

40、0 xDB, 0 xDA, 0 x1A, 0 x1E, 0 xDE, 0 xDF, 0 x1F, 0 xDD,0 x1D, 0 x1C, 0 xDC, 0 x14, 0 xD4, 0 xD5, 0 x15, 0 xD7, 0 x17, 0 x16, 0 xD6, 0 xD2, 0 x12, 0 x13, 0 xD3,0 x11, 0 xD1, 0 xD0, 0 x10, 0 xF0, 0 x30, 0 x31, 0 xF1, 0 x33, 0 xF3, 0 xF2, 0 x32, 0 x36, 0 xF6, 0 xF7,0 x37, 0 xF5, 0 x35, 0 x34, 0 xF4, 0

41、x3C, 0 xFC, 0 xFD, 0 x3D, 0 xFF, 0 x3F, 0 x3E, 0 xFE, 0 xFA, 0 x3A,0 x3B, 0 xFB, 0 x39, 0 xF9, 0 xF8, 0 x38, 0 x28, 0 xE8, 0 xE9, 0 x29, 0 xEB, 0 x2B, 0 x2A, 0 xEA, 0 xEE,0 x2E, 0 x2F, 0 xEF, 0 x2D, 0 xED, 0 xEC, 0 x2C, 0 xE4, 0 x24, 0 x25, 0 xE5, 0 x27, 0 xE7, 0 xE6, 0 x26,0 x22, 0 xE2, 0 xE3, 0 x23, 0 xE1, 0 x21, 0 x20, 0 xE0, 0 xA0, 0 x60, 0 x61, 0 xA1, 0 x63, 0 xA3, 0 xA2,0 x62, 0 x66, 0 xA6, 0 xA7, 0 x67, 0 xA5, 0 x65, 0 x64, 0 xA4, 0 x6C, 0 xAC, 0 xAD, 0 x6D, 0 xAF, 0 x6F,0 x6E, 0 xA

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論