int WriteCommand(unsigned char *ptr)
{
int count;
unsigned long BytesWritten;
int x,Success;
unsigned char wb[12];
DWORD dwStatus;
for(count=0;count < 10;++count)
{
for(x=0;x<9;++x)
wb[x]=0;
/*
Only calculate the CRC on the first 11 bytes. Last byte
of command will contain checksum.
*/
Crc8=0;
for(x=0;x<11;++x)
UpdateCRC8(ptr[x]);
ptr[11] = Crc8;
for(x=0;x<6;++x)
wb[x+1]=ptr[0+x];
Success = WriteFile(DeviceHandle, &wb[0], 9, &BytesWritten, NULL);
if(Success == 0)
{
db("Error30 communicating with device command %X",wb[0]);
return(0);
}
for(x=0;x<6;++x)
wb[x+1]=ptr[6+x];
Success = WriteFile(DeviceHandle, &wb[0], 9, &BytesWritten, NULL);
if(Success == 0)
{
db("Error31 communicating with device");
return(0);
}
Success = ReadUSB(&wb[0]);
if(wb[1] != 0xcc || wb[2] != 0x01)
continue;
else
break;
}
if(wb[1] != 0xcc || wb[2] != 0x01)
{
db("Error32 communicating with device");
return(0);
}
return(1);
}