How to send 887 Bytes via Com-port in C# .NET

63 views Asked by At

I am using .NET 6 LTS with System.IO.Ports 8.0.

I try to send 887 Bytes using an IR transmitter. P is my Com-port. The first 873 bytes are "wakeup" bytes:

for (uint u = 1; u <= 873; u++)
{
    Byte[] bb = { 0x0E };
    P.Write(bb, 0, 1);
}

The problem is, in this case i will only receive (and as it happens send) 425 bytes of those 873. Always this exact number. I also tried using an Array with 873 times 0x0E - this doesn't change anything.

If I add a dirty delay, I receive all bytes:

for (uint u = 1; u <= 873; u++)
{
    Byte[] bb = { 0x0E };
    P.Write(bb, 0, 1);
    Thread.Sleep(1);
}

I do also receive all bytes, if I do for (uint u = 1; u <= 200; u++) multiple times with a Thread.Sleep(1); in between those for.

Unluckily those dirty delays will cause my receiving device not to wake up, because the sequence takes to long (Should be like 4 secs in 2400 Bd 8N1, but is now >14sec).

What is the proper way to do this?

0

There are 0 answers