Timeout exception when writing to virtual COM

I am trying to write to a COM port using .NET sample

I have no problem writing to real COM, but when I try to write to virtual COM I get a timeout exception

Unhandled Exception: System.TimeoutException: Recording timed out. at System.IO.Ports.SerialStream.Write (Byte [] array, Int32 offset, Int32 count, Int32 timeout) at System.IO.Ports.SerialPort.Write (line text) at System.IO.Ports.SerialPort.WriteLine ( line text)

I searched for this issue and found this . according to what said this is the problem:

Function

.net write () uses CreateFile and WriteFile Async like this:

CreateFile("\\\\.\\" + portName,
            NativeMethods.GENERIC_READ | NativeMethods.GENERIC_WRITE,
            0,    // comm devices must be opened w/exclusive-access
            IntPtr.Zero, // no security attributes
            UnsafeNativeMethods.OPEN_EXISTING, // comm devices must use OPEN_EXISTING
            FILE_FLAG_OVERLAPPED,
            IntPtr.Zero  // hTemplate must be NULL for comm devices
            );

WriteFile(_handle, p + offset, count, IntPtr.Zero, overlapped);

      

when i used the ones that had NULL instead of FILE_FLAG_OVERLAPPE

My question is, how can I solve this problem? do i need to write my own code?

0
c # .net serial-port virtual-serial-port


source to share


No one has answered this question yet

See similar questions:

3
C # virtual serial port timeoutexception on write

or similar:

1918
Catching multiple exceptions at once?
1507
What is the difference between an abstract function and a virtual function?
1327
Why is it important to override GetHashCode when the Equals method is overridden?
1242
When to use struct?
1174
Virtual call of the participant in the constructor
957
How and when to use "async and await"
789
When to use. First and when to use .FirstOrDefault with LINQ?
424
Cleanest way to write retry logic?
1
Writing to Serial (Com) Port in Visual C ++
0
VB.NET SerialPort.Write (string) throws uncatchable exception and breaks COM port



All Articles
Loading...
X
Show
Funny
Dev
Pics