Serial Port

T

Thiago Guedes

Hi,
how can I use Serial Port in C#, using a framework native
code.
I dont want to use P/Invoke.

Tks,
Thiago
 
N

Nicholas Paldino [.NET/C# MVP]

Using an active X control still means that you will be using interop
code of some sort, and it will actually take more instructions to call the
COM code than it would to call the P/Invoke code.

Even when the System.IO.Ports namespace is introduced, my bet is that it
will just be a managed wrapper calling native code anyways, so you might
want to do this yourself for now, and switch over when the namespace is
introduced.

Hope this helps.
 
E

Ed Sutton

If you are going the MSComm COM interop route, simply add a reference in
your C# project to MSCommLib. Click on the COM
tab and browse to select your MSCOMM32.OCX .

Then create an instance of it in your C# class:

MSCommLib.MSComm mscomm = new MSCommLib.MSCommClass();

The MSComm control has been working fine for me however I am still looking
for a better .NET way to do it:

Some alternatives to using the MSComm control in .NET

C#
http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=b06e3
0f9-1301-4cc6-ac14-dfe325097c69

Managed C++
http://www.codeproject.com/managedcpp/howtocomport.asp

VB .NET
http://www.mentalis.org/classlib/class.php?id=15


http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=8aaa0
158-95b6-49a7-bb20-93391fc4c196

C# ( This uses thread pooling that is not supported under Win98)
http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=b06e3
0f9-1301-4cc6-ac14-dfe325097c69

C#
http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=fcba7
fc5-666e-4eb0-863f-0045b0c79ec7

-Ed
 
A

Alan Pretre

Nicholas Paldino said:
Even when the System.IO.Ports namespace is introduced, my bet is that it
will just be a managed wrapper calling native code anyways, so you might
want to do this yourself for now, and switch over when the namespace is
introduced.

We use this MS source, haven't had any trouble with it. It looks a lot like
Longhorn, so I expect trivial conversion later.

http://www.gotdotnet.com/community/usersamples/Default.aspx?query=SerialPort

-- Alan
 
E

Ed Sutton

We use this MS source, haven't had any trouble with it. It looks a
lot like Longhorn, so I expect trivial conversion later.
http://www.gotdotnet.com/community/usersamples/Default.aspx?query=SerialPort

The above approach does not support Win98 or WinME. It uses
BindIoCompletionCallback and Windows 95/98/Me are *all* not supported. Of
course .NET does not support Win95 at all.

Also, some methods of the ThreadPool Class are not supported by Win98.

-Ed
 

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