public object GetConnector <T>(object instance, PortConfiguration portConfiguration)
        {
            var importer   = (RemoteImporter)instance;
            var streamName = (string)portConfiguration.Index;

            return(importer.Importer.OpenStream <T>(streamName));
        }
        /// <summary>
        /// Creates an initialized instance of the device configured with fusion and the default settings.
        /// </summary>
        public static NavioPositionDevice Initialize()
        {
            // Create device
            var device = new NavioPositionDevice();

            // Initialize message polling
            device.StartPolling();

            // Initialize port configuration
            var portConfig = new PortConfiguration();

            portConfig.IsInUbx  = true;
            portConfig.IsOutUbx = true;
            portConfig.Mode[9]  = true;
            portConfig.Mode[12] = true;
            portConfig.Mode[13] = true;
            var portResponse = device.WriteMessage(portConfig);

            // Read current software/hardware version from receiver
            device.ReadVersion();

            // Initialize polling for messages
            device.SetPollingRate(0x01, 0x02, 0x01);

            // Return initialized device
            return(device);
        }
Beispiel #3
0
 private static string AssignIndexer(PortDescription desc, PortConfiguration config)
 {
     if (desc.IsList || desc.IsDictionary)
     {
         return(config is null || config.Indexer is null ? string.Empty : config.Indexer);
     }
     return(null);
 }
 internal void ConfigureCOMPort(PortConfiguration portConfiguration)
 {
     try
     {
         myport.BaudRate     = portConfiguration.BaudRate;
         myport.Parity       = portConfiguration.Parity;
         myport.PortName     = portConfiguration.PortName;
         myport.StopBits     = portConfiguration.StopBits;
         myport.ReadTimeout  = portConfiguration.ReadTimeout;
         myport.WriteTimeout = portConfiguration.WriteTimeout;
         myport.DataBits     = portConfiguration.DataBits;
         myport.RtsEnable    = portConfiguration.Rts;
     }
     catch (Exception)
     {
     }
 }
Beispiel #5
0
        /// <summary>
        /// Open the serial port.
        /// </summary>
        Task IPort.OpenAsync(PortConfiguration configuration)
        {
            // Clean up the existing SerialPort object, if we have one.
            if (this.port != null)
            {
                this.port.Dispose();
            }
            SerialPortConfiguration config = configuration as SerialPortConfiguration;

            this.port          = new SerialPort(this.name);
            this.port.BaudRate = config.BaudRate;
            this.port.DataBits = 8;
            this.port.Parity   = Parity.None;
            this.port.StopBits = StopBits.One;
            if (config.Timeout == 0)
            {
                config.Timeout = 1000;                      // default to 1 second but allow override.
            }
            this.port.ReadTimeout = config.Timeout;

            if (this.port.IsOpen == true)
            {
                this.port.Close();
            }

/*            if (config.DataReceived != null)
 *          {
 *              this.dataReceivedCallback = config.DataReceived;
 *              this.port.DataReceived += this.DataReceived;
 *          }
 */

            this.port.Open();

            // This line must come AFTER the call to port.Open().
            // Attempting to use the BaseStream member will throw an exception otherwise.
            //
            // However, even after setting the BaseStream.ReadTimout property, calls to
            // BaseStream.ReadAsync will hang indefinitely. It turns out that you have
            // to implement the timeout yourself if you use the async approach.
            this.port.BaseStream.ReadTimeout = this.port.ReadTimeout;

            return(Task.CompletedTask);
        }
Beispiel #6
0
 public object GetConnector <T>(object instance, PortConfiguration portConfiguration) => throw new InvalidOperationException();
Beispiel #7
0
 /// <summary>
 /// Pretend to open a port.
 /// </summary>
 Task IPort.OpenAsync(PortConfiguration configuration)
 {
     return(Task.CompletedTask);
 }
Beispiel #8
0
 partial void OnPortConfigChanging(PortConfiguration value);
Beispiel #9
0
 /// <summary>
 /// Open the J2534 device.
 /// </summary>
 Task IPort.OpenAsync(PortConfiguration configuration)
 {
     throw new NotImplementedException();
 }
 public object GetConnector <T>(object instance, PortConfiguration portConfiguration)
 {
     Debug.Assert(Equals(this.OutputPorts().Single().Identifier, portConfiguration.Identifier));
     Debug.Assert(instance != null && typeof(IProducer <T>).IsAssignableFrom(instance.GetType()));
     return(instance);
 }
        /// <summary>
        /// Process Brick State
        /// </summary>
        /// <param name="brickState"></param>
        private IEnumerator<ITask> ProcessBrickState(brick.NxtBrickState brickState)
        {
            foreach (string key in brickState.Runtime.Devices.Keys)
            {
                brick.AttachRequest device = brickState.Runtime.Devices[key];
                if (device.Registration.DeviceType != LegoDeviceType.AnalogSensor
                    && device.Registration.DeviceType != LegoDeviceType.DigitalSensor)
                {
                    continue;
                }

                PortSet<DsspDefaultLookup, DsspDefaultGet> lookupPort = ServiceForwarder<PortSet<DsspDefaultLookup, DsspDefaultGet>>(device.Registration.ServiceUri);
                DsspDefaultLookup lu = new DsspDefaultLookup();
                lookupPort.Post(lu);
                yield return Arbiter.Choice(lu.ResponsePort,
                    delegate(LookupResponse luResponse)
                    {
                        foreach(PartnerType pt in luResponse.PartnerList)
                        {
                            // See if this service supports the analog sensor contract
                            if (pt.Contract == analog.Contract.Identifier)
                            {
                                // Check if we have already processed this one.
                                if (_sensorList.ContainsKey(pt.Service))
                                    break;

                                string name = device.Registration.Name;
                                string model = device.Registration.DeviceModel;
                                int hardwareIdentifier = NxtCommon.HardwareIdentifier(device.Registration.Connection.Port);

                                LogVerbose(LogGroups.Console, string.Format("Configuring {0}:{1} on {2} with analog service at {3}", model, name, hardwareIdentifier, pt.Service));
                                analog.AnalogSensorOperations sensorPort = ServiceForwarder<analog.AnalogSensorOperations>(pt.Service);
                                Activate(Arbiter.Choice(sensorPort.Subscribe(_analogSensorNotificationsPort),
                                    delegate(SubscribeResponseType response)
                                    {
                                        // Keep track of the subscription manager response
                                        // so that we can unsubscribe later.
                                        _sensorList.Add(pt.Service, response);
                                    },
                                    delegate(Fault fault)
                                    {
                                        LogError(LogGroups.Console, string.Format("Failure subscribing to {0} on port {1}.", model, hardwareIdentifier));
                                    }));

                                foreach (SensorConfiguration cfg in _state.SensorConfiguration)
                                {
                                    if (cfg.DeviceModel != model)
                                        continue;

                                    SensorRange range = new SensorRange(hardwareIdentifier, model, name, cfg.RangeName);
                                    PortConfiguration portConfig = new PortConfiguration(hardwareIdentifier, range.ContactSensorName, cfg.SuccessRangeMin, cfg.SuccessRangeMax);
                                    portConfig.AnalogSensorServiceUri = pt.Service;

                                    if (portConfig != null)
                                        _state.RuntimeConfiguration.Add(range, portConfig);
                                }
                                break;
                            }
                        }
                    },
                    delegate(Fault f) { });

            }
        }
        /// <summary>
        /// Generate a Port Configuration for the specified device.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="name"></param>
        /// <param name="hardwareIdentifier"></param>
        /// <param name="serviceUri"></param>
        /// <returns></returns>
        private PortConfiguration GeneratePortConfiguration(string model, string name, int hardwareIdentifier, string serviceUri)
        {
            PortConfiguration sensorConfig = new PortConfiguration(hardwareIdentifier, name, 0.0, 0.0);
            bool found = false;
            foreach (SensorConfiguration config in _state.SensorConfiguration)
            {
                if (config.DeviceModel != model)
                    continue;

                found = true;
                sensorConfig.SuccessRangeMin = config.SuccessRangeMin;
                sensorConfig.SuccessRangeMax = config.SuccessRangeMax;
                sensorConfig.AnalogSensorServiceUri = serviceUri;

                // If we found a name override, we are done.
                if (!string.IsNullOrEmpty(config.DeviceName) && config.DeviceName == name)
                    break;

                // otherwise, keep looking for an override.
            }

            if (!found)
                return null;

            return sensorConfig;
        }