Convert string of hex to char
Jul 5, 2013 at 7:03am UTC
Hi
I have this code working:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
char tmp_wku[3];
tmp_wku[0]=0x01;
tmp_wku[1]=0x9D;
tmp_wku[2]=0x62;
char tmp_com[11];
tmp_com[0]=0x09;
tmp_com[1]=0x98;
tmp_com[2]=0x88;
tmp_com[3]=0x55;
tmp_com[4]=0x42;
tmp_com[5]=0xFF;
tmp_com[6]=0xFF;
tmp_com[7]=0xFF;
tmp_com[8]=0xFF;
tmp_com[9]=0xBD;
tmp_com[10]=0x89;
//cout << "..."<<sizeof(tmp_com);
//cout << "--"<<tmp_com;
usb_bulk_write(handlLIN, EP_OUT, tmp_wku, sizeof (tmp_wku), 500);
Sleep(2);
b=usb_bulk_write(handlLIN, EP_OUT, tmp_com, sizeof (tmp_com), 500);
if (b>0)
{
printf("write success %i\n" , b);
}
else
{
printf("%i error writing: %s\n" , b, usb_strerror());
cout << "Error write: " << GetLastErrorStdStr() <<endl;
}
This sends the buffer to a LIN modem.
My question is: can this be done better. If I have a astring of hex numbers like "09 98 88 55 42 FF 00 00 FF BD 89". How could I send this without manually makng a char with hex numbers?
Jul 5, 2013 at 6:20pm UTC
Topic archived. No new replies allowed.