|
-
February 18th, 2006, 01:03 AM
#1
formatting of hex values
In our application header and trailor to be added to message and sent of fixed length. The header and trailor are to be sent as hex constant values. so that
it is interpreted on hex on another end...
ex Field1 - 00E7 - size 2 bytes.
Field2- 0002 - size 2 bytes.
On other end too the hex they look for 00E70002..... which should be equivalent to buffer data of ..
Tried formatting by assigning hex values to char array.but
it is not properly interpreted on other end. In addition null gets added to length and they receive one byte addition to expected
length and error out.
please provide how this can be done avoiding the addition of null at End of string and adding 1 byte to length..can this be done with memcpy...tried byt getting different values..
-
February 18th, 2006, 01:16 AM
#2
Re: formatting of hex values
ex Field1 - 00E7 - size 2 bytes.
Field2- 0002 - size 2 bytes.
On other end too the hex they look for 00E70002..... which should be equivalent to buffer data of ..
How you are assigning hex to char ?
try this
Code:
int hexCodeF1,hexCodeF2;
hexCodeF1=0x00E7;
hexCodeF2=0x0002;
Or
char ch[4];
ch[0]=0x00;
ch[1]=0xE7;
ch[2]=0x00;
ch[3]=0x02;
and you can send this directly.
-Anant
Last edited by anantwakode; February 18th, 2006 at 01:23 AM.
-
February 18th, 2006, 03:22 AM
#3
Re: formatting of hex values
You have to tell us a little bit more about your code.
I don't see any reason why you should receive 5 bytes when you only send 4.
Then I don't understand what you mean by sending hex-values.
Do you mean that you try to send short ints as hex-strings ?
Please show some code.
Kurt
-
February 18th, 2006, 11:24 AM
#4
Re: formatting of hex values
Let me be little more clear
we have the struct defining the message fields
{
char MesgLen [3]; //2 bytes
char Reserve[3] // 2bytes
.
.
.
Data[23] //22 bytes
..
trailor [3] // 2bytes
}
In my program as anandt specified have populated the fields with char array
like MesgLen[0]=0x00;
MesgLen[1]=0xE7;
and so on....
we are to sent the message of 28 bytes length..expected out on other end
00E70002AB.....Data.....1C1A The header and trailor have to be hex .Most of the fields gets populated properly...but now the output on other end becomes
20202000.......data...1C1A00
Regarding the mesg length expected number of bytes on other end was 28 bytes but they receive 29 bytes.On my mesg above u can se at the end 00-representing null field.when i get bufferlen on my side it is 28 but i think because of string format null gets added.
Can anything be done to avoid the above problem with memcpy..or any other suggestions ....hope i am clear...please let me know your thoughts
-
February 19th, 2006, 11:38 PM
#5
Re: formatting of hex values
Hi,
Is the size of structure on both end is same.
sizeof(msgStruct) ?
Are you using same exe for sending/Recieving Data ?
Or both application are difft.
-Anant
-
February 20th, 2006, 10:22 PM
#6
Re: formatting of hex values
These are 2 different applications.My application interface with other through TCP/IP socket. The message structure at both ends are same.
-
February 21st, 2006, 03:50 AM
#7
Re: formatting of hex values
What about the struct size on both end ? is it same ?
because sometimes due the different setting of struct member alignment creats trouble.
You can check it from
Project -> Setting -> C/C++ Tab -> Code Genration ->Struct Member alignment.
-Anant
-
February 21st, 2006, 11:33 PM
#8
Re: formatting of hex values
Thanks Anandt for the answers.atlast found the way to do it..
using memcpy instead of strncpy populated the values and got the response
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
|