예제 #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 SetTermios(Termios terminos)
 {
     byte[] termiosData = TermiosHelpers.getBytes(terminos);
     Libc.tcsetattr(_FileDescriptor.Value, 0, termiosData);
 }