Glenn, looking at your data, I suspect it's a sending problem (and a reciveing problem)
0c FF 00 00 00 #0 This is from you to the card?
#3B025301 00000001 0 Response - not sure what it decodes to exactly, but I assume "OK" with some info.
0c #FF000000 I assume this is the return?
If so, then I would send hex 123 as:
0c 23 01 00 00 #0
as the data looks to be 32 bit little endian (rather than PC which is big endian, so the lowest byte is on the RHS)
If so, it would explain why you are having problems - is there any way you can check? Or point me at the interface specification manual?
"Hi,
Just sent 123(hex) as 0c 23 01 00 00 with the command /cw 0c 23 01 00 00 via HyperTerm got a #0 when I read it with a cr I get 23010000(hex) I read in as 23010000 which I tranlate to 00000123 parse to 291(dec) Meaning my reading function is OK. When I send I am sending 291 (dec) is 0c 12 30 00 00 meaning my send is wrong. I need to go back to the string parsing thanks."
If all you need is little endian <--> integer, then that's pretty easy:
public static string IntToLEString(int i)
{
StringBuilder sb = new StringBuilder(4 * 2 + 3);
sb.AppendFormat("{0:X2} ", ((i >> 00) & 0xFF));
sb.AppendFormat("{0:X2} ", ((i >> 08) & 0xFF));
sb.AppendFormat("{0:X2} ", ((i >> 16) & 0xFF));
sb.AppendFormat("{0:X2} ", ((i >> 24) & 0xFF));
return sb.ToString();
}
public int LEStringToInt(string s)
{
int result = 0;
string byte0 = s.Substring(0, 2);
string byte1 = s.Substring(3, 2);
string byte2 = s.Substring(6, 2);
string byte3 = s.Substring(9, 2);
result = int.Parse(byte0, NumberStyles.HexNumber) |
int.Parse(byte1, NumberStyles.HexNumber) << 8 |
int.Parse(byte2, NumberStyles.HexNumber) << 16 |
int.Parse(byte3, NumberStyles.HexNumber) << 24;
return result;
}
I'd probably want to put some error checking in, but you are probably doing that to recognise the response already. (You may need to ignore the spaces on the returned values as well, but that's pretty easy)