/// <summary> /// Create new SerialPort from the native library: libserial-release.aar. /// Creates a Serial object and opens the port if a port is specified, otherwise it remains closed until serial::Serial::open is called. /// @throws SerialException Generic serial error. /// @throws SerialIOException I/O error. /// @throws IllegalArgumentException Invalid arguments are given. /// </summary> /// <param name="device">A string containing the address of the serial port, which would be something like 'COM1' on Windows and '/dev/ttyS0' on Linux.</param> /// <param name="baudrate">An unsigned 32-bit integer that represents the baudrate.</param> /// <param name="stopbits">Number of stop bits used, default is stopbits_one, possible values are: stopbits_one, stopbits_one_point_five, stopbits_two.</param> /// <param name="parity">Method of parity, default is parity_none, possible values are: parity_none, parity_odd, parity_even.</param> /// <param name="byteSize">Size of each byte in the serial transmission of data, default is eightbits, possible values are: fivebits, sixbits, sevenbits, eightbits.</param> /// <param name="flowControl">Flowcontrol Type of flowcontrol used, default is flowcontrol_none, possible values are: flowcontrol_none, flowcontrol_software, flowcontrol_hardware.</param> /// <param name="timeout">A serial::Timeout struct that defines the timeout conditions for the serial port. inter_byte_timeout,read_timeout_constant,read_timeout_multiplier,write_timeout_constant,write_timeout_multiplier</param> public SerialPort( string device, int baudrate, Stopbits stopbits, Parity parity, ByteSize byteSize, FlowControl flowControl, Timeout timeout) { SerialPortBuilder Serial = new SerialPortBuilder( device, baudrate, stopbits, parity, byteSize, timeout, flowControl); OnReceiveThread = new System.Threading.Thread(() => { while (!_stopOnReceive) { System.Threading.Thread.Sleep(_howManyDelayOnReceivingThread); var buffer = Read(); if (buffer != null && buffer.Length > 0) { OnReceived(this, new SerialPortEventArgs() { Data = buffer }); } } }); OnReceiveThread.IsBackground = true; OnReceiveThread.Start(); _serialPort = Serial.NativeSerialPort; }