[sldev] Serial port errors

Ajinkya Kale kaleajinkya at gmail.com
Sat May 10 22:29:22 PDT 2008


In the idle() function of llappviewer.cpp I did the following to
continuously poll serial port data :

void LLAppViewer::idle()
{
    LLSD info;
    LPWSTR        portSerial = new WCHAR[MAX_PATH];

    //Get_Version_Str(info);

    info["COM1"] = ll_convert_wide_to_string(portSerial);

    HANDLE hSerial;
    hSerial =
CreateFile(portSerial,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);

    if(hSerial==INVALID_HANDLE_VALUE)
    {
        if(GetLastError()==ERROR_FILE_NOT_FOUND)
        {
            llinfos << "SERIAL PORT : Serial port does not exist" << llendl;
        }
        llinfos << "SERIAL PORT : we had an unknown error " << llendl;
    }

    DCB dcbSerialParams = {0};

    if (!GetCommState(hSerial, &dcbSerialParams))
    {
           llinfos << "SERIAL PORT : error getting serial port state " <<
llendl;

    }

    dcbSerialParams.BaudRate=CBR_19200;
    dcbSerialParams.ByteSize=8;
    dcbSerialParams.StopBits=ONESTOPBIT;
    dcbSerialParams.Parity=NOPARITY;

    if(!SetCommState(hSerial, &dcbSerialParams))
    {
         llinfos << "SERIAL PORT : something went wrong with setting the
serial port state. " << llendl;

    }

    COMMTIMEOUTS timeouts={0};
    timeouts.ReadIntervalTimeout=50;
    timeouts.ReadTotalTimeoutConstant=50;
    timeouts.ReadTotalTimeoutMultiplier=10;
    timeouts.WriteTotalTimeoutConstant=50;
    timeouts.WriteTotalTimeoutMultiplier=10;

    if(!SetCommTimeouts(hSerial, &timeouts))
    {
        llinfos << "SERIAL PORT : there was a problem setting the timeouts "
<< llendl;
    }

    char sBuff[2] = {0};
    DWORD dwBytesRead = 0;

    if(!ReadFile(hSerial, sBuff, 1, &dwBytesRead, NULL))
    {
         llinfos << "SERIAL PORT : error reading file" << llendl;
    }
    else
    {
         llinfos << sBuff << llendl;
    }


    CloseHandle(hSerial);

--------------------------------------------------------------------------------------------------------------------------------------
When the viewer starts I get the following errors in the idle loop :
INFO: LLAppViewer::idle: SERIAL PORT : we had an unknown error
INFO: LLAppViewer::idle: SERIAL PORT : error getting serial port state
INFO: LLAppViewer::idle: SERIAL PORT : something went wrong with setting the
serial port state.
INFO: LLAppViewer::idle: SERIAL PORT : there was a problem setting the
timeouts
INFO: LLAppViewer::idle: SERIAL PORT : error reading file


Any suggestion ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.secondlife.com/pipermail/sldev/attachments/20080510/cb28f547/attachment.htm


More information about the SLDev mailing list