Re: formatting of hex values
Quote:
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
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
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
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
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.
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
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