Exemple #1
0
        private bool SetFrostedAttributes(int fd, int baudRate, Parity parity, int dataBits, StopBits stopBits, Handshake handshake)
        {
            tDeviceInfo newtio = new tDeviceInfo();

            if (TCGetAttribute(fd, newtio) == -1)
            {
                return(false);
            }

            newtio.c_cflag |= (uint)(e_c_oflag.CLOCAL | e_c_oflag.CREAD);
            // there is no definition for e_c_lflag.ECHOL that I can find. It was in the list of or'ed flags below
            unchecked
            {
                newtio.c_lflag &= (uint)-(int)(e_c_lflag.ICANON | e_c_lflag.ECHO | e_c_lflag.ECHOE | e_c_lflag.ECHOK | e_c_lflag.ECHONL | e_c_lflag.ISIG | e_c_lflag.IEXTEN);
            }
            newtio.c_oflag &= (uint)(e_c_oflag.OPOST);
            newtio.c_iflag  = (uint)e_c_iflag.IGNBRK;

            baudRate = SetupBaudRate(baudRate);

            unchecked
            {
                newtio.c_cflag &= (uint)-(uint)e_c_oflag.CSIZE;
            }

            switch (dataBits)
            {
            case 5:
                newtio.c_cflag |= (uint)e_c_oflag.CS5;
                break;

            case 6:
                newtio.c_cflag |= (uint)e_c_oflag.CS6;
                break;

            case 7:
                newtio.c_cflag |= (uint)e_c_oflag.CS6;
                break;

            case 8:
            default:
                newtio.c_cflag |= (uint)e_c_oflag.CS8;
                break;
            }

            switch (stopBits)
            {
            case StopBits.None:
                break;

            case StopBits.One:
                unchecked
                {
                    newtio.c_cflag &= (uint)-(uint)e_c_oflag.CSTOPB;
                }
                break;

            case StopBits.Two:
                newtio.c_cflag |= (uint)e_c_oflag.CSTOPB;
                break;

            case StopBits.OnePointFive:
                break;
            }

            unchecked
            {
                newtio.c_iflag &= (uint)-(uint)(e_c_iflag.INPCK | e_c_iflag.ISTRIP);
            }

            switch (parity)
            {
            case Parity.None:                     /* None */
                newtio.c_cflag &= ~(uint)(e_c_oflag.PARENB | e_c_oflag.PARODD);
                break;

            case Parity.Odd:                     /* Odd */
                newtio.c_cflag |= (uint)(e_c_oflag.PARENB | e_c_oflag.PARODD);
                break;

            case Parity.Even:                     /* Even */
                newtio.c_cflag &= ~(uint)(e_c_oflag.PARODD);
                newtio.c_cflag |= (uint)(e_c_oflag.PARENB);
                break;

            case Parity.Mark:                     /* Mark */
                /* XXX unhandled */
                break;

            case Parity.Space:                     /* Space */
                /* XXX unhandled */
                break;
            }

            newtio.c_iflag &= ~(uint)(e_c_iflag.IXOFF | e_c_iflag.IXON);
#if CRTSCTS
            newtio.c_cflag &= ~CRTSCTS;
#endif //* def CRTSCTS */

            switch (handshake)
            {
            case Handshake.None:                     /* None */
                /* do nothing */
                break;

            case Handshake.RequestToSend:                     /* RequestToSend (RTS) */
#if CRTSCTS
                newtio.c_cflag |= CRTSCTS;
#endif //* def CRTSCTS */
                break;

            case Handshake.RequestToSendXOnXOff:                     /* RequestToSendXOnXOff (RTS + XON/XOFF) */
#if CRTSCTS
                newtio.c_cflag |= CRTSCTS;
#endif //* def CRTSCTS */
            /* fall through */
            case Handshake.XOnXOff:                     /* XOnXOff */
                newtio.c_iflag |= (uint)(e_c_iflag.IXOFF | e_c_iflag.IXON);
                break;
            }

            if (CFSetOSpeed(newtio, baudRate) < 0 || CFSetISpeed(newtio, baudRate) < 0 ||
                TCSetAttribute(fd, (uint)e_tcsetaatr.TCSANOW, newtio) < 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }

            //return set_attributes(fd, baudRate, parity, dataBits, sb, hs);
        }
Exemple #2
0
 private int TCSetAttribute(int fd, uint optional_actions, tDeviceInfo newtio)
 {
     return(tcsetattr(fd, optional_actions, newtio));
 }
Exemple #3
0
 private int CFSetOSpeed(tDeviceInfo newtio, int baudRate)
 {
     newtio.c_ospeed = (uint)baudRate;
     return((int)newtio.c_ospeed);
 }
Exemple #4
0
        private int TCGetAttribute(int fd, tDeviceInfo newtio)
        {
            int result = tcgetattr(fd, newtio);

            return(result);
        }
Exemple #5
0
 private static extern int tcsetattr(int fd, uint optional_actions, tDeviceInfo newtio);
		private bool SetFrostedAttributes(int fd, int baudRate, Parity parity, int dataBits, StopBits stopBits, Handshake handshake)
		{
			tDeviceInfo newtio = new tDeviceInfo();
			if (TCGetAttribute(fd, newtio) == -1)
			{
				return false;
			}

			newtio.c_cflag |= (uint)(e_c_oflag.CLOCAL | e_c_oflag.CREAD);
			// there is no defenition for e_c_lflag.ECHOL that I can find. It was in the list of or'ed flags below
			unchecked
			{
				newtio.c_lflag &= (uint)-(int)(e_c_lflag.ICANON | e_c_lflag.ECHO | e_c_lflag.ECHOE | e_c_lflag.ECHOK | e_c_lflag.ECHONL | e_c_lflag.ISIG | e_c_lflag.IEXTEN);
			}
			newtio.c_oflag &= (uint)(e_c_oflag.OPOST);
			newtio.c_iflag = (uint)e_c_iflag.IGNBRK;

			baudRate = SetupBaudRate(baudRate);

			unchecked
			{
				newtio.c_cflag &= (uint)-(uint)e_c_oflag.CSIZE;
			}

			switch (dataBits)
			{
				case 5:
					newtio.c_cflag |= (uint)e_c_oflag.CS5;
					break;

				case 6:
					newtio.c_cflag |= (uint)e_c_oflag.CS6;
					break;

				case 7:
					newtio.c_cflag |= (uint)e_c_oflag.CS6;
					break;

				case 8:
				default:
					newtio.c_cflag |= (uint)e_c_oflag.CS8;
					break;
			}

			switch (stopBits)
			{
				case StopBits.None:
					break;

				case StopBits.One:
					unchecked
					{
						newtio.c_cflag &= (uint)-(uint)e_c_oflag.CSTOPB;
					}
					break;

				case StopBits.Two:
					newtio.c_cflag |= (uint)e_c_oflag.CSTOPB;
					break;

				case StopBits.OnePointFive:
					break;
			}

			unchecked
			{
				newtio.c_iflag &= (uint)-(uint)(e_c_iflag.INPCK | e_c_iflag.ISTRIP);
			}

			switch (parity)
			{
				case Parity.None: /* None */
					newtio.c_cflag &= ~(uint)(e_c_oflag.PARENB | e_c_oflag.PARODD);
					break;

				case Parity.Odd: /* Odd */
					newtio.c_cflag |= (uint)(e_c_oflag.PARENB | e_c_oflag.PARODD);
					break;

				case Parity.Even: /* Even */
					newtio.c_cflag &= ~(uint)(e_c_oflag.PARODD);
					newtio.c_cflag |= (uint)(e_c_oflag.PARENB);
					break;

				case Parity.Mark: /* Mark */
					/* XXX unhandled */
					break;

				case Parity.Space: /* Space */
					/* XXX unhandled */
					break;
			}

			newtio.c_iflag &= ~(uint)(e_c_iflag.IXOFF | e_c_iflag.IXON);
#if CRTSCTS
			newtio.c_cflag &= ~CRTSCTS;
#endif //* def CRTSCTS */

			switch (handshake)
			{
				case Handshake.None: /* None */
					/* do nothing */
					break;

				case Handshake.RequestToSend: /* RequestToSend (RTS) */
#if CRTSCTS
				newtio.c_cflag |= CRTSCTS;
#endif //* def CRTSCTS */
					break;

				case Handshake.RequestToSendXOnXOff: /* RequestToSendXOnXOff (RTS + XON/XOFF) */
#if CRTSCTS
				newtio.c_cflag |= CRTSCTS;
#endif //* def CRTSCTS */
				/* fall through */
				case Handshake.XOnXOff: /* XOnXOff */
					newtio.c_iflag |= (uint)(e_c_iflag.IXOFF | e_c_iflag.IXON);
					break;
			}

			if (CFSetOSpeed(newtio, baudRate) < 0 || CFSetISpeed(newtio, baudRate) < 0 ||
				TCSetAttribute(fd, (uint)e_tcsetaatr.TCSANOW, newtio) < 0)
			{
				return false;
			}
			else
			{
				return true;
			}

			//return set_attributes(fd, baudRate, parity, dataBits, sb, hs);
		}
Exemple #7
0
 private static extern int tcgetattr(int fd, tDeviceInfo newtio);
		private int CFSetOSpeed(tDeviceInfo newtio, int baudRate)
		{
			newtio.c_ospeed = (uint)baudRate;
			return (int)newtio.c_ospeed;
		}
		private int TCSetAttribute(int fd, uint optional_actions, tDeviceInfo newtio)
		{
			return tcsetattr(fd, optional_actions, newtio);
		}
		private static extern int tcsetattr(int fd, uint optional_actions, tDeviceInfo newtio);
		private int TCGetAttribute(int fd, tDeviceInfo newtio)
		{
			int result = tcgetattr(fd, newtio);
			return result;
		}
		private static extern int tcgetattr(int fd, tDeviceInfo newtio);