Example #1
0
 /// <summary>
 /// Creates a new Serial Port
 /// </summary>
 /// <param name="portName">Name of the port (COM1, ...)</param>
 /// <param name="baudRate">Baud rate (9600, 115200, ...) </param>
 /// <param name="parity">Parity</param>
 /// <param name="dataBits">Number of data bits (5, 6, 7, or 8)</param>
 /// <param name="stopBits">Stop bits</param>
 public SerialPort(string portName, int baudRate, Parity parity, byte dataBits, StopBits stopBits)
 {
     NewLine = "\r\n";
     lowLevelSerialPort = tempSerialPort;
     lowLevelSerialPort.PortName = portName;
     lowLevelSerialPort.BaudRate = baudRate;
     lowLevelSerialPort.Parity = parity;
     lowLevelSerialPort.DataBits = dataBits;
     lowLevelSerialPort.StopBits = stopBits;
 }
Example #2
0
        /// <summary>
        /// This will create a temporary serial port depending on the operating system.
        /// It also finds the related constructor to call it from <see cref="SerialPort"/> constructor.
        /// </summary>
        static SerialPort()
        {
            switch (Helper.RunningPlatform)
            {
                case Platform.Windows:
                    tempSerialPort = new SerialPortWin32();
                    break;

                case Platform.Linux:
                    tempSerialPort = new SerialPortPOSIX();
                    break;

                default:
                    if (PlatformSpecificImplementation == null)
                        throw new NotImplementedException("SerialPort not implemented for " + Helper.RunningPlatform.ToString());
                    tempSerialPort = PlatformSpecificImplementation.Invoke(Helper.RunningPlatform);
                    break;
            }
            //serialConstructor = (tempSerialPort.GetType()).GetConstructor(new Type[] {
             //   typeof(string), typeof(int), typeof(Parity), typeof(byte), typeof(StopBits) });
        }