public void ClientAndServerCommunication() { using var runtime = new Runtime(new RuntimeConfig { NumCoreThreads = 2 }); var map = new DeviceMap(); map.AddEndpoint(UNIT_ID, new WriteHandler(), new DatabaseUpdate((db) => { for (ushort i = 0; i < NUM_POINTS; ++i) { db.AddCoil(i, false); db.AddDiscreteInput(i, false); db.AddHoldingRegister(i, 0); db.AddInputRegister(i, 0); } })); var server = Server.CreateTcpServer(runtime, ENDPOINT, 100, map); var client = Channel.CreateTcpClient(runtime, ENDPOINT, 10); // set a unique pattern to test reads server.Update(UNIT_ID, new DatabaseUpdate(db => { db.UpdateDiscreteInput(3, true); db.UpdateInputRegister(4, 42); })); TestReadDiscreteInputs(client); TestReadInputRegisters(client); TestWriteSingleCoil(client); TestWriteSingleRegister(client); TestWriteMultipeCoils(client); TestWriteMultipeRegisters(client); }
public DataToSend Processing(DataToSend inputData) { ISocketService socketService = new SocketService(); DataToSend outputData = new DataToSend(); LoginMap loginMap = new LoginMap(); DeviceMap deviceMap = new DeviceMap(); AccountMap accountMap = new AccountMap(); RegistrationMap registrationMap = new RegistrationMap(); if (inputData.Action == MessageSocketData.SocketObj.Action.Login) { Console.WriteLine("Login..."); LoginDTO loginDTO = loginMap.MapTo(inputData.FirstObject as LoginSocket); DeviceDTO deviceDTO = deviceMap.MapTo(inputData.SecondObject as DeviceSocket); AccountDTO accountDTO = new AccountDTO(); accountDTO = socketService.CheckUser(loginDTO, deviceDTO); outputData.FirstObject = accountMap.MapFrom(accountDTO); } if (inputData.Action == MessageSocketData.SocketObj.Action.Registration) { Console.WriteLine("Registration..."); RegistrationDTO registrationDTO = registrationMap.MapTo(inputData.FirstObject as RegistrationSocket); bool answer = socketService.GetRegistration(registrationDTO); outputData.Boolean = answer; } return(outputData); }
public void Merge(JObject payload, DeviceMap map, string deviceId) { var template = GetTemplate(map); Merge(payload, template, deviceId); Merge(payload, map.Parameters, deviceId); }
private Dictionary <string, string> GetTemplate(DeviceMap map) { var template = _templates.FirstOrDefault(x => string.Equals(x.Type, map.Type, StringComparison.InvariantCultureIgnoreCase) && string.Equals(x.Class, map.Class, StringComparison.InvariantCultureIgnoreCase)) ?? _templates.FirstOrDefault(x => string.Equals(x.Type, map.Type, StringComparison.InvariantCultureIgnoreCase)); return(template?.Parameters); }
private async void RemoteSystemWatcher_RemoteSystemAdded(RemoteSystemWatcher sender, RemoteSystemAddedEventArgs args) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { _progressRing.IsActive = true; RemoteSystems.Add(args.RemoteSystem); DeviceMap.Add(args.RemoteSystem.Id, args.RemoteSystem); }); }
private static Server CreateTlsServer(Runtime runtime, DeviceMap map, TlsServerConfig tlsConfig) { // ANCHOR: tls_server_create var decodeLevel = new DecodeLevel(); var server = Server.CreateTls(runtime, "127.0.0.1:802", 10, map, tlsConfig, new AuthorizationHandler(), decodeLevel); // ANCHOR_END: tls_server_create return(server); }
private static Server CreateRtuServer(Runtime runtime, DeviceMap map) { // ANCHOR: rtu_server_create var decodeLevel = new DecodeLevel(); var server = Server.CreateRtu(runtime, "/dev/ttySIM1", new SerialPortSettings(), map, decodeLevel); // ANCHOR_END: rtu_server_create return(server); }
private static Server CreateTcpServer(Runtime runtime, DeviceMap map) { // ANCHOR: tcp_server_create var decodeLevel = new DecodeLevel(); var server = Server.CreateTcp(runtime, "127.0.0.1:502", 100, map, decodeLevel); // ANCHOR_END: tcp_server_create return(server); }
void Miner_WorkAccepted(IPool arg1, IPoolWork arg2, IMiningDevice arg3) { this.UpdateHashrate(arg1); MiningDeviceData data; if (DeviceMap.TryGetValue(arg3, out data)) { data.UpdatedHashRate(arg3); } }
void Miner_WorkRejected(IPool arg1, IPoolWork arg2, IMiningDevice arg3, IShareResponse arg4) { this.UpdateHashrate(arg1); MiningDeviceData data; if (DeviceMap.TryGetValue(arg3, out data)) { data.UpdatedHashRate(arg3); } }
static void SA_DeviceMapUpdatedEvent(object sender, DeviceMap e) { if (offlineMode) { return; } Debug.WriteLine("device map updated event"); //this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => //{ ////Clean up existing //this.txtNW.Text = string.Empty; //this.txtNE.Text = string.Empty; //this.txtSW.Text = string.Empty; //this.txtSE.Text = string.Empty; //this.txtE.Text = string.Empty; // this.txtW.Text = string.Empty; // //Update the Device Map Display // for (int i = 0; i < e.NW.Count; i++) // { // this.txtNW.Text += e.NW[i]; // if ((e.NW.Count > 1) && (i >= 0)) this.txtNW.Text += " "; // } // for (int i = 0; i < e.NE.Count; i++) // { // this.txtNE.Text += e.NE[i]; // if ((e.NE.Count > 1) && (i >= 0)) this.txtNE.Text += " "; // } // for (int i = 0; i < e.E.Count; i++) // { // this.txtE.Text += e.E[i]; // if ((e.E.Count > 1) && (i >= 0)) this.txtE.Text += " "; // } // for (int i = 0; i < e.SW.Count; i++) // { // this.txtSW.Text += e.SW[i]; // if ((e.SW.Count > 1) && (i >= 0)) this.txtSW.Text += " "; // } // for (int i = 0; i < e.SE.Count; i++) // { // this.txtSE.Text += e.SE[i]; // if ((e.SE.Count > 1) && (i >= 0)) this.txtSE.Text += " "; // } // for (int i = 0; i < e.W.Count; i++) // { // this.txtW.Text += e.W[i]; // if ((e.W.Count > 1) && (i >= 0)) this.txtW.Text += " "; // } //}); }
public void OnBackButton() { if (!DeviceManager.Instance.isValidScheme) { ErrorPopup.Instance.Show("Error!!\n\n<size=50>wrong controller scheme pair</size>"); return; } DeviceMap.SavePlayerDevice(); SceneManager.LoadScene("MainMenuScene"); }
private async void RemoteSystemWatcher_RemoteSystemRemoved(RemoteSystemWatcher sender, RemoteSystemRemovedEventArgs args) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { _progressRing.IsActive = true; if (DeviceMap.ContainsKey(args.RemoteSystemId)) { RemoteSystems.Remove(DeviceMap[args.RemoteSystemId]); DeviceMap.Remove(args.RemoteSystemId); } }); }
/// <summary> /// Initializes a new instance of the <see cref="AppiumConfig"/> class. /// Configuration method for wiring up the information needed for the appium drivers and application /// </summary> /// <param name="deviceName">Name of the device</param> public AppiumConfig(string deviceName = null) { operatingSystem = Environment.OSVersion; platform = operatingSystem.Platform; buildDir = AppDomain.CurrentDomain.BaseDirectory; solutionDir = Directory.GetParent(buildDir).Parent.Parent.Parent.FullName; DeviceMap = GetMap.Get(devicesDir, deviceName).Map; appPath = SetAppPath.Get(DeviceMap).AppPath; DeviceMap.Add("app", appPath); }
private void RemoveDevice(object obj) { Tuple <IMiningDeviceManager, IMiningDevice> t = obj as Tuple <IMiningDeviceManager, IMiningDevice>; MiningDeviceData data; if (DeviceMap.TryGetValue(t.Item2, out data)) { data.Done(); Devices.Remove(data); DeviceMap.Remove(t.Item2); } }
// ANCHOR_END: auth_handler static void Main(string[] args) { // initialize logging with the default configuration Logging.Configure( new LoggingConfig(), new ConsoleLogger() ); // initialize the runtime var runtime = new Runtime(new RuntimeConfig { NumCoreThreads = 4 }); // create the device map // ANCHOR: device_map_init var map = new DeviceMap(); map.AddEndpoint(1, new WriteHandler(), db => { for (ushort i = 0; i < 10; ++i) { db.AddCoil(i, false); db.AddDiscreteInput(i, false); db.AddHoldingRegister(i, 0); db.AddInputRegister(i, 0); } }); // ANCHOR_END: device_map_init if (args.Length != 1) { Console.WriteLine("you must specify a transport type"); Console.WriteLine("usage: server_example <channel> (tcp, rtu, tls-ca, tls-self-signed)"); Environment.Exit(-1); } // create the TCP server var server = CreateServer(args[0], runtime, map); try { RunServer(server); } finally { runtime.Shutdown(); } }
static void Main(string[] args) { Logging.SetMaxLogLevel(LogLevel.Info); Logging.SetHandler(new LogHandler()); using var runtime = new Runtime(new RuntimeConfig { NumCoreThreads = 1 }); var map = new DeviceMap(); map.AddEndpoint(1, new WriteHandler(), new DatabaseUpdate((db) => { for (ushort i = 0; i < 10; ++i) { db.AddCoil(i, false); db.AddDiscreteInput(i, false); db.AddHoldingRegister(i, 0); db.AddInputRegister(i, 0); } })); var server = Server.CreateTcpServer(runtime, "127.0.0.1:502", 10, map); ushort registerValue = 0; bool bitValue = false; while (true) { server.Update(1, new DatabaseUpdate((db) => { registerValue += 1; bitValue = !bitValue; for (ushort i = 0; i < 10; ++i) { db.UpdateDiscreteInput(i, bitValue); db.UpdateInputRegister(i, registerValue); } })); Thread.Sleep(1000); } }
private static Server CreateServer(string type, Runtime runtime, DeviceMap map) { switch (type) { case "tcp": return(CreateTcpServer(runtime, map)); case "rtu": return(CreateRtuServer(runtime, map)); case "tls-ca": return(CreateTlsServer(runtime, map, GetCaTlsConfig())); case "tls-self-signed": return(CreateTlsServer(runtime, map, GetSelfSignedTlsConfig())); default: Console.WriteLine($"unknown server type: {type}"); Environment.Exit(-1); return(null); } }
private void UpdateDevices(object obj) { Tuple <IMiningDeviceManager, IMiningDevice> t = obj as Tuple <IMiningDeviceManager, IMiningDevice>; var arg1 = t.Item1; var arg2 = t.Item2; if (arg1 != null && arg1.Devices != null) { if (Devices.Count != arg1.Devices.Count() - 1) { foreach (IMiningDevice d in arg1.Devices) { if (!DeviceMap.ContainsKey(d)) { MiningDeviceData data = new MiningDeviceData(d); Devices.Add(data); DeviceMap.Add(d, data); } } } else if (arg2 != null) { if (!DeviceMap.ContainsKey(arg2)) { MiningDeviceData data = new MiningDeviceData(arg2); Devices.Add(data); DeviceMap.Add(arg2, data); } } } }
public frmDeviceMapManage(DeviceMap obj) { InitializeComponent(); CurrentDeviceMap = obj; }
static void SA_DeviceMapUpdatedEvent(object sender, DeviceMap e) { if (offlineMode) return; Debug.WriteLine("device map updated event"); //this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => //{ ////Clean up existing //this.txtNW.Text = string.Empty; //this.txtNE.Text = string.Empty; //this.txtSW.Text = string.Empty; //this.txtSE.Text = string.Empty; //this.txtE.Text = string.Empty; // this.txtW.Text = string.Empty; // //Update the Device Map Display // for (int i = 0; i < e.NW.Count; i++) // { // this.txtNW.Text += e.NW[i]; // if ((e.NW.Count > 1) && (i >= 0)) this.txtNW.Text += " "; // } // for (int i = 0; i < e.NE.Count; i++) // { // this.txtNE.Text += e.NE[i]; // if ((e.NE.Count > 1) && (i >= 0)) this.txtNE.Text += " "; // } // for (int i = 0; i < e.E.Count; i++) // { // this.txtE.Text += e.E[i]; // if ((e.E.Count > 1) && (i >= 0)) this.txtE.Text += " "; // } // for (int i = 0; i < e.SW.Count; i++) // { // this.txtSW.Text += e.SW[i]; // if ((e.SW.Count > 1) && (i >= 0)) this.txtSW.Text += " "; // } // for (int i = 0; i < e.SE.Count; i++) // { // this.txtSE.Text += e.SE[i]; // if ((e.SE.Count > 1) && (i >= 0)) this.txtSE.Text += " "; // } // for (int i = 0; i < e.W.Count; i++) // { // this.txtW.Text += e.W[i]; // if ((e.W.Count > 1) && (i >= 0)) this.txtW.Text += " "; // } //}); }