CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Checksum

  1. #1
    Join Date
    Mar 2004
    Posts
    40

    Checksum

    objective: byte summation of whole message without the header followed by two's complement of the sum.

    Header: 0xAA
    Message Type: 0x01
    Message Length : 0x00
    Checksum: 0xFF

    Question:
    1) how to do a checksum?
    2) Is it to say adding of 0x01 and 0x00 will give me 0xFF or ???
    3) How to send the bytes over?

  2. #2
    Join Date
    Apr 2004
    Posts
    76

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360
    Quote Originally Posted by larry77
    objective: byte summation of whole message without the header followed by two's complement of the sum.

    Question:
    1) how to do a checksum?
    2) Is it to say adding of 0x01 and 0x00 will give me 0xFF or ???
    3) How to send the bytes over?
    What exactly do you mean in the last question? Sending bytes over? To a device or what?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Mar 2004
    Posts
    40
    i am tryin to send the data in hex form over.
    before that i need to conver the data from float form into hex. then send it over.

  5. #5
    Join Date
    May 2004
    Posts
    103
    hey dude...
    hope this helps....
    (i'm assuming u are sending this to a device connected to serial port)

    Code:
    byte buf[4];
    buf[1] = 0xAA;
    buf[2] = 0x01;
    buf[3] = 0x00;
    buf[4] = ...... // u can do ur calculations for ur checksum here dude 
    
    WriteFile (m_hCommPort,buf,sizeof(buf),&dwBytesWritten ,&ov);....
    hopefully this helps....

    later
    Last edited by thamizh07; July 14th, 2004 at 10:32 PM.

  6. #6
    Join Date
    Mar 2004
    Posts
    40
    yup actually, i m sending this data out to other device.

    but i got this error after adding ur code.
    any solution?/

    error C2065: 'byte' : undeclared identifier
    error C2146: syntax error : missing ';' before identifier 'buf'
    error C2065: 'buf' : undeclared identifier
    error C2109: subscript requires array or pointer type
    error C2109: subscript requires array or pointer type
    error C2106: '=' : left operand must be l-value
    error C2109: subscript requires array or pointer type
    error C2106: '=' : left operand must be l-value
    error C2109: subscript requires array or pointer type
    error C2106: '=' : left operand must be l-value
    error C2065: 'm_hCommPort' : undeclared identifier
    error C2065: 'ov' : undeclared identifier

  7. #7
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360
    What application do u have that doesn't recognize byte? Since byte is declared as

    Code:
    typedef unsigned char byte;
    you can replace byte with unsigned char in your code. All the errors will be gone.

    ov must me an OVERLAPPED variable, and is required if your file was opened with FILE_FLAG_OVERLAPPED flag.

    Quote Originally Posted by larry77
    yup actually, i m sending this data out to other device.
    This is what I was asking by sending over.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  8. #8
    Join Date
    Mar 2004
    Posts
    40
    char buf[4];

    buf[0] = 0x9A;
    buf[1] = 0x53;
    buf[2] = 0x54; // m
    buf[3] = 0x9D;


    WriteFile (hCom,buf,sizeof(buf),&dwBytesWritten ,NULL);


    ** data send over to hyper terminal , it display as ascii ( char) , not in hex. How to ssend over in hex?
    Last edited by larry77; July 15th, 2004 at 03:56 AM.

  9. #9
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360
    ASCII is just another representation of binary. Everything in a computer is binary. If you send A, as a number, this is the hex represenation of dec 10 or binary 1010. If you send char A, that is hex 41, or dec 65. So, they (hex A and char 'A')are different things. You're most probably to send number data, not chars (string) to your output device. I'm not familiar with hyper terminals, but it probably converts it to ASCII and display your data in another format.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured