public static IPv2ServerDevice CreateServerDevice(out int port, IEnumerable <Pv2RttRecordDesc> records, IEnumerable <Pv2RttFieldDesc> fields, out string rttFolder, uint writeRttTimeMs, byte comId = 1, byte sysId = 1) { port = GetAvailablePort(); var serverPort = PortFactory.Create($"tcp://127.0.0.1:{port}?srv=true"); serverPort.Enable(); var serverConnection = new MavlinkV2Connection(serverPort, _ => { _.RegisterMinimalDialect(); _.RegisterCommonDialect(); _.RegisterArdupilotmegaDialect(); _.RegisterIcarousDialect(); _.RegisterUavionixDialect(); }); var config = new InMemoryConfiguration(); var suffix = "PV3"; Pv2DeviceParams.SystemId.WriteToConfigValue(config, suffix, sysId); Pv2DeviceParams.ComponentId.WriteToConfigValue(config, suffix, comId); Pv2RttInterface.RecordTickTime.WriteToConfigValue(config, suffix, writeRttTimeMs); rttFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); return(new Pv2ServerDeviceBase(serverConnection, config, Array.Empty <Pv2ParamType>(), Pv2DeviceClass.PayloadSdr, Array.Empty <IWorkModeFactory>(), new ChunkFileStore(rttFolder), records, fields, suffix)); }
/// <summary> /// Load an existing serial port configuration from disk. /// </summary> /// <param name="name">name of device attached to serial port</param> /// <param name="config">serial port configuration</param> public static void Load(string name, out ISerialConfig config) { config = null; using (FileStream stream = ReadStream(name)) { config = (ISerialConfig)PortFactory.Create(PortType.Serial, stream); } }
public void AddPort(string nodeIdentifier, string portType) { this._portFactory = new PortFactory(); var port = _portFactory.GetPort(portType); port.NodeIdentifier = nodeIdentifier; this._ports.Add(port); }
/// <summary> /// Create a new serial port configuration for a given device filled with default values. /// </summary> /// <param name="name">name of device attached to serial port</param> /// <param name="config">serial port configuration</param> public static void Create(string name, out ISerialConfig config) { if (VBHelpers.Match(name.ToLower(), "com?")) { throw new ArgumentException("A valid device name must be provided. Devices cannot be named using COM device names (i.e. COM1, COM2, etc)", name); } config = (ISerialConfig)PortFactory.Create(PortType.Serial, name); }
public static PayloadV2Client CreateClient(int port, byte comId = 255, byte sysId = 255, byte targetCompId = 1, byte targetSysId = 1) { var clientPort = PortFactory.Create($"tcp://127.0.0.1:{port}"); clientPort.Enable(); var clientConnection = new MavlinkV2Connection(clientPort, _ => { _.RegisterMinimalDialect(); _.RegisterCommonDialect(); _.RegisterArdupilotmegaDialect(); _.RegisterIcarousDialect(); _.RegisterUavionixDialect(); }); var mavlinkClient = new MavlinkClient(clientConnection, new MavlinkClientIdentity { ComponentId = 255, SystemId = 255, TargetComponentId = 1, TargetSystemId = 1, }, new MavlinkClientConfig()); return(new PayloadV2Client(mavlinkClient)); }
public static IPv2ClientDevice CreateClientDevice(int port, byte comId = 255, byte sysId = 255, byte targetCompId = 1, byte targetSysId = 1) { var serverPort = PortFactory.Create($"tcp://127.0.0.1:{port}"); serverPort.Enable(); var serverConnection = new MavlinkV2Connection(serverPort, _ => { _.RegisterMinimalDialect(); _.RegisterCommonDialect(); _.RegisterArdupilotmegaDialect(); _.RegisterIcarousDialect(); _.RegisterUavionixDialect(); }); return(new Pv2ClientDeviceBase(serverConnection, new MavlinkClientIdentity { ComponentId = comId, SystemId = sysId, TargetComponentId = targetCompId, TargetSystemId = targetSysId, }, new PacketSequenceCalculator(), new Pv2CfgDescriptionEmptyStore(), new Pv2RttDescriptionEmptyStore(), new Pv2BaseDescriptionEmptyStore(), new Pv2DeviceBaseConfig(), true)); }
public static IPayloadV2Server CreateServer(out int port, byte compId = 1, byte sysId = 1) { port = GetAvailablePort(); var serverPort = PortFactory.Create($"tcp://127.0.0.1:{port}?srv=true"); serverPort.Enable(); var serverConnection = new MavlinkV2Connection(serverPort, _ => { _.RegisterMinimalDialect(); _.RegisterCommonDialect(); _.RegisterArdupilotmegaDialect(); _.RegisterIcarousDialect(); _.RegisterUavionixDialect(); }); var mavlinkServer = new MavlinkServerBase(serverConnection, new MavlinkServerIdentity { ComponentId = compId, SystemId = sysId }); mavlinkServer.Heartbeat.Set(_ => _.Autopilot = MavAutopilot.MavAutopilotGeneric); mavlinkServer.Heartbeat.Start(); return(new PayloadV2Server(mavlinkServer)); }
public void LoadConfig(string path) { StreamReader sr = new StreamReader(path); var config = (JObject)JsonConvert.DeserializeObject(sr.ReadToEnd()); sr.Close(); JToken token; if (config.TryGetValue("AGVConfig", out token)) { ISerialize serialize = new ProtoClass(); foreach (JObject t in token.Values()) { try { IPort port = new TcpPort(t.Value <string>("port")); //var test = $"HuiJinYun.Domain.Entity.Device.{t.Value<string>("type")}AGV<TState, TPosition>"; Type type = Type.GetType($"HuiJinYun.Domain.Entity.Device.{t.Value<string>("type")}AGV`2"); type = type.MakeGenericType(typeof(eHuiJinYunAGVState), typeof(eHuiJinYunStagePosition)); object[] @params = new object[] { port, serialize }; @params = @params.Concat(buildParams(type, t.Value <JObject>("options"))).ToArray <object>(); var agv = (IAGV <eHuiJinYunAGVState, eHuiJinYunStagePosition>)Activator.CreateInstance(type, @params); AGVs.Add(agv); } catch { continue; } } } if (config.TryGetValue("DeviceConfig", out token)) { ISerialize serialize = new ProtoClass(); foreach (JObject t in token.Values()) { try { var port = PortFactory.NewPort(t.Value <string>("port")); Type type = Type.GetType($"HuiJinYun.Domain.Entity.Device.{t.Value<string>("type")}Device"); var device = (PlcDeviceBase)Activator.CreateInstance(type, port, serialize); Devices.Add(((JProperty)t.Parent).Name, device); } catch (Exception ex) { continue; } } } if (config.TryGetValue("StageConfig", out token)) { foreach (var t in token.Values()) { try { List <IDevice> deviceList = new List <IDevice>(); foreach (var d in t["Device"].Values <string>()) { deviceList.Add(Devices[d]); } Type type = Type.GetType($"HuiJinYun.Domain.Entity.{((JProperty)t.Parent).Name}Stage"); var stage = (IProductionStage)Activator.CreateInstance(type, deviceList.ToArray()); Stages.Add(stage); } catch (Exception ex) { continue; } } } object[] buildParams(Type type, JObject joParams) { if (null == joParams) { return(new object[0]); } else { object[] @params = new object[joParams.Count]; List <JProperty> jpParams = new List <JProperty>(joParams.Properties()); for (var i = 0; i < jpParams.Count; i++) { @params[i] = jpParams[i].Value.Value <string>(); } return(@params); } } }
/// <summary> /// Create a new GPIB port configuration for a given device filled with default values. /// </summary> /// <param name="name">name of device attached to GPIB port</param> /// <param name="config">GPIB port configuration</param> public static void Create(string name, out IGpibConfig config) { config = (IGpibConfig)PortFactory.Create(PortType.Gpib, name); }
/// <summary> /// Create a new telnet port configuration for a given device filled with default values. /// </summary> /// <param name="name">name of device attached to telnet port</param> /// <param name="config">telnet port configuration</param> public static void Create(string name, out ITelnetConfig config) { config = (ITelnetConfig)PortFactory.Create(PortType.Telnet, name); }
/// <summary> /// Creates an ActivePort within the TQF of the given PortType and configuration provided by the given stream /// </summary> /// <param name="type">Type of ActivePort to create</param> /// <param name="stream">Configuration stream compatible with the underlying PortType</param> public static void Create(PortType type, Stream stream) { Create(PortFactory.Create(type, stream)); }
/// <summary> /// Creates an ActivePort within the TQF of the given PortType with the given name and default settings (9600 8N1) /// </summary> /// <param name="type">Type of underlying Port to associate with the ActivePort</param> /// <param name="name">Unique name for the ActivePort</param> public static void Create(PortType type, string name) { Create(PortFactory.Create(type, name)); }