|
-
July 13th, 2004, 12:30 AM
#1
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?
-
July 13th, 2004, 03:03 PM
#2
-
July 14th, 2004, 03:32 AM
#3
 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?
-
July 14th, 2004, 08:24 PM
#4
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.
-
July 14th, 2004, 10:27 PM
#5
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.
-
July 14th, 2004, 10:48 PM
#6
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
-
July 15th, 2004, 02:36 AM
#7
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.
 Originally Posted by larry77
yup actually, i m sending this data out to other device.
This is what I was asking by sending over.
-
July 15th, 2004, 03:33 AM
#8
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.
-
July 15th, 2004, 03:47 AM
#9
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|