示例#1
0
        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;
        }
示例#2
0
 private void SetBaudRate(BaudRate baudRate)
 {
     byte[] termiosData = new byte[Marshal.SizeOf(typeof(Termios))];
     Libc.tcgetattr(_FileDescriptor.Value, termiosData);
     Libc.cfsetspeed(termiosData, baudRate);
 }