示例#1
0
        public async void ExecuteSerialBegin_Click(object sender, EventArgs e)
        {
            OperationsPanel.Enabled  = false;
            CredentialsPanel.Enabled = false;
            Response.Text            = "Waiting for response..";
            Status.Text = "Executing..";

            Bolt myBolt = new Bolt(ApiKey.Text.Trim(), DeviceId.Text.Trim());

            BaudRates baudRate = 0;

            switch (BaudRateSel.SelectedIndex)
            {
            case 0: baudRate = BaudRates.Baud2400; break;

            case 1: baudRate = BaudRates.Baud4800; break;

            case 2: baudRate = BaudRates.Baud9600; break;

            case 3: baudRate = BaudRates.Baud19200; break;
            }

            RequestURL.Text = BuildRequestUrl("serialBegin", new List <string> {
                "baud"
            }, new List <string> {
                ((int)baudRate).ToString()
            });

            Response response = await myBolt.SerialBegin(baudRate);

            Response.Text            = response.ResponseString;
            Status.Text              = "Ready";
            OperationsPanel.Enabled  = true;
            CredentialsPanel.Enabled = true;
        }
示例#2
0
        static private BaudRates ConvertToBusiness(BaudRateFile value)
        {
            BaudRates result = new BaudRates();

            result.IdBaudRate = value.Id;
            result.Value      = value.BaudRate;

            return(result);
        }
示例#3
0
 public MainViewModel()
 {
     _Random            = new Random();
     SerialPorts        = SerialPort.GetPortNames();
     BaudRates          = new[] { 300, 600, 1200, 2400, 9600, 14400, 19200, 38400, 57600, 115200 };
     SelectedSerialPort = SerialPorts.Where(p => p == DefaultPortName).FirstOrDefault();
     SelectedBaudRate   = BaudRates.Where(r => r == DefaultBaudRate).FirstOrDefault();
     InitialiseSerialPort();
 }
示例#4
0
        public Serial(COMPorts port, DataBits dataBits, ParityBits parityBits, StopBits stopBits, BaudRates baudRate, Interrupts interrupts)
        {
            this.port       = port;
            this.dataBits   = dataBits;
            this.parityBits = parityBits;
            this.stopBits   = stopBits;
            this.baudRate   = baudRate;
            this.interrupts = interrupts;

            Init();
        }
示例#5
0
		public void SerialOpen(String portName, BaudRates baud)
		{
			BasicPortSettings portSettings = new BasicPortSettings();
			portSettings.BaudRate = baud;
			mPort = new Port(portName, portSettings);
			mPort.RThreshold = 1;
			mPort.SThreshold = 1;	// send 1 byte at a time
			mPort.InputLen = 0;
			mPort.Open();
			mPort.DataReceived +=new Port.CommEvent(mPort_DataReceived);
		}
        //private readonly ILog _log;

        protected RS232Base(string devicePort, BaudRates deviceBaudRate, Parity parity, int bits, StopBits stopBits)
        {
            try
            {
                SerialPort = new SerialPort(devicePort, (int)deviceBaudRate, parity, bits, stopBits);
                //_log = LogManager.GetLogger(GetType());
            }
            catch (Exception ex)
            {
                CallBacker.CallBackException?.Invoke(ex);
            }
        }
示例#7
0
        /// <summary>
        /// Initializes serial communication.
        /// </summary>
        /// <param name="baudRate">It is the baud rate to be set for Bolt. It can take value 2400, 4800, 9600, 19200.</param>
        /// <returns>Response object</returns>
        public async Task <Response> SerialBegin(BaudRates baudRate)
        {
            string Querry = BuildQuerry("/serialBegin?baud=" + ((int)baudRate).ToString());

            string responseString = "";
            await Task.Run(delegate
            {
                responseString = (new WebClient()).DownloadString(Querry);
            });

            return(new Response(responseString));
        }
示例#8
0
        static public bool Exists(BaudRates value)
        {
            List <BaudRateFile> data = _serializer.RecoverData();

            foreach (BaudRateFile br in data)
            {
                if (!br.Deleted && br.BaudRate == value.Value)
                {
                    return(true);
                }
            }
            return(false);
        }
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="CyrusBuilt.MonoPi.Devices.CrystalFontzSerialLCD.CrystalFontz63xSerial"/>
        /// class with the BAUD rate to negotiate with display.
        /// </summary>
        /// <param name="baud">
        /// The BAUD rate.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// BAUD rate cannot be less than 2400 or greater than 19200.
        /// </exception>
        public CrystalFontz63xSerial(BaudRates baud)
        {
            if ((Int32)baud < 2400)
            {
                throw new ArgumentOutOfRangeException("baud", "Cannot be less than 2400 baud.");
            }

            if ((Int32)baud > 19200)
            {
                throw new ArgumentOutOfRangeException("baud", "Cannot be greater than 19200 baud.");
            }
            this._baud = baud;
            this._lcd  = new Rs232SerialPort(baud);
        }
示例#10
0
        /// <summary>
        /// Change reader serial baud rate. After calling this method, you should reconnect using new baud
        /// </summary>
        /// <param name="baud"></param>
        /// <param name="forceOverNetwork"></param>
        /// <returns></returns>
        public async Task SetSerialBaudRate(BaudRates baud, bool forceOverNetwork = false)
        {
            if (!forceOverNetwork && streamFactory is NetworkStreamFactory)
            {
                throw new InvalidOperationException($"You should not change baud rate of the reader connected over the network. " +
                                                    $"While this is possible, most probably you will loose connectivity to reader" +
                                                    $"until you make manual changes on the network host");
            }
            var responses = await SendReceive(new CommandDataPacket(ReaderCommand.SetSerialBaudRate,
                                                                    (byte)baud));

            responses.First().CheckSuccess();
            streamFactory.UpdateBaudRate(baud.ToNumber());
        }
示例#11
0
        /// <summary>
        /// Init constructor.
        /// </summary>
        public DebugSerialPortSource(string name, BaudRates baudRate, Encoding encoder, Parity parity, int dataBits, StopBits stopBits)
        {
            this.name   = name;
            description = string.Format("{0} ({1} / {2}) Source", name, (int)baudRate, encoder.EncodingName);
            message     = new StringBuilder(4096);
            timer       = new Timer(InternalDataFlush);

            if (stopBits == StopBits.None)
            {
                port = new SerialPort(name, (int)baudRate, parity, dataBits);
            }
            else
            {
                port = new SerialPort(name, (int)baudRate, parity, dataBits, stopBits);
            }
            port.Encoding      = encoder;
            port.DiscardNull   = true;
            port.NewLine       = "\n";
            port.DataReceived += InternalDataReceived;
            port.Handshake     = Handshake.None;
        }
示例#12
0
 public void SerialOpen(String portName, BaudRates baud)
 {
     if (portName.StartsWith("COM"))
     {
         BasicPortSettings portSettings = new BasicPortSettings();
         portSettings.BaudRate = baud;
         mPort            = new Port(portName + ":", portSettings);
         mPort.RThreshold = 1;
         mPort.SThreshold = 1;                   // send 1 byte at a time
         mPort.InputLen   = 0;
         mPort.Open();
         mPort.DataReceived += new Port.CommEvent(mPort_DataReceived);
     }
     else
     {
         try{
             BluetoothAddress address = BluetoothAddress.Parse(portName);
             bluetoothClient = new BluetoothClient();
             bluetoothClient.SetPin(address, "0000");
             BluetoothEndPoint btep = new BluetoothEndPoint(address, BluetoothService.SerialPort, 1);
             bluetoothClient.Connect(btep);
             stream = bluetoothClient.GetStream();
             if (stream == null)
             {
                 bluetoothClient.Close();
                 bluetoothClient = null;
             }
             else
             {
                 if (stream.CanTimeout)
                 {
                     stream.WriteTimeout = 2;
                     stream.ReadTimeout  = 2;
                 }
             }
         }catch (System.IO.IOException) {
             bluetoothClient = null;
         }
     }
 }
示例#13
0
        private void Construct()
        {
            ComPort        = Properties.Settings.Default.LastUsedComPort;
            OwnPhoneNumber = "5555555555";
            BaudRate       = Properties.Settings.Default.LastUsedBaudRate.ToString();
            DataBits       = 8;
            StopBits       = 1;
            ParityBits     = "None";
            ReadTimeout    = 300;
            WriteTimeout   = 300;

            foreach (string s in System.IO.Ports.SerialPort.GetPortNames())
            {
                ComPorts.Add(s);
            }

            BaudRates.Add("4800");
            BaudRates.Add("9600");
            BaudRates.Add("19200");
            BaudRates.Add("38400");
            BaudRates.Add("57600");
        }
示例#14
0
        public static int ToNumber(this BaudRates baud)
        {
            switch (baud)
            {
            case BaudRates.Baud9600:
                return(9600);

            case BaudRates.Baud19200:
                return(19200);

            case BaudRates.Baud38400:
                return(38400);

            case BaudRates.Baud57600:
                return(57600);

            case BaudRates.Baud115200:
                return(115200);

            default:
                throw new ArgumentOutOfRangeException(nameof(baud), baud, null);
            }
        }
示例#15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UsbAdapter"/> class.
 /// </summary>
 /// <param name="port">The COM port name (e.g COM1).</param>
 /// <param name="baudRate">The serial baud rate.</param>
 public UsbAdapter(String port, BaudRates baudRate) : this(port, (int)baudRate)
 {
 }
示例#16
0
 /// <summary>
 /// Open the specified device with the specified BAUD rate.
 /// </summary>
 /// <param name="device">
 /// The path to the serial port device to open.
 /// </param>
 /// <param name="baud">
 /// The BAUD rate to negotiate.
 /// </param>
 /// <exception cref="ObjectDisposedException">
 /// This instance has been disposed and is no longer usable.
 /// </exception>
 /// <exception cref="InvalidOperationException">
 /// The serial port is already open.
 /// </exception>
 public void Open(String device, BaudRates baud)
 {
     this._device = device;
     this._baud = baud;
     this.Open();
 }
示例#17
0
        public IDataStreamFactory GetConnection(ConnectionType type = ConnectionType.Any, BaudRates baudRate = BaudRates.Baud57600)
        {
            SerialConnectionString cs = null;

            switch (type)
            {
            case ConnectionType.Any:
                cs = GetConnectionStrings().FirstOrDefault();
                break;

            case ConnectionType.Network:
            case ConnectionType.Serial:
                cs = GetConnectionStrings().FirstOrDefault(x => x.Type == type);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            if (cs != null)
            {
                return(cs.Connect());
            }

            Skip.If(true);

            return(null);
        }
示例#18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UsbAdapter"/> class.
 /// </summary>
 /// <param name="device">The USB serial device.</param>
 /// <param name="baudRate">The serial baud rate.</param>
 public UsbAdapter(UsbDevice device, BaudRates baudRate) : this(device.Port, baudRate)
 {
 }
示例#19
0
文件: GPS.cs 项目: mendhak/gpstracka
        /// <summary>
        /// Auto discover our GPS
        /// </summary>
        /// <returns>True if we have found a GPS</returns>
        private bool autodiscover()
        {
            Type searchbauds = typeof(OpenNETCF.IO.Serial.BaudRates);

            // get a list of devices
            foreach (string port in this.devices())
            {
                foreach (OpenNETCF.IO.Serial.BaudRates bauds in OpenNETCF.EnumEx.GetValues(searchbauds))
                {
                    if ((bauds >= minbaudrate) && (bauds <= maxbaudrate))
                    {
                        // initialize the port like in run proc
                        DetailedPortSettings portSettings = new HandshakeNone();
                        cp = new Port(port,portSettings);
                        cp.Settings.BaudRate = bauds;

                        cp.RThreshold=64;
                        cp.InputLen=1;
                        OnAutoDiscovery( OpenNETCF.IO.Serial.GPS.AutoDiscoverStates.Testing,port,cp.Settings.BaudRate);

                        try
                        {
                            cp.Open();
                        }
                        catch
                        {
                            OnAutoDiscovery(OpenNETCF.IO.Serial.GPS.AutoDiscoverStates.FailedToOpen,port,cp.Settings.BaudRate);
                        }

                        if (cp.IsOpen)
                        {
                            // if port open, invoke cp_DataReceived if bytes occur
                            cp.DataReceived+=new Port.CommEvent(cp_DataReceived);

                            if (state==States.Opening)
                                setstate=States.Running;

                            int cpt=0;
                            while (state==States.Running && cpt <= 100)
                            {
                                // wait 1 seconds for the sentences
                                Thread.Sleep(10);
                                cpt++;
                            }

                            if (state==States.AutoDiscovery)
                            {
                                OnAutoDiscovery(OpenNETCF.IO.Serial.GPS.AutoDiscoverStates.Opened,port,cp.Settings.BaudRate);
                                comport = port;
                                baudrate = cp.Settings.BaudRate;
                                autodiscovery=false;
                                return true;
                            }
                            else
                            {
                                cp.Close();
                                setstate=States.Opening;
                            }

                            OnAutoDiscovery(OpenNETCF.IO.Serial.GPS.AutoDiscoverStates.Failed,port,cp.Settings.BaudRate);
                        }

                        cp.Dispose();
                        cp=null;
                    }
                }
            }
            // default values
            OnAutoDiscovery(OpenNETCF.IO.Serial.GPS.AutoDiscoverStates.NoGPSDetected,comport,baudrate);
            autodiscovery=false;
            return false;
        }
示例#20
0
		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="CyrusBuilt.MonoPi.Devices.CrystalFontzSerialLCD.CrystalFontz63xSerial"/>
		/// class with the GPIO pin to control the backlight with
		/// and the BAUD rate to negotiate with the display.
		/// </summary>
		/// <param name="backlightPin">
		/// The GPIO pin to use to control the backlight.
		/// </param>
		/// <param name="baud">
		/// The BAUD rate.
		/// </param>
		/// <exception cref="ArgumentOutOfRangeException">
		/// BAUD rate cannot be less than 2400 or greater than 19200.
		/// </exception>
		public CrystalFontz63xSerial(IRaspiGpio backlightPin, BaudRates baud) {
			this._baud = baud;
			if ((Int32)baud < 2400) {
				throw new ArgumentOutOfRangeException("baud", "Cannot be less than 2400 baud.");
			}

			if ((Int32)baud > 19200) {
				throw new ArgumentOutOfRangeException("baud", "Cannot be greater than 19200 baud.");
			}
			this._lcd = new Rs232SerialPort(baud);
			this._backlightPin = backlightPin;
		}
示例#21
0
        public void SerialOpen(String portName, BaudRates baud)
        {
            if (portName.StartsWith("COM")){
                BasicPortSettings portSettings = new BasicPortSettings();
                portSettings.BaudRate = baud;
                mPort = new Port(portName+":", portSettings);
                mPort.RThreshold = 1;
                mPort.SThreshold = 1;	// send 1 byte at a time
                mPort.InputLen = 0;
                mPort.Open();
                mPort.DataReceived +=new Port.CommEvent(mPort_DataReceived);
            }else{

                try{
                    BluetoothAddress address = BluetoothAddress.Parse(portName);
                    bluetoothClient = new BluetoothClient();
                    bluetoothClient.SetPin(address, "0000");
                    BluetoothEndPoint btep = new BluetoothEndPoint(address, BluetoothService.SerialPort, 1);
                    bluetoothClient.Connect(btep);
                    stream = bluetoothClient.GetStream();
                    if (stream == null){
                        bluetoothClient.Close();
                        bluetoothClient = null;
                    }else{
                        if (stream.CanTimeout){
                            stream.WriteTimeout = 2;
                            stream.ReadTimeout = 2;
                        }
                    }
                }catch(System.IO.IOException){
                    bluetoothClient = null;
                }

            }
        }
示例#22
0
 /// <summary>
 /// Sets the USB adapter serial baud rate.
 /// </summary>
 /// <param name="rate">The rate.</param>
 public ITranscodingBuilder WithBaudRate(BaudRates rate)
 {
     return(WithBaudRate((int)rate));
 }
示例#23
0
 public SerialPortDataSource(string sourceName, BaudRates baudRate, PInvokeStopBits stopBits)
 {
     SourceName = sourceName;
     BaudRate   = baudRate;
     StopBits   = stopBits;
 }
示例#24
0
        public Serial(COMPorts port, DataBits dataBits, ParityBits parityBits, StopBits stopBits, BaudRates baudRate, Interrupts interrupts)
        {
            this.port = port;
            this.dataBits = dataBits;
            this.parityBits = parityBits;
            this.stopBits = stopBits;
            this.baudRate = baudRate;
            this.interrupts = interrupts;

            Init();
        }
        /// <summary>
        /// Creates a serial connection and sets up the class to begin a connection
        /// </summary>
        /// <param name="ComPort"></param>
        /// <param name="Address"></param>
        /// <param name="BaudRate"></param>
        /// <param name="DataPackageChunkSize"></param>
        public FingerPrintScaner(string ComPort, uint?Address = null, BaudRates BaudRate = BaudRates.BaudRateOf57600, PackageLength DataPackageChunkSize = PackageLength.LengthOf128, bool OpenNow = true)
        {
            if (!Enum.IsDefined(typeof(BaudRates), BaudRate))
            {
                throw new Exception("BaudRate is not a valid baudrate!");
            }
            if (!Enum.IsDefined(typeof(PackageLength), DataPackageChunkSize))
            {
                throw new Exception("The chunk size is not a valid max chunk size for the device!");
            }
            int BaudRateValue = DefaultBaudRate;

            switch (BaudRate)
            {
            case BaudRates.BaudRateOf9600:
                BaudRateValue = 9600;
                BaudRate      = BaudRates.BaudRateOf9600;
                break;

            case BaudRates.BaudRateOf19200:
                BaudRateValue = 19200;
                BaudRate      = BaudRates.BaudRateOf19200;
                break;

            case BaudRates.BaudRateOf28800:
                BaudRateValue = 28800;
                BaudRate      = BaudRates.BaudRateOf28800;
                break;

            case BaudRates.BaudRateOf38400:
                BaudRateValue = 38400;
                BaudRate      = BaudRates.BaudRateOf38400;
                break;

            case BaudRates.BaudRateOf48000:
                BaudRateValue = 48000;
                BaudRate      = BaudRates.BaudRateOf48000;
                break;

            case BaudRates.BaudRateOf57600:
                BaudRateValue = 57600;
                BaudRate      = BaudRates.BaudRateOf57600;
                break;

            case BaudRates.BaudRateOf67200:
                BaudRateValue = 67200;
                BaudRate      = BaudRates.BaudRateOf67200;
                break;

            case BaudRates.BaudRateOf76800:
                BaudRateValue = 76800;
                BaudRate      = BaudRates.BaudRateOf76800;
                break;

            case BaudRates.BaudRateOf86400:
                BaudRateValue = 86400;
                BaudRate      = BaudRates.BaudRateOf86400;
                break;

            case BaudRates.BaudRateOf96000:
                BaudRateValue = 96000;
                BaudRate      = BaudRates.BaudRateOf96000;
                break;

            case BaudRates.BaudRateOf105600:
                BaudRateValue = 105600;
                BaudRate      = BaudRates.BaudRateOf105600;
                break;

            case BaudRates.BaudRateOf115200:
                BaudRateValue = 115200;
                BaudRate      = BaudRates.BaudRateOf115200;
                break;
            }

            if (Address != null)
            {
                this.AddressBytes = BitConverterHelpers.GetBytes32(Address.Value);
            }

            this.DataPackageChunkSize = DataPackageChunkSize;
            SerialPort = new SerialPort(ComPort, BaudRateValue, Parity.None, 8, StopBits.One);

            if (OpenNow)
            {
                SerialPort.Open();
            }
        }
        /// <summary>
        /// Sets the systems baud rate then sets
        /// </summary>
        /// <param name="BaudRate"></param>
        /// <returns></returns>
        public BasicCommandReturn SetSystemBaudRate(BaudRates BaudRate)
        {
            if (!Enum.IsDefined(typeof(BaudRates), BaudRate))
            {
                throw new Exception("BaudRate is not a valid baudrate!");
            }
            this.BaudRate = BaudRate;
            BasicCommandReturn Return = SetSystemParam(SystemParam.BaudRate, (byte)BaudRate);

            if (Return.Status != Errors.Success || !Return.Valid)
            {
                return(Return);
            }
            int BaudRateValue = DefaultBaudRate;

            switch (BaudRate)
            {
            case BaudRates.BaudRateOf9600:
                BaudRateValue = 9600;
                BaudRate      = BaudRates.BaudRateOf9600;
                break;

            case BaudRates.BaudRateOf19200:
                BaudRateValue = 19200;
                BaudRate      = BaudRates.BaudRateOf19200;
                break;

            case BaudRates.BaudRateOf28800:
                BaudRateValue = 28800;
                BaudRate      = BaudRates.BaudRateOf28800;
                break;

            case BaudRates.BaudRateOf38400:
                BaudRateValue = 38400;
                BaudRate      = BaudRates.BaudRateOf38400;
                break;

            case BaudRates.BaudRateOf48000:
                BaudRateValue = 48000;
                BaudRate      = BaudRates.BaudRateOf48000;
                break;

            case BaudRates.BaudRateOf57600:
                BaudRateValue = 57600;
                BaudRate      = BaudRates.BaudRateOf57600;
                break;

            case BaudRates.BaudRateOf67200:
                BaudRateValue = 67200;
                BaudRate      = BaudRates.BaudRateOf67200;
                break;

            case BaudRates.BaudRateOf76800:
                BaudRateValue = 76800;
                BaudRate      = BaudRates.BaudRateOf76800;
                break;

            case BaudRates.BaudRateOf86400:
                BaudRateValue = 86400;
                BaudRate      = BaudRates.BaudRateOf86400;
                break;

            case BaudRates.BaudRateOf96000:
                BaudRateValue = 96000;
                BaudRate      = BaudRates.BaudRateOf96000;
                break;

            case BaudRates.BaudRateOf105600:
                BaudRateValue = 105600;
                BaudRate      = BaudRates.BaudRateOf105600;
                break;

            case BaudRates.BaudRateOf115200:
                BaudRateValue = 115200;
                BaudRate      = BaudRates.BaudRateOf115200;
                break;
            }
            SerialPort.Close();
            SerialPort.BaudRate = BaudRateValue;
            SerialPort.Open();
            return(Return);
        }
示例#27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.Serial.Rs232SerialPort"/>
 /// class with the device path and the BAUD rate to negotiate.
 /// </summary>
 /// <param name="device">
 /// The device path to open (default is "/dev/ttyAMA0").
 /// </param>
 /// <param name='baud'>
 /// The BAUD rate to negotiate (default is <see cref="BaudRates.Baud9600"/>,
 /// which is 9600 BAUD).
 /// </param>
 public Rs232SerialPort(String device, BaudRates baud)
 {
     this._device = device;
     this._baud   = baud;
 }
示例#28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.Serial.Rs232SerialPort"/>
 /// class with the BAUD rate to negotiate.
 /// </summary>
 /// <param name="baud">
 /// The BAUD rate to negotiate (default is <see cref="BaudRates.Baud9600"/>,
 /// which is 9600 BAUD).
 /// </param>
 public Rs232SerialPort(BaudRates baud)
 {
     this._baud = baud;
 }
示例#29
0
 /// <summary>
 /// Open the specified device with the specified BAUD rate.
 /// </summary>
 /// <param name="device">
 /// The path to the serial port device to open.
 /// </param>
 /// <param name="baud">
 /// The BAUD rate to negotiate.
 /// </param>
 /// <exception cref="ObjectDisposedException">
 /// This instance has been disposed and is no longer usable.
 /// </exception>
 /// <exception cref="InvalidOperationException">
 /// The serial port is already open.
 /// </exception>
 public void Open(String device, BaudRates baud)
 {
     this._device = device;
     this._baud   = baud;
     this.Open();
 }
示例#30
0
 protected RS232Base(string devicePort, BaudRates deviceBaudRate, Parity parity, int bits, StopBits stopBits)
 {
     SerialPort = new SerialPort(devicePort, (int)deviceBaudRate, parity, bits, stopBits);
     _log       = LogManager.GetLogger(GetType());
 }
示例#31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.Serial.Rs232SerialPort"/>
 /// class with the BAUD rate to negotiate.
 /// </summary>
 /// <param name="baud">
 /// The BAUD rate to negotiate (default is <see cref="BaudRates.Baud9600"/>,
 /// which is 9600 BAUD).
 /// </param>
 public Rs232SerialPort(BaudRates baud)
 {
     this._baud = baud;
 }
示例#32
0
文件: Roomba.cs 项目: zivanov/iRobot
        /// <summary>
        /// Sets the baud rate in bits per second(bps) at which SCI
        /// commands and data are sent according to the baud code sent 
        /// in the data byte. The default baud rate at power up is 57600 
        /// bps. (See Serial Port Settings, above.) Once the baud rate is 
        /// changed, it will persist until Roomba is power cycled by removing
        /// the battery(or until the battery voltage falls below the minimum
        /// required for processor operation). You must wait 100ms after
        /// sending this command before sending additional commands
        /// at the new baud rate.The SCI must be in passive, safe, or full
        /// mode to accept this command.This command puts the SCI in 
        /// passive mode.
        /// </summary>
        public void Baud(BaudRates baudRate)
        {

            this.commandQueue.PutToQue(new byte[] { (byte)RoombaOpcodes.BAUD, (byte)baudRate });
        }
示例#33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.Serial.Rs232SerialPort"/>
 /// class with the device path and the BAUD rate to negotiate.
 /// </summary>
 /// <param name="device">
 /// The device path to open (default is "/dev/ttyAMA0").
 /// </param>
 /// <param name='baud'>
 /// The BAUD rate to negotiate (default is <see cref="BaudRates.Baud9600"/>,
 /// which is 9600 BAUD).
 /// </param>
 public Rs232SerialPort(String device, BaudRates baud)
 {
     this._device = device;
     this._baud = baud;
 }
示例#34
0
        // private Stream theBaseStream;

        public SafeSerialPort(string portName, BaudRates baudRate, DataBits dataBits, Parity parity, StopBits stopBits)
            : base(portName, (int)baudRate, parity, (int)dataBits, stopBits)
        {
            // SerialPort.DataBits
        }
        /// <summary>
        /// Initializes a new instances of SerialPortSelectorViewModel.
        /// </summary>
        /// <param name="prompt">The prompt to display in the port selection area.</param>
        /// <param name="availablePorts">The available ports.</param>
        /// <param name="disabledPorts">Non-selectable ports.</param>
        /// <param name="selectedSerialPort">The currently selected port.</param>
        /// <param name="baudRates">Available baud rates to choose from.</param>
        /// <param name="defaultBaudRate">The default baud rate.</param>
        /// <param name="checkPortAvailability">If <c>true</c>, check the port to see if it is already in use before adding it to the selection list.</param>
        /// <param name="inclusionFilter">If <c>null</c> or it returns <c>true</c>, ports from all available ports are included.</param>
        public SerialPortSelectorViewModel(string prompt, IEnumerable <string> availablePorts, IEnumerable <string> disabledPorts, string selectedSerialPort, IEnumerable <int> baudRates, int defaultBaudRate, bool checkPortAvailability, Predicate <IConnection> inclusionFilter)
        {
            InclusionFilter = inclusionFilter;
            if (!string.IsNullOrWhiteSpace(prompt))
            {
                Prompt = prompt;
            }
            else
            {
                Prompt = Resources.Strings.SelectSerialPortDialog_Message;
            }
            if (baudRates == null)
            {
                BaudRates = new ObservableCollection <BaudRateViewModel>(new[] { new BaudRateViewModel(defaultBaudRate) });
            }
            else
            {
                BaudRates = new ObservableCollection <BaudRateViewModel>(baudRates.Select(r => new BaudRateViewModel(r)));
            }
            var ports = availablePorts;

            if ((ports == null) || !ports.Any())
            {
                ports = inclusionFilter == null ? SerialPortConnection.AvailablePorts : SerialPortConnection.GetAvailablePorts(inclusionFilter);
            }
            if (ports != null)
            {
                AvailableSerialPorts = new ObservableCollection <SerialPortViewModel>(ports.OrderBy(p => p).Select(p => new SerialPortViewModel(p)));
            }
            else
            {
                AvailableSerialPorts = new ObservableCollection <SerialPortViewModel>();
            }
            if (disabledPorts == null)
            {
                DisabledSerialPorts = new ObservableCollection <string>();
            }
            else
            {
                DisabledSerialPorts = new ObservableCollection <string>(disabledPorts);
            }
            if (checkPortAvailability)
            {
                var portsInUse = INTV.Shared.Model.Device.SerialPortConnection.PortsInUse;
                foreach (var portInUse in portsInUse.Where(p => (InclusionFilter == null) || InclusionFilter(Connection.CreatePseudoConnection(p, ConnectionType.Serial))))
                {
                    DisabledSerialPorts.Add(portInUse);
                }
            }
            foreach (var disabledPort in DisabledSerialPorts.Where(p => (InclusionFilter == null) || InclusionFilter(Connection.CreatePseudoConnection(p, ConnectionType.Serial))).OrderBy(p => p).Reverse())
            {
                var viewModel = AvailableSerialPorts.FirstOrDefault(p => p.PortName == disabledPort);
                if (viewModel == null)
                {
                    viewModel = new SerialPortViewModel(disabledPort, false);
                }
                else
                {
                    viewModel.IsSelectable = false;
                    AvailableSerialPorts.Remove(viewModel);
                }
                if (AvailableSerialPorts.Count == 0)
                {
                    AvailableSerialPorts.Add(viewModel);
                }
                else
                {
                    AvailableSerialPorts.Insert(0, viewModel);
                }
            }
            _selectedSerialPort          = selectedSerialPort;
            _selectedSerialPortViewModel = AvailableSerialPorts.FirstOrDefault(p => p.PortName == _selectedSerialPort);
            DefaultBaudRate            = defaultBaudRate;
            _selectedBaudRate          = defaultBaudRate;
            _selectedBaudRateViewModel = BaudRates.FirstOrDefault(b => b.BaudRate == defaultBaudRate);
            INTV.Shared.Interop.DeviceManagement.DeviceChange.DeviceAdded   += DeviceAdded;
            INTV.Shared.Interop.DeviceManagement.DeviceChange.DeviceRemoved += DeviceRemoved;
        }
示例#36
0
 public Rs232Impl(string devicePort, BaudRates deviceBaudRate, Parity parity, int bits, StopBits stopBits) : base(devicePort, deviceBaudRate, parity, bits, stopBits)
 {
 }
示例#37
0
 public SerialPort(string port, BaudRates baudRate, Parities parity, DataSizes dataBits, StopSizes stopBits)
 {
     this.ComPort = port;
     this.BaudRate = baudRate;
     this.Parity = parity;
     this.DataBits = dataBits;
     this.StopBits = stopBits;
 }
示例#38
0
 public SerialPortDataSource(string sourceName, BaudRates baudRate)
     : this(sourceName, baudRate, PInvokeStopBits.One)
 {
 }
示例#39
0
 static private BaudRateFile ConvertToFile(BaudRates value)
 {
     return(new BaudRateFile(value));
 }