By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,168 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,168 IT Pros & Developers. It's quick & easy.

Get handle from System.IO.SerialPort

P: n/a
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 -

Jan 29 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
hi Kristoffer,

Kristoffer Persson wrote:
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 <--
Jan 29 '07 #2

P: n/a
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?

"Stefan Hoffmann" wrote:
hi Kristoffer,

Kristoffer Persson wrote:
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 <--
Jan 29 '07 #3

P: n/a
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 -

"Kristoffer Persson" wrote:
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 -
Feb 1 '07 #4

P: n/a
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...

--
Per aspera ad astra

Diderot
"Kristoffer Persson" wrote:
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?

"Stefan Hoffmann" wrote:
hi Kristoffer,

Kristoffer Persson wrote:
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 <--
Feb 15 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.