Problem with serial communication in real time application

  • Hello all
    I would like to write a real time application in Windows CE and NetDCU8.
    for testing real time in Windows CE, I wrote two program and load them in two NetDCU8 board. One of them sends a text file(8192 bytes) and another and get file and save it via Serial port. sender sends a block of data and wait for receiver Acknowledgement. I test program in different size of blocks to send (for example 2048, 1024, 512, ...) In receiver I can get file correctly.
    But my problem is:
    I expected the all receiving process takes T msec but when I measure time, receiveing process takes (T + X) msec and X is different when I change size of block to send and receive. for example I got this:
    I calculated T and that must be about 630 msec (in 115200 bps).


    Block Size X(msec)
    2048 52
    1024 72
    512 192
    256 332
    128 702
    64 1312
    32 2557


    I know X may be included some background process time but I cannot underestand why X is very huge and how can I calculate time and how can I insure about time in real time application.


    Thanks

  • Quote

    I expected the all receiving process takes T msec but when I measure time, receiveing process takes (T + X) msec and X is different when I change size of block to send and receive.


    It is important that you set the timeouts to your needs with SetCommTimeouts(). It also depends on how you read the file on the receiving side.


    The serial protocol just sends the bytes, there is no further information how many bytes are transmitted or when the transmission of a block ends. For example if you just use ReadFile() to read from the serial port, then either the requested number of bytes must have been received, or a timeout has to be recognized before the function returns. Did you adapt the receiving block size to the sending block size? Or do you just wait for a rather large number of bytes?


    Because if the receiving side has to wait for a timeout, then it is logical that each additional block increases the total time, as each block has to wait for the timeout.


    There are several ways to reduce this additional time. Two of them may be these:


    1. Send some special "End of block" character after each block and use it to trigger the receiving side to process the data.


    2. Use the so called windowing technique when transferring the data to reduce the handshaking time for the acknowledgement. The problem with your solution is that the sending side has to wait with the next block until the previous block is acknowledged. This is dead time. But if you use a window of two blocks, then the sending side can continue to send already the next block before the first block has to be acknowledged. Therefore the sending of data and the receiving of acknowledgements can overlap. This uses the full-duplex-feature of a serial line much better. You can extend this method to a window of three or more windows. Just include the block number in the acknowledgement for that the sender knows which block is OK and which is not.


    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.

  • Dear Mr. Keller
    Thank you for your reply.


    In receiving side, I use ReadFile() with the same block size in sender. for example if block size in sender is 2048 bytes, in reseiver is 2048 bytes too. and I set commmunication port timeouts.


    I try to use another solution that you told me.
    but
    Is delay causes by task switching in windows and API overheads?
    How can measure those overheads?


    Thanks

  • Quote

    Is delay causes by task switching in windows and API overheads?


    I think all of that together. For example I could imagine that ReadFile() automatically issues a new thread to wait for the data. This alone can be responsible for some delay. But that is just speculation, I don't know all these internals of Windows CE myself.


    Quote

    How can measure those overheads?


    I think for this problem the Remote Kernel Tracker can help you fine. There you can see when the task switches happen and how fast your thread is getting the data.


    Tip: Print the CurrentThreadID() at the start of your program, then you'll find it easier in the tracker output.


    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.

  • dear Mr. Keller
    Thanks for your reply
    My problem is I want calculate time in real time and I need that times for writing main program.
    I need to know how to calculate all things (or measure that).
    for example I want to send 2048 byte via serial port with 115200 baudrate
    I know the pure time is about 178 msec (10 bit for each byte) but what is the overhead of that? and how can I calculate the total time?
    Is exist any calcutable things that I tell exactly this takes X msec?


    The main problem for me is that I don't know how to calculate the time of a particular work. and I need that timing because I have to write a real time application.


    Could you please lead me?
    Thanks