Search

Technical Discussion Group Forum

This forum is provided for user discussion. While Beacon EmbeddedWorks support staff and engineers participate, Beacon EmbeddedWorks does not guarantee the accuracy of all information within in the Technical Discussion Group (TDG).

The "Articles" forums provide brief Articles written by Beacon EmbeddedWorks engineers that address the most frequently asked technical questions.

To receive email notifications when updates are posted for a Beacon EmbeddedWorks product download, please subscribe to the TDG Forum of interest.

TDG Forum

PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 03 Sep 2008 09:17 AM by  freem
Serial port driver/timing in windows CE
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages

freem



New Member


Posts:
New Member


--
31 Mar 2008 03:36 PM
    Logic

    The serial port not buffering any out going chars. Somebody(Logic or MS) is blocking my threads when I write to the port. I have put together a test app that if the serial port driver was interrupt driven and has a buffer should generate a pulsetrain with a period of 10mS - 11mS. It does not, I see the Writefile blocking until char is sent. I need to know why and how to fix this! My Windows image has all of latest drivers in it. Here is test my code:

    int _tmain(int argc, _TCHAR* argv[])
    {
    DWORD dwBytesWritten;
    char acTest[] = {0x00, 0x00};
    HANDLE hSerialDriverCommPort;
    DCB srSerialDriverDcb;
    COMMTIMEOUTS srSerialDriverTimeout;


    //Open the port
    hSerialDriverCommPort = CreateFile(TEXT("COM2:"),
    GENERIC_READ|GENERIC_WRITE,
    0,
    0,
    OPEN_EXISTING,
    FILE_FLAG_OVERLAPPED,
    0);



    //Setup the serial baud and other settings
    memset(&srSerialDriverDcb, 0x00, sizeof(DCB));
    srSerialDriverDcb.DCBlength = sizeof(DCB);
    GetCommState (hSerialDriverCommPort,&srSerialDriverDcb);

    srSerialDriverDcb.BaudRate = 2400;
    srSerialDriverDcb.ByteSize = 8;
    srSerialDriverDcb.Parity = NOPARITY;
    srSerialDriverDcb.fBinary = TRUE;
    srSerialDriverDcb.fParity = FALSE;
    srSerialDriverDcb.StopBits = ONESTOPBIT;
    srSerialDriverDcb.fAbortOnError = FALSE;
    srSerialDriverDcb.fRtsControl = RTS_CONTROL_DISABLE;

    SetCommState(hSerialDriverCommPort, &srSerialDriverDcb);

    //Set the serial timeouts
    srSerialDriverTimeout.ReadIntervalTimeout = 1;
    srSerialDriverTimeout.ReadTotalTimeoutConstant = 1;
    srSerialDriverTimeout.ReadTotalTimeoutMultiplier = 1;
    srSerialDriverTimeout.WriteTotalTimeoutConstant = 10;
    srSerialDriverTimeout.WriteTotalTimeoutMultiplier = 1;

    SetCommTimeouts(hSerialDriverCommPort, &srSerialDriverTimeout);
    CeSetThreadPriority(GetCurrentThread(), 0);
    while(1)
    {
    Sleep(10); //10mS + (0uS to 1000uS), Timing is 10mS to 11mS
    //Write char
    WriteFile(hSerialDriverCommPort, acTest, 1, &dwBytesWritten, NULL); //This blocks for 4mS, why????????
    }
    return 0;

    red3791@gmail.com



    New Member


    Posts:
    New Member


    --
    02 Apr 2008 09:20 AM
    I am currently having the same problem, I tried a very similar application and received the same results. Any help would be appreciated !

    Thanks,

    AlanREI



    New Member


    Posts:
    New Member


    --
    03 Sep 2008 08:39 AM
    I've not written a driver before but...

    Normally, the sleep function only has a resolution of about 15.625 ms due to the system clock's resolution. Ordinarily, you have to use QueryPerformanceCounter function and calculate a delta and the time period based off of it's tick frequency which can also be queried.

    I wasn't sure if this applied to driver code, but after a quick google search I did find some Microsoft driver code example with QueryPerformanceCounter calls in it. My guess, is that if your 11 ms sleep is taking 15 ms, this may be the problem.

    freem



    New Member


    Posts:
    New Member


    --
    03 Sep 2008 09:17 AM
    Follow up

    Windows CE does not support overlapping of serial ports. In simpler terms no buffering. WriteFile will block while writing serial port.

    Thanks for the input but I got this one licked. To deal with this problem I created a thread and buffer for writing to the port.

    Thanks
    You are not authorized to post a reply.