WriteFile (..) does not work in RS232 Communication

  • I am using NETDCU8. To communicate between two prozessors (this from NETDCU8 and an ARM 7) I use the RS232 Port. Everything work well except the order WriteFile (...). Using this the Code runs until this point, a breakpoint in the next line is never reached. Then the whole code is that corrupted, that even a "stop debugging" does not stop the software on the NETDCU8. A whole power off / power on reset has to be done to reanimate the system.
    Using instead of WriteFile (..) TransmitCommChar(..) with a loop works well. ReadFile (..) also works great for reading data.
    Some help would be convenient...

  • Can you create a small code sample that shows this error?


    Regards,


    H. Keller

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • The initialization of the COM Port looks like this:


    The settings look like this:



    This is more or less a copy of example code f&s delivers. The writing to the port looks like this:



    Like already described ReadFile (..) works well, TransmitCommChar (..) like in the Code works well, too. Using the WriteFile (..) (like commented out) does not work. The line SetCommMask was just for some tryout, it does not work with or without that line. The program never leaves the WriteFile Routine.


    The whole stuff works in an own thread.

  • Quote from "YoMas"
    Code
    1. m_hSPort = CreateFile( pszName,
    2. GENERIC_READ | GENERIC_WRITE,
    3. 0,
    4. NULL,
    5. OPEN_EXISTING,
    6. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED | FILE_FLAG_RANDOM_ACCESS,
    7. NULL
    8. );
    9. ...
    10. WriteFile (m_hSPort, &bDaten[0], 1, &dwBytesTransferred, NULL);


    When using FILE_FLAG_OVERLAPPED, you have to give the OVERLAPPED structure to the WriteFile() function. However overlapped access is not supported in WinCE anyway, so maybe removing the FILE_FLAG_OVERLAPPED is already the solution.


    In addition the serial port is a hardware device that can only be read and written sequentially. There is no way of using random access (seek, etc). So you have to remove the FILE_FLAG_RANDOM_ACCESS also. And you can not change the attribute of the COM-port file, therefore also leave out FILE_ATTRIBUTE_NORMAL.


    Now try again...


    Regards,


    H. Keller

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Thank you for your hints, BUT:


    No combination of dwFlagsAndAttributes, nor leaving out all of them works. Still the program stops at WriteFile(..) and never comes out of this routine again.


    Please HELP!!!

  • Hallo,


    have you already tried the "Quick RS232 test" sample from our "Windows CE Samples" forum? I think there is a simple mistake hidden in your code.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Just to give a final answer:
    The mistake lies in fOutxCtsFlow = TRUE and in fOutxDsrFlow = TRUE. Changing both parameters to FALSE solves the probblem.


    Generally the RS232 is extremly bad documented in WCE, also the microsoft webpage is no help at all. So for a lot of settings, which could be made it is not obvious what hardware settings correspond to them.