|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
CRC checksum algorithmI’m working with handheld device that communicates with windows service thru the serial port. Transaction between device and my application looks like this: Handshaking: Device sends ENQ Service responds DLE 0 Device sends DLESOH4168840000SR01L01DLEETX4á As you see at the end of the string, after DLE ETX (Data Link escape and end of text) control codes, device sends two more characters 4á. If I’m not mistaking, this would be the calculation of CRC checksum of this string. After each transaction, I need to calculate CRC and compare to the one that device sends. Just to make sure that we didn’t miss any data. I tried many different ways, but can’t come up with the correct algorithm to get 4á on this string. Is anybody can give me a hand on this one? Thanks Hi,
This might be a CRC or, perhaps, a simpler checksum. Since it is only a single byte, my guess is that it is not a CRC (though I have CRC-8 code in my book, its use is quite uncommon). You are printing the data as ASCII/ANSI (text), so the font used can confuse things. If you print out the actual binary data received, I may be able to run a quick check to see what algorithm has been used. Dick -- Richard Grier (Microsoft Visual Basic MVP) See www.hardandsoftware.net for contact information. Author of Visual Basic Programmer's Guide to Serial Communications, 4th Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See www.mabry.com/vbpgser4 to order. Dick,
Here is the actual binary data of this string: ?bRead() {Length=23} (0): 16 (1): 1 (2): 52 (3): 49 (4): 54 (5): 56 (6): 56 (7): 52 (8): 48 (9): 48 (10): 48 (11): 48 (12): 83 (13): 82 (14): 48 (15): 49 (16): 76 (17): 48 (18): 49 (19): 16 (20): 3 (21): 52 (22): 225 Show quoteHide quote "Dick Grier" wrote: > Hi, > > This might be a CRC or, perhaps, a simpler checksum. Since it is only a > single byte, my guess is that it is not a CRC (though I have CRC-8 code in > my book, its use is quite uncommon). > > You are printing the data as ASCII/ANSI (text), so the font used can confuse > things. If you print out the actual binary data received, I may be able to > run a quick check to see what algorithm has been used. > > Dick > > -- > Richard Grier (Microsoft Visual Basic MVP) > > See www.hardandsoftware.net for contact information. > > Author of Visual Basic Programmer's Guide to Serial Communications, 4th > Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See > www.mabry.com/vbpgser4 to order. > > > Hi,
This looks like: DLE-STX[data]DLE-ETX[2-byteCS] Is that your understanding? If so, then this probably is a 16-bit CRC, not a simple checksum. The trick is to determine what CRC (or, perhaps some other form of 2-byte checksum). Do you have any description from the vendor on what it is, or how it is calculated? I've tried your data with a standard CRC-16, and the result is D066, not 34FF (hex format), so my guess it that this CS is different. Can you get any more information on what or how this CS is used? Dick -- Richard Grier (Microsoft Visual Basic MVP) See www.hardandsoftware.net for contact information. Author of Visual Basic Programmer's Guide to Serial Communications, 4th Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See www.mabry.com/vbpgser4 to order. Dick,
I took a look at you book on your web site. As mentioned in a post I am working on an older PLC interafce to OPC. I have written OPC servers before so this is not a problem. I have never writtin a serial communications in VB.NET until now. I have gotten an example rs232 class that seems to work fine. I will have to write a CRC algoritham and since this interface is attached to 10 PLC's on 10 serial ports I was thinking of multi-threading the it. What books would you recommend I look into? I would really rather not use the MSCOMM.OCX from VB6. Thanks wg Show quoteHide quote "Dick Grier" <dick_grierNOSPAM@msn.com> wrote in message news:%23sfOktLfFHA.1044@tk2msftngp13.phx.gbl... > Hi, > > This might be a CRC or, perhaps, a simpler checksum. Since it is only a > single byte, my guess is that it is not a CRC (though I have CRC-8 code in > my book, its use is quite uncommon). > > You are printing the data as ASCII/ANSI (text), so the font used can > confuse things. If you print out the actual binary data received, I may > be able to run a quick check to see what algorithm has been used. > > Dick > > -- > Richard Grier (Microsoft Visual Basic MVP) > > See www.hardandsoftware.net for contact information. > > Author of Visual Basic Programmer's Guide to Serial Communications, 4th > Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See > www.mabry.com/vbpgser4 to order. > > I don't know if you are able to use a beta product or not, but just to let
you know, Visual Studio 2005 includes a serial communication control. Richard Rosenheim Show quoteHide quote "wg" <w*@hotmail.com> wrote in message news:xrHwe.3840$qm.3014@bignews5.bellsouth.net... > Dick, > > I took a look at you book on your web site. As mentioned in a post I am > working on an older PLC interafce to OPC. I have written OPC servers before > so this is not a problem. I have never writtin a serial communications in > VB.NET until now. I have gotten an example rs232 class that seems to work > fine. I will have to write a CRC algoritham and since this interface is > attached to 10 PLC's on 10 serial ports I was thinking of multi-threading > the it. What books would you recommend I look into? I would really rather > not use the MSCOMM.OCX from VB6. > > Thanks > > > wg > "Dick Grier" <dick_grierNOSPAM@msn.com> wrote in message > news:%23sfOktLfFHA.1044@tk2msftngp13.phx.gbl... > > Hi, > > > > This might be a CRC or, perhaps, a simpler checksum. Since it is only a > > single byte, my guess is that it is not a CRC (though I have CRC-8 code in > > my book, its use is quite uncommon). > > > > You are printing the data as ASCII/ANSI (text), so the font used can > > confuse things. If you print out the actual binary data received, I may > > be able to run a quick check to see what algorithm has been used. > > > > Dick > > > > -- > > Richard Grier (Microsoft Visual Basic MVP) > > > > See www.hardandsoftware.net for contact information. > > > > Author of Visual Basic Programmer's Guide to Serial Communications, 4th > > Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See > > www.mabry.com/vbpgser4 to order. > > > > > > Richard,
I have not downloaded it yet. I am worried about it being a beta version. Will this affect anything? wg Show quoteHide quote "Richard L Rosenheim" <rich***@rlr.com> wrote in message news:uKsogsTfFHA.2840@tk2msftngp13.phx.gbl... >I don't know if you are able to use a beta product or not, but just to let > you know, Visual Studio 2005 includes a serial communication control. > > Richard Rosenheim > > > "wg" <w*@hotmail.com> wrote in message > news:xrHwe.3840$qm.3014@bignews5.bellsouth.net... >> Dick, >> >> I took a look at you book on your web site. As mentioned in a post I am >> working on an older PLC interafce to OPC. I have written OPC servers > before >> so this is not a problem. I have never writtin a serial communications in >> VB.NET until now. I have gotten an example rs232 class that seems to work >> fine. I will have to write a CRC algoritham and since this interface is >> attached to 10 PLC's on 10 serial ports I was thinking of multi-threading >> the it. What books would you recommend I look into? I would really rather >> not use the MSCOMM.OCX from VB6. >> >> Thanks >> >> >> wg >> "Dick Grier" <dick_grierNOSPAM@msn.com> wrote in message >> news:%23sfOktLfFHA.1044@tk2msftngp13.phx.gbl... >> > Hi, >> > >> > This might be a CRC or, perhaps, a simpler checksum. Since it is only >> > a >> > single byte, my guess is that it is not a CRC (though I have CRC-8 code > in >> > my book, its use is quite uncommon). >> > >> > You are printing the data as ASCII/ANSI (text), so the font used can >> > confuse things. If you print out the actual binary data received, I >> > may >> > be able to run a quick check to see what algorithm has been used. >> > >> > Dick >> > >> > -- >> > Richard Grier (Microsoft Visual Basic MVP) >> > >> > See www.hardandsoftware.net for contact information. >> > >> > Author of Visual Basic Programmer's Guide to Serial Communications, 4th >> > Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See >> > www.mabry.com/vbpgser4 to order. >> > >> > >> >> > > wg,
You have a few options: You can get free Visual Basic Resource Kit from Microsoft. I has in it the Sax Communications Community Edition .NET Serial control. Something like MSComm control. Also if you look at Dick Grier web site www.hardandsoftware.net , you can download NETComm.ocx control. Val Show quoteHide quote "wg" wrote: > Richard, > > I have not downloaded it yet. I am worried about it being a beta version. > Will this affect anything? > > > wg > > > "Richard L Rosenheim" <rich***@rlr.com> wrote in message > news:uKsogsTfFHA.2840@tk2msftngp13.phx.gbl... > >I don't know if you are able to use a beta product or not, but just to let > > you know, Visual Studio 2005 includes a serial communication control. > > > > Richard Rosenheim > > > > > > "wg" <w*@hotmail.com> wrote in message > > news:xrHwe.3840$qm.3014@bignews5.bellsouth.net... > >> Dick, > >> > >> I took a look at you book on your web site. As mentioned in a post I am > >> working on an older PLC interafce to OPC. I have written OPC servers > > before > >> so this is not a problem. I have never writtin a serial communications in > >> VB.NET until now. I have gotten an example rs232 class that seems to work > >> fine. I will have to write a CRC algoritham and since this interface is > >> attached to 10 PLC's on 10 serial ports I was thinking of multi-threading > >> the it. What books would you recommend I look into? I would really rather > >> not use the MSCOMM.OCX from VB6. > >> > >> Thanks > >> > >> > >> wg > >> "Dick Grier" <dick_grierNOSPAM@msn.com> wrote in message > >> news:%23sfOktLfFHA.1044@tk2msftngp13.phx.gbl... > >> > Hi, > >> > > >> > This might be a CRC or, perhaps, a simpler checksum. Since it is only > >> > a > >> > single byte, my guess is that it is not a CRC (though I have CRC-8 code > > in > >> > my book, its use is quite uncommon). > >> > > >> > You are printing the data as ASCII/ANSI (text), so the font used can > >> > confuse things. If you print out the actual binary data received, I > >> > may > >> > be able to run a quick check to see what algorithm has been used. > >> > > >> > Dick > >> > > >> > -- > >> > Richard Grier (Microsoft Visual Basic MVP) > >> > > >> > See www.hardandsoftware.net for contact information. > >> > > >> > Author of Visual Basic Programmer's Guide to Serial Communications, 4th > >> > Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See > >> > www.mabry.com/vbpgser4 to order. > >> > > >> > > >> > >> > > > > > > > Actually, the DesktopSerialIO dll that I have placed on my site is better
(IMO) than NETComm.ocx for .NET applications, unless you are porting from VB6 -- where it is just about a wash. Dick -- Richard Grier (Microsoft Visual Basic MVP) See www.hardandsoftware.net for contact information. Author of Visual Basic Programmer's Guide to Serial Communications, 4th Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See www.mabry.com/vbpgser4 to order. Hi,
>> I will have to write a CRC algoritham and since this interface isattached to 10 PLC's on 10 serial ports I was thinking of multi-threading the it. What books would you recommend I look into? I would really rather not use the MSCOMM.OCX from VB6. << Threading is OK. Easiest my be to download DesktopSerialIO dll from my homepage. It already implements threaded receive, so you don't really need anything more. It is practical to simply use the OnComm events, which execute in the object's worker thread context. I have CRC examples in my book, and I suspect that the CRC-16 (CCITT) is the one that you need. Dick -- Richard Grier (Microsoft Visual Basic MVP) See www.hardandsoftware.net for contact information. Author of Visual Basic Programmer's Guide to Serial Communications, 4th Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See www.mabry.com/vbpgser4 to order. This looks similar to an Allen-Bradley protocol, so you might want to look
this up. As the last character is only 8-bit it is more likely to be a BCC (binary check character) rather than a CRC, which is usually at least 16-bit. The normal way to calculate a BCC is to sum the data MOD 256. Bear in mind, though, that _data_ does not mean the entire binary string. BCC is usually calculated on only a part of the string. In the case of an Allen-Bradley protocol this would be all data between (but not including) the DLE SOH and DLE ETX. Also, A-B actually takes the two's complement of the resulting BCC. Ultimately, the only way to know for certain is to get some reference for the equipment you are working with from the manufacturer. HTH Charles Show quoteHide quote "ValK" <V***@discussions.microsoft.com> wrote in message news:376C5F72-536F-4469-94A6-75047A07C1F6@microsoft.com... > Hello, > I'm working with handheld device that communicates with windows service > thru > the serial port. > Transaction between device and my application looks like this: > > Handshaking: > Device sends ENQ > Service responds DLE 0 > Device sends DLESOH4168840000SR01L01DLEETX4á > > As you see at the end of the string, after DLE ETX (Data Link escape and > end > of text) control codes, device sends two more characters 4á. > If I'm not mistaking, this would be the calculation of CRC checksum of > this > string. > > After each transaction, I need to calculate CRC and compare to the one > that > device sends. Just to make sure that we didn't miss any data. > I tried many different ways, but can't come up with the correct algorithm > to > get 4á on this string. > Is anybody can give me a hand on this one? > > Thanks > I am in the process of looking for code for a CRC 16H checksum algorithim.
If anyone has this or a reference to where to find one it would be greatly appriciated. I am writing an interface to old old PLC (Programmable Logic Controller). Thanks wg Show quoteHide quote "ValK" <V***@discussions.microsoft.com> wrote in message news:376C5F72-536F-4469-94A6-75047A07C1F6@microsoft.com... > Hello, > I'm working with handheld device that communicates with windows service > thru > the serial port. > Transaction between device and my application looks like this: > > Handshaking: > Device sends ENQ > Service responds DLE 0 > Device sends DLESOH4168840000SR01L01DLEETX4á > > As you see at the end of the string, after DLE ETX (Data Link escape and > end > of text) control codes, device sends two more characters 4á. > If I'm not mistaking, this would be the calculation of CRC checksum of > this > string. > > After each transaction, I need to calculate CRC and compare to the one > that > device sends. Just to make sure that we didn't miss any data. > I tried many different ways, but can't come up with the correct algorithm > to > get 4á on this string. > Is anybody can give me a hand on this one? > > Thanks > Hi,
I have two different CRC-16 algorithms in my book. You also can download from my homepage. However, there are lots of possible algorithms, so you need to know for sure which one is being used. Probably the CCITT CRC-16, but... Dick -- Richard Grier (Microsoft Visual Basic MVP) See www.hardandsoftware.net for contact information. Author of Visual Basic Programmer's Guide to Serial Communications, 4th Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See www.mabry.com/vbpgser4 to order. Dick,
I just ordered you book to help out. I also downloaded the DestopIO dll to ty. The algorithm is CRC-16H or CCITTA. Thanks, wg Show quoteHide quote "Dick Grier" <dick_grierNOSPAM@msn.com> wrote in message news:O03v2gZfFHA.2152@TK2MSFTNGP14.phx.gbl... > Hi, > > I have two different CRC-16 algorithms in my book. You also can download > from my homepage. However, there are lots of possible algorithms, so you > need to know for sure which one is being used. Probably the CCITT CRC-16, > but... > > Dick > > -- > Richard Grier (Microsoft Visual Basic MVP) > > See www.hardandsoftware.net for contact information. > > Author of Visual Basic Programmer's Guide to Serial Communications, 4th > Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See > www.mabry.com/vbpgser4 to order. > > Hi,
What protocol? Some protocols calculate the CRC over only the data (not the packet header and trailer), and some calculate the CRC over the entire packet. Dick -- Richard Grier (Microsoft Visual Basic MVP) See www.hardandsoftware.net for contact information. Author of Visual Basic Programmer's Guide to Serial Communications, 4th Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See www.mabry.com/vbpgser4 to order. Dick,
Not sure the protocal, just rs232 serial string. It calculates it over the data only, not using the header, not sure if there is a trailer. From the PLC manual I am to send a request and the PLC responses with the data. Both the send a receive have a checksum of CITTA. I had sent you an email asking about the DesktopIO form you site. How would you use this control and look for a delimeter? Specifically if the buffer is of size catch a string message and keep the rest. Thanks wg Show quoteHide quote "Dick Grier" <dick_grierNOSPAM@msn.com> wrote in message news:u5b8dnkfFHA.1204@TK2MSFTNGP12.phx.gbl... > Hi, > > What protocol? Some protocols calculate the CRC over only the data (not > the packet header and trailer), and some calculate the CRC over the entire > packet. > > Dick > > -- > Richard Grier (Microsoft Visual Basic MVP) > > See www.hardandsoftware.net for contact information. > > Author of Visual Basic Programmer's Guide to Serial Communications, 4th > Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See > www.mabry.com/vbpgser4 to order. > > |
|||||||||||||||||||||||