Get handle from System.IO.SerialPort

G

Guest

Does anyone know if it's possible to get the Win32 handle to the serial port
used under the hood in System.IO.SerialPort?

The reason I want it is so I'd be able to make changes the DCB struct. I
want to set the fRtsControl to RTS_CONTROL_TOGGLE so the RTS signal will be
reset automatically when the TX buffer is empty.

- Kristoffer -
 
S

Stefan Hoffmann

hi Kristoffer,

Kristoffer said:
Does anyone know if it's possible to get the Win32 handle to the serial port
used under the hood in System.IO.SerialPort?
The reason I want it is so I'd be able to make changes the DCB struct. I
want to set the fRtsControl to RTS_CONTROL_TOGGLE so the RTS signal will be
reset automatically when the TX buffer is empty.
Using VS2005, System.IO.Ports.SerialPort has a property RtsEnable.


mfG
--> stefan <--
 
G

Guest

Yes, it does. But I can't use it unless I know exactly when the buffer is
empty. If I set it too soon, not all bytes will be sent. If I set it too
late, I will miss incoming communication. If I could somehow set the
RTS_CONTROL_TOGGLE for the port, I wouldn't have to worry.

The other option would be to wait for a "tx buffer empty" event to be
signalled after a call to Write. Something like this:

port.RtsEnable = true;
port.Write(buffer, 0, byteCount);
WaitForTxBufferToBeEmpty(port);
this.port.RtsEnable = false;

....but then how do I implement WaitForTxBufferToBeEmpty?
 
G

Guest

I never got an answer to my question, but I assume there is no way to get the
Win32 handle to the serial port. To be able to use the RTS_CONTROL_TOGGLE
feature, I had to use platform invoke and the Win32 API.

- Kristoffer -
 
G

Guest

I have the same problem using un RS232/RS485 converter. My workaround is
enable permanet rx on the RS485 conveter. So i can read that i write, end
then switch off RTS.

port.RtsEnable = true;
port.Write(...); /* Write n byte */
port.Read(...); /* Read MY tramitted n byte */
this.port.RtsEnable = false;

I hope this workaround can hel you...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top