aliasx

I need to enumerate the available serial ports. I'm using c#. Anyone know how

cheers,

gareth



Re: .NET Base Class Library c# serial port enumeration

ahmedilyas

try this:

string[] theSerialPortNames = System.IO.Ports.SerialPort.GetPortNames();

that should return you a list of valid serial ports






Re: .NET Base Class Library c# serial port enumeration

aliasx

Spot on. Thanks, you're a star.



Re: .NET Base Class Library c# serial port enumeration

ahmedilyas

no worries, glad I could help :-)




Re: .NET Base Class Library c# serial port enumeration

hornet77

ahmedilyas wrote:

try this:

string[] theSerialPortNames = System.IO.Ports.SerialPort.GetPortNames();

that should return you a list of valid serial ports



this works with fw 2.0....how can I do the same thing with 1.1

Thanks




Re: .NET Base Class Library c# serial port enumeration

hornet77

ahmedilyas wrote:

try this:

string[] theSerialPortNames = System.IO.Ports.SerialPort.GetPortNames();

that should return you a list of valid serial ports



this works with .NET 2.0....how can I do the same thing with 1.1

Thanks





Re: .NET Base Class Library c# serial port enumeration

hornet77

ahmedilyas wrote:

try this:

string[] theSerialPortNames = System.IO.Ports.SerialPort.GetPortNames();

that should return you a list of valid serial ports



this works with .NET 2.0....how can I do the same thing with 1.1

Thanks




Re: .NET Base Class Library c# serial port enumeration

ahmedilyas

you can't - SerialPorts class was made for .NET 2.0/included in .NET 2.0. I guess you would have to use some Win32 API calls to get the serial ports in .NET 1.1




Re: .NET Base Class Library c# serial port enumeration

nobugz

You can, just do what GetPortNames() does: enumerate the values in HKLM\Hardware\DeviceMap\SerialComm registry key.





Re: .NET Base Class Library c# serial port enumeration

ahmedilyas

System.IO.Ports is a namespace/class that was added in .NET 2.0 and not available in .NET 1.0/1.1. But as suggested you can go through the reg keys as NoBugz has shown - did not mean that no its not possible end of - :-)




Re: .NET Base Class Library c# serial port enumeration

janverge

How about setting the Port.For example a printer to a COM1 or LPT1 or COM2 ...etc. vise versa.

Can C# be able to assign Port programmatically

An example is on your WinXP when you :

1. click Start and click Printer and faxes.

2. Right click any of the printer installed in your local machine and click Properties.

3. It will show "<Your Local Machine Printer name> Properties."

4. Click on the Ports tab and there it will show the following port(s) or the enumerated ports.

5. If I check or choose any of the Port e.g. COM1, COM2 ..etc ... LPT1, LPT2.. etc.. .. FILE:, USB ..etc .etc

QUESTION: Can C# do this programmatically Is there any windows API to programmatically select or put a check mark on the Printer Port selected. Of course alot of the forums as showing the EnumPorts

[DllImport("winspool.drv", EntryPoint = "EnumPorts")]

public static extern int EnumPortsA(string pName, int Level, int lpbPorts, int cbBuf, ref int pcbNeeded, ref int pcReturned);

But this does not help me solve my issue.

Thank you for hearing me out. Hope anyone can share their coding experience regarding this issue.

you may email or send me a reply : janverge@gmail.com





Re: .NET Base Class Library c# serial port enumeration

nobugz

You'd better start a new thread with this question. It is completely unrelated to this thread.