Serial, RS422, In C #, the TxDone event does not fire, data is not accepted

I am writing an application that uses OpenNETCF.IO.Serial (open source, see the serial code here ) for its serial communication on Windows CE 6.0. This application is encoded in C # in Compact Framework 2.0. I do not believe that the problem that I am going to describe is specifically related to these details, but I may be wrong in this regard.

The problem I am facing is that, apparently randomly (read as: an intermittent problem that I still can not reliably duplicate), the data will not be transmitted or received until the device itself reboots. A Windows CE device interacts with a system that launches a completely different application. Rebooting this other system and disconnecting / reconnecting the communication cables does not seem to fix this problem, only rebooting the Windows CE device.

The only sign of this problem is the absence of the TxDone event when OpenNETCF starts (look for "TxDone ();" in the OpenNETCF.IO.Serial class) and no data is received when I know that the fact that the connected system is sending data.

Any character value from 1 to 255 (0x01 - 0xFF) can be sent and received in our serial connection. Zero values ​​are discarded.

My sequential settings: 38400 Baud, 8 data bits, no parity, 1 stop bit (38400, 8n1). I set the size of the input and output buffers to 256 bytes. The DataReceived event occurs whenever we receive 1 or more characters, and transmission occurs when there are 1 or more bytes in the output buffer, because messages have a variable length.

No acknowledgment is used. Since this is RS422, only 4 signals are used: RX +, RX-, TX +, TX -.

"DataReceived", , DataReceived. , . Windows CE, . , ", ". / , , . , - .

, - , , , , , , .

, , , .. . , , , , , . .

, 2/24/2011:
(1) , Windows CE, . , , , , , , , , 25V - , 5V -- ).
, , , , , , , , , . , - , , , , .

(2) @ctacke , , , , :

lock(transmitLockObj)
{
    try
    {
        comPort.Output = data;
    }
    [various catches and error handling for each]
}

(3) UART OVERRUN , < 10 300 38400 . , ReadFile TxDone ( ). , , , , . .

My DataReceived :

try
{
    byte[] input = comPort.Input; //set so Input gets FULL RX buffer

    lock(bufferLockObj)
    {
        for (int i = 0; i < input.Length; i++)
        {
            _rxRawBuffer.Enqueue(input[i]);
            //timer regularly checks this buffer and parses data elsewhere
            //there, it is "lock(bufferLockObj){dataByte = _rxRawBuffer.Dequeue();}"
            //so wait is kept short in DataReceived, while remaining safe
        }
    }
}
catch (Exception exc)
{
    //[exception logging and handling]
    //hasn't gotten here, so no point in showing
}

, WriteFile , , UART OVERRUN. , UART OVERRUN.

? , , , .

+3
2

, . , , -, . , , , , - .

0

, , .

, , , , - , , . , , , ( ).

, , Serial lib, , Tx, TxDone . , Serial lib ( , ), - .

+1

Source: https://habr.com/ru/post/1791238/


All Articles