📄 modbus crc.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0039)http://www.temcocontrols.com/modbus.htm -->
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:v =
"urn:schemas-microsoft-com:vml" xmlns:o =
"urn:schemas-microsoft-com:office:office" xmlns:w =
"urn:schemas-microsoft-com:office:word"><HEAD><TITLE>unsigned short CRC16(unsigned char *puchMsg, unsigned char usDataLen)</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content=Word.Document name=ProgId>
<META content="MSHTML 6.00.2800.1106" name=GENERATOR>
<META content="Microsoft Word 9" name=Originator><LINK
href="./modbus2_files/filelist.xml" rel=File-List><!--[if gte mso 9]><xml> <o:DocumentProperties> <o:Author>software</o:Author> <o:LastAuthor>Shirley</o:LastAuthor> <o:Revision>2</o:Revision> <o:TotalTime>95</o:TotalTime> <o:Created>2003-05-23T18:57:00Z</o:Created> <o:LastSaved>2003-05-23T18:57:00Z</o:LastSaved> <o:Pages>4</o:Pages> <o:Words>1484</o:Words> <o:Characters>8462</o:Characters> <o:Lines>70</o:Lines> <o:Paragraphs>16</o:Paragraphs> <o:CharactersWithSpaces>10391</o:CharactersWithSpaces> <o:Version>9.3821</o:Version> </o:DocumentProperties></xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:Compatibility> <w:UseFELayout/> </w:Compatibility> </w:WordDocument></xml><![endif]-->
<STYLE>@font-face {
font-family: SimSun;
}
@font-face {
font-family: @SimSun;
}
@page Section1 {size: 623.7pt 842.0pt; margin: 1.0in 89.85pt 74.0pt 89.85pt; mso-header-margin: 35.45pt; mso-footer-margin: 35.45pt; mso-paper-source: 0; }
P.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"; mso-style-parent: ""; mso-pagination: widow-orphan; mso-fareast-font-family: SimSun; mso-fareast-language: ZH-CN
}
LI.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"; mso-style-parent: ""; mso-pagination: widow-orphan; mso-fareast-font-family: SimSun; mso-fareast-language: ZH-CN
}
DIV.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"; mso-style-parent: ""; mso-pagination: widow-orphan; mso-fareast-font-family: SimSun; mso-fareast-language: ZH-CN
}
H1 {
FONT-SIZE: 14pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: Arial; mso-pagination: widow-orphan; mso-fareast-language: ZH-CN; mso-style-next: Normal; mso-outline-level: 1; mso-bidi-font-size: 8.0pt; mso-font-kerning: 0pt
}
H2 {
FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: Arial; mso-pagination: widow-orphan; mso-fareast-language: ZH-CN; mso-style-next: Normal; mso-outline-level: 2; mso-bidi-font-size: 8.0pt
}
A:link {
COLOR: blue; TEXT-DECORATION: underline; text-underline: single
}
SPAN.MsoHyperlink {
COLOR: blue; TEXT-DECORATION: underline; text-underline: single
}
A:visited {
COLOR: purple; TEXT-DECORATION: underline; text-underline: single
}
SPAN.MsoHyperlinkFollowed {
COLOR: purple; TEXT-DECORATION: underline; text-underline: single
}
P.MsoPlainText {
FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Courier New"; mso-pagination: widow-orphan; mso-fareast-font-family: SimSun; mso-fareast-language: ZH-CN
}
LI.MsoPlainText {
FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Courier New"; mso-pagination: widow-orphan; mso-fareast-font-family: SimSun; mso-fareast-language: ZH-CN
}
DIV.MsoPlainText {
FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Courier New"; mso-pagination: widow-orphan; mso-fareast-font-family: SimSun; mso-fareast-language: ZH-CN
}
DIV.Section1 {
page: Section1
}
OL {
MARGIN-BOTTOM: 0in
}
UL {
MARGIN-BOTTOM: 0in
}
</STYLE>
<!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="1027"/></xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1"/> </o:shapelayout></xml><![endif]--></HEAD>
<BODY lang=EN-US style="tab-interval: .5in" vLink=purple link=blue>
<DIV class=Section1>
<P class=MsoNormal><SPAN style="FONT-FAMILY: Arial">Modbus protocol is a widely
used and well documented communications method. It was selected for the tstat
protocol since it provides a very simple and low overhead means of writing
information to the Tstat products. <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: Arial"><![if !supportEmptyParas]><![endif]> <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: Arial">The tstat communications
follows a simple routine of queries issued by the master (your product) and our
tstats (the slaves). Modbus has various command types, we keep things simple by
using only the READ and WRITE commands, type 3 and type 5 commands in Modbus
parlance. The master will prepare a packet comprised of the target address,
command type (read or write) , the starting address and number of bytes to be
accessed, and finally a CRC for error detection. <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: Arial"><![if !supportEmptyParas]><![endif]> <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: Arial">Tstats are set to
communicate over RS485 network using 9600 baud, N81 byte structure. Normal RS485
distance, termination and cabling rules apply. Physical layer is standard
twisted pair + ground cabling. A shield is optional.<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: Arial"><![if !supportEmptyParas]><![endif]> <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Arial; mso-fareast-language: EN-US">A modbus packet looks
like this: <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Arial; mso-fareast-language: EN-US"><SPAN
style="mso-spacerun: yes"> </SPAN>Byte1<SPAN
style="mso-spacerun: yes"> </SPAN>Device ID, the destination address
for a particular message<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Arial; mso-fareast-language: EN-US"><SPAN
style="mso-spacerun: yes"> </SPAN>Byte2<SPAN
style="mso-spacerun: yes"> </SPAN>Function<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Arial; mso-fareast-language: EN-US"><SPAN
style="mso-spacerun: yes"> </SPAN>Byte3<SPAN
style="mso-spacerun: yes"> </SPAN>Starting address of the particular
storage register(s) to be read or written, hi byte, <o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Arial; mso-fareast-language: EN-US"><SPAN
style="mso-spacerun: yes"> </SPAN>Byte4<SPAN
style="mso-spacerun: yes"> </SPAN>Starting address low
byte<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Arial; mso-fareast-language: EN-US"><SPAN
style="mso-spacerun: yes"> </SPAN>Byte5<SPAN
style="mso-spacerun: yes"> </SPAN>No of registers to read/write (hi
byte)<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Arial; mso-fareast-language: EN-US"><SPAN
style="mso-spacerun: yes"> </SPAN>Byte6<SPAN
style="mso-spacerun: yes"> </SPAN>No of registers to read/write (low
byte)<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Arial; mso-fareast-language: EN-US"><SPAN
style="mso-spacerun: yes"> </SPAN>Byte7<SPAN
style="mso-spacerun: yes"> </SPAN>CRC hi byte<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Arial; mso-fareast-language: EN-US"><SPAN
style="mso-spacerun: yes"> </SPAN>Byte8<SPAN
style="mso-spacerun: yes"> </SPAN>CRC low byte</SPAN><SPAN
style="mso-fareast-language: EN-US"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="mso-fareast-language: EN-US"><![if !supportEmptyParas]><![endif]> <o:p></o:p></SPAN></P>
<P class=MsoNormal><B><SPAN
style="FONT-FAMILY: Arial; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-US; mso-bidi-font-size: 14.0pt">Software
tools can be found at : <A
href="http://www.wittecom.com/">http://www.wittecom.com/</A><o:p></o:p></SPAN></B></P>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: Arial; mso-fareast-language: EN-US">If your application can
read & write bytes to a separate PC running the 慚odbus Slave
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -