/* This method will send a CCNET command to the bill validator and wait for response from it. BufOut is a pointer to the array, containing the command. Array should contain a full command including STX, correct device address, length, command and 2 CRC bytes. BufIn is a pointer to an empty array, which will be filled with the validator’s response.
*/
int CCCRSProtocol::SendCommand(LPBYTE BufOut, LPBYTE BufIn)
{
ResetEvent(hRecieved);
iRecievingError=RE_TIMEOUT;
iBytesToRecieve=3;
COMPort.Send(BufOut,BufOut[2]);
if((BufOut[3]==ACK)||(BufOut[3]==NAK)) return RE_NONE;
if(COMPort.Recieve(BufIn,iBytesToRecieve))
{
if(BufIn[0]!=SYNC)iRecievingError=RE_SYNC;
else
if(COMPort.Recieve((LPBYTE)BufIn+iBytesToRecieve,BufIn[iBytesToRecieve-1]-iBytesToRecieve)) iRecievingError=RE_NONE;
else
{
iRecievingError=RE_DATA;
PurgeComm(COMPort.GetHandle(),PURGE_RXABORT|PURGE_RXCLEAR);
}
}
return iRecievingError;
}