Esempio n. 1
0
 public static extern int tcgetattr(int fd, out termios t);
Esempio n. 2
0
 public static extern int tcsetattr(int fd, int optional_actions, ref termios t);
Esempio n. 3
0
 public static extern void cfmakeraw(termios t);
Esempio n. 4
0
 public static extern int cfsetspeed(ref termios t, Int32 speed);
Esempio n. 5
0
        private void setOptions()
        {
            termios options;

            Syscalls.tcgetattr(_FileDescriptor, out options);

            /* Set baud rate */
            Syscalls.cfsetspeed(ref options, findBaudrate(_baudRate));

            /* These will ensure that the program does not become the 'owner' of the
             * port subject to sporatic job control and hangup signals,
             * and also that the serial interface driver will read incoming data bytes.
             */

            options.c_cflag |= (Macros.CLOCAL | Macros.CREAD);

            /* Set byte size */
            options.c_cflag &= ~Macros.CSIZE;             /* Mask the character size bits */
            options.c_cflag |= findByteSize(_dataBits);   /* Select 8 data bits */

            /* Set parity */
            switch (_parity)
            {
            case Parity.None:
                options.c_cflag &= ~Macros.PARENB;                 /* Mask the parity bits */
                break;

            case Parity.Odd:
                options.c_cflag |= Macros.PARENB;                 /* Mask the parity bits */
                options.c_cflag |= Macros.PARODD;
                break;

            case Parity.Even:
                options.c_cflag |= Macros.PARENB;                 /* Mask the parity bits */
                options.c_cflag &= ~Macros.PARODD;
                break;

            case Parity.Mark:
                throw new NotImplementedException();

            case Parity.Space:
                throw new NotImplementedException();
            }

            /* Set stop bits */
            if (_stopBits == StopBits.One)
            {
                options.c_cflag &= ~Macros.CSTOPB;
            }
            else if (_stopBits == StopBits.Two)
            {
                options.c_cflag |= Macros.CSTOPB;
            }
            else
            {
                throw new ArgumentOutOfRangeException("Only one and two stop bits are supported");
            }

            /* Dtr Control */
            int status = 0;

            if (_dtrControl == DtrControl.Enable)
            {
                Syscalls.ioctl(_FileDescriptor, Macros.TIOCMGET, ref status);
                status &= ~Macros.TIOCM_DTR;
                Syscalls.ioctl(_FileDescriptor, Macros.TIOCMSET, ref status);
            }

            // Hardware flow control

            /*
             *
             * try {
             *      options.c_cflag |= Macros.CNEW_RTSCTS;
             * } catch (ArgumentNullException) {
             *      try {
             *              options.c_cflag |= Macros.CRTSCTS;
             *      } catch (ArgumentNullException) {
             *              throw new HardwareFlowControlNotSupportedException ();
             *      }
             * }
             */
            /* Enables software flow control */

            /*
             * options.c_iflag |= (Macros.IXON | Macros.IXOFF | Macros.IXANY);
             */

            /* Choose raw input (as opposed to canonical) */
            options.c_lflag &= ~(Macros.ICANON | Macros.ECHO | Macros.ECHOE | Macros.ISIG);

            /* Choose raw output (as opposed to canonical) */
            options.c_oflag &= ~Macros.OPOST;


            /* Enable parity */
            options.c_iflag |= (Macros.INPCK | Macros.ISTRIP);

            /* Set read time out and behavior */
            options.c_cc [Macros.VMIN]  = 0;
            options.c_cc [Macros.VTIME] = 2;             // x100 msec

            /* Write out the options */
            Syscalls.tcsetattr(_FileDescriptor, Macros.TCSAFLUSH, ref options);

            /* Read time*/
            Syscalls.fcntl(_FileDescriptor, Macros.F_SETFL, 0);

            termios check = getOptions();

            if (check.c_iflag != options.c_iflag)
            {
                throw new InvalidOperationException();
            }
        }
Esempio n. 6
0
 public static extern int cfgetospeed(ref termios t);
Esempio n. 7
0
 public static extern int cfsetspeed(ref termios t, Int32 speed);
Esempio n. 8
0
 public static extern int cfgetospeed(ref termios t);
Esempio n. 9
0
 public static extern void cfmakeraw(termios t);
Esempio n. 10
0
 public static extern int tcsetattr(int fd, int optional_actions, ref termios t);
Esempio n. 11
0
 public static extern int tcgetattr(int fd, out termios t);