Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 213017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:14:23+00:00 2026-05-11T18:14:23+00:00

I am planning on re-writing a Win32 application (native C++) in .NET – most

  • 0

I am planning on re-writing a Win32 application (native C++) in .NET – most likely using mono so I can run it on Win32, Linux and mac. The problem I am trying to solve (having only really developed for Win32) is an issue with the serial port definition. How does one typically identify differences in platform when there is only supposed to be one executable. Specifically, the COM port is identified in windows as COM1 or something like that (\.\COM) but on linux they are specified as something like /dev/ttyS0.

Does one check the platform at runtime for this information?

I think the only difference would be in the opening and closing of the port. The reading and writing is the same.

Perhaps this is a more generic question in that it applies to any platform-specific stuff in mono/.NET.

How do you handle this? In some string resource or config file, or hard-coded and switch based on runtime platform?

Any code sample for this? Note am a C++ developer and not familiar with all the classes available in .NET. is there a way to get either the serial port naming scheme from the CLR or is there a way to get the OS/Platform from the CLR?

it would have been nice for the CLR to have been able to present the serial ports in a more independent manner. Maybe that is not possible.

Thanks,
Tim

EDIT

Given the one response so far I guess I should just try the
SerialPort.GetPortNames() enumeration first to see if it works. (on both platforms)

In win32 for the higher port numbers and ofr the USB dongle – it is not as simple as the basic COM port enumeration.

I will report the findings here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:14:23+00:00Added an answer on May 11, 2026 at 6:14 pm

    Just discovered this thread, and thought I aught to just add my discoveries: randomly, I am also worried about this on a mac. In Windows and Linux (in VS and Mono alike) SerialPort.GetPortNames() return a list, with the following rules:

    1) Windows returns a list of strings like Com1, Com4, missing out any which don’t exist (USB Serial adapters seem to take a COM number based on the plug they are plugged into, consistantly) From my serial port scanner:

    Scanning COM1
    Scanning COM4
    Scanning Complete

    2) Linux returns all possibly tty serial ports that the compiler of the linux distro has enabled. This seems to be about 8 ports, which if you try to open, will throw an exception (from my serial port scanner:

    Scanning /dev/ttyS0
    Scanning /dev/ttyS1 Port FailedSystem.IO.IOException: I/O Error
    at System.IO.Ports.SerialPortStream..ctor (System.String portName, Int32 baudRate, Int32 dataBits, Parity parity, StopBits stopBits, Boolean dtrEnable, Boolean rtsEnable, Handshake handshake, Int32 readTimeout, Int32 writeTimeout, Int32 readBufferSize, Int32 writeBufferSize) [0x00000]
    at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
    at System.IO.Ports.SerialPort.Open () [0x00000]
    at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
    at HSMScanner.Program.Main (System.String[] args) [0x00000]
    Scanning /dev/ttyS2 Port FailedSystem.IO.IOException: I/O Error
    at System.IO.Ports.SerialPortStream..ctor (System.String portName, Int32 baudRate, Int32 dataBits, Parity parity, StopBits stopBits, Boolean dtrEnable, Boolean rtsEnable, Handshake handshake, Int32 readTimeout, Int32 writeTimeout, Int32 readBufferSize, Int32 writeBufferSize) [0x00000]
    at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
    at System.IO.Ports.SerialPort.Open () [0x00000]
    at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
    at HSMScanner.Program.Main (System.String[] args) [0x00000]
    Scanning /dev/ttyS3 Port FailedSystem.IO.IOException: I/O Error
    at System.IO.Ports.SerialPortStream..ctor (System.String portName, Int32 baudRate, Int32 dataBits, Parity parity, StopBits stopBits, Boolean dtrEnable, Boolean rtsEnable, Handshake handshake, Int32 readTimeout, Int32 writeTimeout, Int32 readBufferSize, Int32 writeBufferSize) [0x00000]
    at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
    at System.IO.Ports.SerialPort.Open () [0x00000]
    at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
    at HSMScanner.Program.Main (System.String[] args) [0x00000]

    3) Macs…

    Oh dear oh dear. Macs (when a usb serial port is plugged in and drivers and everything are ok) don’t return anything on the GetPortNames(). Nada. Looking in the /dev/tty, the extra devices appear only when the device is plugged in and has names like /dev/tty.usbserial-A7006Ro7 unfortunatly, using this name as an argument to the program followed by serial.open dosnt seem to have any effect.

    Looking more into it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm planning on writing a medium-size WinForms application that I'll write in C#, .NET
We're writing an asp.net web app on IIS 6 and are planning on storing
One thing I struggle with is planning an application's architecture before writing any code.
I'm planning on writing a program for Linux that uses text to speech and
So I'm planning on writing an application that is largely a windowless application. There
I'm planning on writing a simple application in Java which has a basic UI
I am planning on writing a medium size web application that will be XML
I am writing an application similar to a chat server-client pair. I am planning
I was planning to use url routing for a Web Forms application. But, after
I'm planning on writing an RPC server in Java. The server needs to accept

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.