public void Open() { // open serial port int fd = Libc.open(portName, Libc.OpenFlags.O_RDWR | Libc.OpenFlags.O_NONBLOCK); if (fd == -1) { throw new Exception($"failed to open port ({portName})"); } // set baud rate byte[] termiosData = new byte[256]; Libc.tcgetattr(fd, termiosData); Libc.cfsetspeed(termiosData, baudRate); Libc.tcsetattr(fd, 0, termiosData); // start reading Task.Run((Action)StartReading, CancellationToken); this.fd = fd; }
private void SetBaudRate(BaudRate baudRate) { byte[] termiosData = new byte[Marshal.SizeOf(typeof(Termios))]; Libc.tcgetattr(_FileDescriptor.Value, termiosData); Libc.cfsetspeed(termiosData, baudRate); }