Linux support via mono using /dev/tty as port

Added by beerygaz almost 5 years ago

I'm trying to use the toolkit on mono, but when I try to use MobileGatewayConfiguration.PortName = "/dev/ttyS0" I get an invalid port error when I call the MessageGateway.Find() function. Are these port names supported?

Replies (3)

RE: Linux support via mono using /dev/tty as port - Added by admin over 4 years ago


Have you tried to get all the available ports? /dev/ttyXX should be supported.


RE: Linux support via mono using /dev/tty as port - Added by beerygaz over 4 years ago

You are correct, /dev/ttySxxx is supported. An invalid port throws:

Using port: /dev/ttyS0
MessagingToolkit.Core.GatewayException: /dev/ttyS0 port does not exist

A valid port throws:

Using port: /dev/ttyS1
System.IO.IOException: Invalid argument
  at System.IO.Ports.SerialPortStream.ThrowIOException () [0x00000] in <filename unknown>:0
  at System.IO.Ports.SerialPortStream.SetSignal (SerialSignal signal, Boolean value) [0x00000] in <filename unknown>:0
  at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:SetSignal (System.IO.Ports.SerialSignal,bool)
  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] in <filename unknown>:0
  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] in <filename unknown>:0
  at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
  at MessagingToolkit.Core.Mobile.BaseMobileGateway`1[MessagingToolkit.Core.Mobile.MobileGateway].OpenPort () [0x00000] in <filename unknown>:0
  at MessagingToolkit.Core.Mobile.BaseMobileGateway`1[MessagingToolkit.Core.Mobile.MobileGateway].Connect () [0x00000] in <filename unknown>:0
Invalid argument


            IMobileGateway mobileGateway = MobileGatewayFactory.Default;
            System.Console.WriteLine("Using port: {0}",args[0]);

            MobileGatewayConfiguration config = MobileGatewayConfiguration.NewInstance();

            config.PortName = args[0];
            config.BaudRate = (PortBaudRate)Enum.Parse(typeof(PortBaudRate), "9600");
            config.DataBits = (PortDataBits)Enum.Parse(typeof(PortDataBits), "8");
            config.Parity = PortParity.None;
            config.StopBits = PortStopBits.One;
            config.Handshake = PortHandshake.None;

            // Check for the PIN status during connect
            config.DisablePinCheck = false;

            // Default to verbose by default
            config.LogLevel = LogLevel.Verbose;

            // Create the gateway for mobile
            MessageGateway<IMobileGateway, MobileGatewayConfiguration> messageGateway =
                MessageGateway<IMobileGateway, MobileGatewayConfiguration>.NewInstance();
                mobileGateway = messageGateway.Find(config);
                if (mobileGateway == null)
                    Console.WriteLine("Error connecting to gateway. Check the log file" );
                Console.WriteLine("Connected to gateway successfully");
            catch (Exception ex)

RE: Linux support via mono using /dev/tty as port [closed] - Added by beerygaz over 4 years ago

It turns out this is a problem using socat to create virtual serial ports and using the System.IO.Ports implementation in mono, the two just won't work together. This is not a bug with messagingtoolkit. It does however limit implementation on Linux when using virtual serial ports.