473,383 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Get handle from System.IO.SerialPort

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
4 8621
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: henrycortezwu | last post by:
Hi All, I'm trying to connect to a virtual port (COM19, OUTGOING, "Bluetooth Serial Port") using VS2005 System.IO.Ports. When I ran the ff code below here's what happens. 1) VS2005 Compiles w/o...
7
by: Tamir.D | last post by:
is there a way to embed the System.IO.Ports.SerialPort object in my html . so that the client can access to a device connected to his SerialCOM ? i tried to wrap the System.IO.Ports.SerialPort in...
1
by: sranger | last post by:
When I try to use a System.IO.Ports.SerialPort object to read from a serial port, half of the time I have no problems. However, after I successfully read from the serial port, then close the...
5
by: LongBow | last post by:
Hello, Is there a way, in .NET, to determine what are the avialable Serial (Communications) Ports on a Windows OS and is there a way to determine that port isn't being use other than attempting...
0
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
I read from a serialport using a worker thread. Because the worker thread t does not loop often, I cannot wait to terminate the worker thread using a boolean in the While condition. So I have a...
3
by: Adriano | last post by:
Hello, I'm developing an application in VB.NET 2005 that communicates with a device through RS232, and need to send the following sequence of hexadecimal data to the device: 0xFF, 0x01, 0xC3,...
3
by: Bandu | last post by:
hi, i'm using serial port functionality provided by .net framework 2.0 using system.io.ports. Is there anyway that i can set DTR/DSR handshaking? Regards, Bandu
0
by: Bandu | last post by:
Hi, is System.IO.Ports.SerialPort supported in 64bit? I'm writing C# application and its worked fine with 32 bit. But in 64-bit, System.IO.Ports.SerialPort never fire up the Event Handler (e.g....
1
by: JDS | last post by:
I am getting the following error in my application: System.UnauthorizedAccessException was unhandled Message="Access to the port is denied." Source="System" StackTrace: at...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.