예제 #1
1
DWORD SerialPort::ThreadProc (LPVOID lpdwThreadParam ) {
    SerialPort *port =  (SerialPort *)lpdwThreadParam;
    HANDLE hCOM = port->get_com();
    DWORD read;
    const int buffSize = 1024;
    char buff[buffSize];
    while (true) {
        read = 0;
        bool res = ReadFile(hCOM, buff, buffSize, &read,0);
        if(!port->mTreadFlag)
        	break;
        if(res) {
            if(read > 0) {
                port->mReadError = false;
                buff[read]='\0';
                SerialPortRecieved(port, buff, read);
                port->mBytesRecivedSinceLastSend += read;
            } else {
                if(GetCommModemStatus(hCOM, &read)==0) {
                    if(port->mReadError == false)
                        SerialPortError(port, ERROR_READ_STRING);
                    port->mReadError = true;
                } else {
                    port->mReadError = false;
                }
                port->sleep(100);
            }
        } else {
            port->mReadError = true;
            SerialPortError(port, ERROR_READ_STRING);
            port->sleep(100);
        }
    }
    return 0;
}
void * SerialPort::thread_start(void *arg) {
    SerialPort *port =  (SerialPort *)arg;
    int hCOM = port->get_com();

    const int buffSize = 1024;
    char buff[buffSize];
    while (true) {
        int rb = read(hCOM, buff, buffSize);
        if(!port->mTreadFlag)
        	break;
        if(rb>0) {
            port->mReadError = false;
            buff[rb]='\0';
            SerialPortRecieved(port, buff, rb);
            port->mBytesRecivedSinceLastSend += rb;
        } else if(rb==0) {
            if(port->mReadError==false)
                SerialPortError(port, ERROR_READ_STRING);
            port->mReadError = true;
            port->sleep(100);
        } else {
            port->mReadError = false;
            port->sleep(100);
        }
    }
    return 0;
}
예제 #3
0
static void * thread_start(void *arg)
{
    SerialPort *port =  (SerialPort *)arg;
    int hCOM = port->getCom();

    const int buffSize = 1024;
    char buff[buffSize];
    while (port->mTreadFlag) {
        int rb = read(hCOM, buff, buffSize);
        if(rb>0) {
            port->mReadError = false;
            buff[rb]='\0';
            SerialPortRecieved(port, buff);
            port->lastCharRecieved = buff[rb-1];
        } else if(rb==0) {
            if(port->mReadError==false)
                SerialPortError(port, ERROR_READ_STRING);
            port->mReadError = true;
            usleep(50000);
        } else {
            port->mReadError = false;
            usleep(50000);
        }
    }
    port->mTreadFlag = true;
    return 0;
}