(完整版)RFID毕业课程设计 下载本文

}

} return 0;

}

if(invFlag ==true){ }

if(accLen

continue; flag = true;

tagNum =buffer[2]; for(;tagNum>0;tagNum--){ }

if((tagNum-1) != num &&(tagNum!=0&&num!=0))

continue;

length = buffer[1];

commandLength+=buffer[1+commandLength]; num = buffer[2+commandLength]; if((tagNum-1) !=num)

break;

if(commandLength

continue;

m=-1; flag=true;

UINT WINAPI CSerialPort::ListenThread( void* pParam ) {

** 得到本类的指针 *

CSerialPort *pSerialPort = reinterpret_cast(pParam); ** 读取输入缓冲区中的数据并输出显示 * char cRecved = 0x00; accum = -1;

if(buffer != NULL){ delete []buffer; }

buffer = new char[1000]; 线程循环,轮询方式读取串口数据 while (!pSerialPort->s_bExit) {

UINT BytesInQue = pSerialPort->GetBytesInCOM(); ** 如果串口输入缓冲区中无数据,则休息一会再查询 * ** 如果Inventory标志位为true,等一轮结束再接受* if ( BytesInQue == 0 && flag1 ==false) if ( BytesInQue == 0) {

Sleep(SLEEP_TIME_INTERVAL); continue; } do {

cRecved = 0x00;

if(pSerialPort->ReadChar(cRecved)) {

accum++;

buffer[accum] = cRecved; }

}while(--BytesInQue); } return 0; }

void CSerialPort::flush(){ }

bool CSerialPort::read(int beg, int len, char arr[]){ }

bool CSerialPort::ReadChar( char &cRecved )这里cRecved是引用 {

BOOL bResult = TRUE; while(len

Sleep(1); m=-1; rdLen = 0;

arr = new char[len];

for(int i=beg;i

arr[i] = buffer[i+rdLen];

rdLen+=len;

}

bool CSerialPort::WriteData( unsigned char* pData, unsigned int length ) {

for(int i=0;i

buffer[i] ='\\0'; DWORD BytesRead = 0; if(m_ false; }

** 临界区保护 *

EnterCriticalSection(&m_csCommunicationSync); ** 从缓冲区读取一个字节的数据 *

bResult = ReadFile(m_(&m_csCommunicationSync); }

** 离开临界区 *

LeaveCriticalSection(&m_csCommunicationSync); return (BytesRead == 1);

return false;

BOOL bResult = TRUE; DWORD BytesToSend = 0; if(m_ false; }

** 临界区保护 *

EnterCriticalSection(&m_csCommunicationSync); ** 向缓冲区写入指定量的数据 *

bResult = WriteFile(m_(&m_csCommunicationSync);