Ejemplo n.º 1
0
        // set the comm parms ... can only be done if port is not open -- silently fails if port is open (fixme -- add some error checking)
        //
        public void setCommParms(int baudrate, Parity p, DataBits data, StopBits stop, HandshakeBits h)
        {
            if (commPort.IsOpen)
            {
                return;                                // bail out if it's already open
            }
            commPort.BaudRate = baudrate;

            switch (p)
            {
            case Parity.NONE:
                commPort.Parity = System.IO.Ports.Parity.None;
                break;

            case Parity.ODD:
                commPort.Parity = System.IO.Ports.Parity.Odd;
                break;

            case Parity.EVEN:
                commPort.Parity = System.IO.Ports.Parity.Even;
                break;

            case Parity.MARK:
                commPort.Parity = System.IO.Ports.Parity.Mark;
                break;

            case Parity.SPACE:
                commPort.Parity = System.IO.Ports.Parity.Space;
                break;

            default:
                commPort.Parity = System.IO.Ports.Parity.None;
                break;
            }

            switch (stop)
            {
            case StopBits.ONE:
                commPort.StopBits = System.IO.Ports.StopBits.One;
                break;

            case StopBits.ONE_AND_HALF:
                commPort.StopBits = System.IO.Ports.StopBits.OnePointFive;
                break;

            case StopBits.TWO:
                commPort.StopBits = System.IO.Ports.StopBits.Two;
                break;

            default:
                commPort.StopBits = System.IO.Ports.StopBits.One;
                break;
            }

            switch (data)
            {
            case DataBits.EIGHT:
                commPort.DataBits = 8;
                break;

            case DataBits.SEVEN:
                commPort.DataBits = 7;
                break;

            case DataBits.SIX:
                commPort.DataBits = 6;
                break;

            default:
                commPort.DataBits = 8;
                break;
            }

            switch (h)
            {
            case HandshakeBits.RTS:
                commPort.Handshake = Handshake.RequestToSend;
                break;

            case HandshakeBits.XOnXOff:
                commPort.Handshake = Handshake.XOnXOff;
                break;

            case HandshakeBits.None:
                commPort.Handshake = Handshake.None;
                break;
            }
        }
Ejemplo n.º 2
0
        // set the comm parms ... can only be done if port is not open -- silently fails if port is open (fixme -- add some error checking) 
		// 
		public void setCommParms(int baudrate, Parity p, DataBits data, StopBits stop, HandshakeBits h)  
		{ 
			if ( commPort.IsOpen ) return; // bail out if it's already open 
			
			commPort.BaudRate = baudrate; 
			
			switch ( p ) 
			{ 
				case Parity.NONE: 
					commPort.Parity = System.IO.Ports.Parity.None; 
					break; 
				case Parity.ODD:
                    commPort.Parity = System.IO.Ports.Parity.Odd; 
					break; 
				case Parity.EVEN:
                    commPort.Parity = System.IO.Ports.Parity.Even; 
					break; 
				case Parity.MARK:
                    commPort.Parity = System.IO.Ports.Parity.Mark; 
					break; 
				case Parity.SPACE:
                    commPort.Parity = System.IO.Ports.Parity.Space; 
					break; 
				default:
                    commPort.Parity = System.IO.Ports.Parity.None; 
					break; 
			}
									
			switch ( stop ) 
			{
				case StopBits.ONE:
                    commPort.StopBits = System.IO.Ports.StopBits.One;  
					break; 
				case StopBits.ONE_AND_HALF:
                    commPort.StopBits = System.IO.Ports.StopBits.OnePointFive; 
					break; 
				case StopBits.TWO:
                    commPort.StopBits = System.IO.Ports.StopBits.Two; 
					break; 
				default:
                    commPort.StopBits = System.IO.Ports.StopBits.One; 
					break; 
			}
			
			switch ( data ) 
			{
				case DataBits.EIGHT: 
					commPort.DataBits = 8; 
					break;
				case DataBits.SEVEN:
					commPort.DataBits = 7; 
					break; 
				case DataBits.SIX: 
					commPort.DataBits = 6; 
					break; 
				default: 
					commPort.DataBits = 8; 
					break; 
			}

            switch (h)
            {
                case HandshakeBits.RTS:
                    commPort.Handshake = Handshake.RequestToSend;
                    break;

                case HandshakeBits.XOnXOff:
                    commPort.Handshake = Handshake.XOnXOff;
                    break;

                case HandshakeBits.None:
                    commPort.Handshake = Handshake.None;
                    break;
            }
		}