private void listBoxDetectedSystems_SelectedIndexChanged(object sender, EventArgs e) { if (listBoxDetectedSystems.SelectedIndex != -1 && listBoxDetectedSystems.Items.Count > listBoxDetectedSystems.SelectedIndex) { var system_info = listBoxDetectedSystems.Items[listBoxDetectedSystems.SelectedIndex]; if (system_info is EthSystemDiscoverer.SystemInfo) { EthSystemDiscoverer.SystemInfo eth_system_info = system_info as EthSystemDiscoverer.SystemInfo; txtDeviceIP.Text = eth_system_info.IPAddress.ToString(); } else if (system_info is SerSystemDiscoverer.SystemInfo) { SerSystemDiscoverer.SystemInfo ser_system_info = system_info as SerSystemDiscoverer.SystemInfo; txtDeviceIP.Text = ser_system_info.PortName; } btnConnect.Enabled = (_connector != null && !_connector.IsConnected) || (_connector == null); } else { btnConnect.Enabled = false; } }
private void OnEthSystemDiscovered(EthSystemDiscoverer.SystemInfo systemInfo) { _syncContext.Post( new SendOrPostCallback( delegate { listBoxDetectedSystems.Items.Add(systemInfo); }), null); }
private void listBoxDetectedSystems_SelectedIndexChanged(object sender, EventArgs e) { if (listBoxDetectedSystems.SelectedIndex != -1 && listBoxDetectedSystems.Items.Count > listBoxDetectedSystems.SelectedIndex) { var system_info = listBoxDetectedSystems.Items[listBoxDetectedSystems.SelectedIndex]; if (system_info is EthSystemDiscoverer.SystemInfo) { EthSystemDiscoverer.SystemInfo eth_system_info = system_info as EthSystemDiscoverer.SystemInfo; txtDeviceIP.Text = eth_system_info.IPAddress.ToString(); } else if (system_info is SerSystemDiscoverer.SystemInfo) { SerSystemDiscoverer.SystemInfo ser_system_info = system_info as SerSystemDiscoverer.SystemInfo; txtDeviceIP.Text = ser_system_info.PortName; } } RefreshGui(); }
private void btnConnect_Click(object sender, EventArgs e) { if (listBoxDetectedSystems.SelectedIndex == -1 || listBoxDetectedSystems.SelectedIndex >= listBoxDetectedSystems.Items.Count) { return; } btnConnect.Enabled = false; _autoconnect = false; try { var system_info = listBoxDetectedSystems.Items[listBoxDetectedSystems.SelectedIndex]; if (system_info is EthSystemDiscoverer.SystemInfo) { EthSystemDiscoverer.SystemInfo eth_system_info = system_info as EthSystemDiscoverer.SystemInfo; EthSystemConnector conn = new EthSystemConnector(eth_system_info.IPAddress, eth_system_info.Port) { UserName = "******", Password = txtPassword.Text }; _connector = conn; } else if (system_info is SerSystemDiscoverer.SystemInfo) { SerSystemDiscoverer.SystemInfo ser_system_info = system_info as SerSystemDiscoverer.SystemInfo; SerSystemConnector conn = new SerSystemConnector(ser_system_info.PortName, ser_system_info.Baudrate); _connector = conn; } _logger.Enabled = cbLoggingEnabled.Checked; _connector.Logger = _logger; _system = new DataManSystem(_connector) { DefaultTimeout = 5000 }; // Subscribe to events that are signalled when the system is connected / disconnected. _system.SystemConnected += new SystemConnectedHandler(OnSystemConnected); _system.SystemDisconnected += new SystemDisconnectedHandler(OnSystemDisconnected); _system.SystemWentOnline += new SystemWentOnlineHandler(OnSystemWentOnline); _system.SystemWentOffline += new SystemWentOfflineHandler(OnSystemWentOffline); _system.KeepAliveResponseMissed += new KeepAliveResponseMissedHandler(OnKeepAliveResponseMissed); _system.BinaryDataTransferProgress += new BinaryDataTransferProgressHandler(OnBinaryDataTransferProgress); _system.OffProtocolByteReceived += new OffProtocolByteReceivedHandler(OffProtocolByteReceived); _system.AutomaticResponseArrived += new AutomaticResponseArrivedHandler(AutomaticResponseArrived); // Subscribe to events that are signalled when the device sends auto-responses. ResultTypes requested_result_types = ResultTypes.ReadXml | ResultTypes.Image | ResultTypes.ImageGraphics; _results = new ResultCollector(_system, requested_result_types); _results.ComplexResultCompleted += Results_ComplexResultCompleted; _results.SimpleResultDropped += Results_SimpleResultDropped; _system.SetKeepAliveOptions(cbEnableKeepAlive.Checked, 3000, 1000); _system.Connect(1000); try { _system.SetResultTypes(requested_result_types); } catch { } } catch (Exception ex) { CleanupConnection(); AddListItem("Failed to connect: " + ex.ToString()); } _autoconnect = true; RefreshGui(); }
private void btnConnect_Click(object sender, EventArgs e) { btnConnect.Enabled = false; try { if (listBoxDetectedSystems.SelectedIndex != -1 && listBoxDetectedSystems.Items.Count > listBoxDetectedSystems.SelectedIndex) { var system_info = listBoxDetectedSystems.Items[listBoxDetectedSystems.SelectedIndex]; if (system_info is EthSystemDiscoverer.SystemInfo) { EthSystemDiscoverer.SystemInfo eth_system_info = system_info as EthSystemDiscoverer.SystemInfo; EthSystemConnector conn = new EthSystemConnector(eth_system_info.IPAddress); conn.UserName = "******"; conn.Password = txtPassword.Text; _connector = conn; } else if (system_info is SerSystemDiscoverer.SystemInfo) { SerSystemDiscoverer.SystemInfo ser_system_info = system_info as SerSystemDiscoverer.SystemInfo; SerSystemConnector conn = new SerSystemConnector(ser_system_info.PortName, ser_system_info.Baudrate); _connector = conn; } } _connector.Logger = new GuiLogger(tbLog, cbLoggingEnabled.Checked, ref _closing); _system = new DataManSystem(_connector); _system.DefaultTimeout = 5000; // Subscribe to events that are signalled when the system is connected / disconnected. _system.SystemConnected += new SystemConnectedHandler(OnSystemConnected); _system.SystemDisconnected += new SystemDisconnectedHandler(OnSystemDisconnected); _system.SystemWentOnline += new SystemWentOnlineHandler(OnSystemWentOnline); _system.SystemWentOffline += new SystemWentOfflineHandler(OnSystemWentOffline); // Subscribe to events that are signalled when the deveice sends auto-responses. _system.ReadStringArrived += new ReadStringArrivedHandler(OnReadStringArrived); _system.XmlResultArrived += new XmlResultArrivedHandler(OnXmlResultArrived); _system.ImageArrived += new ImageArrivedHandler(OnImageArrived); _system.ImageGraphicsArrived += new ImageGraphicsArrivedHandler(OnImageGraphicsArrived); _system.BinaryDataTransferProgress += new BinaryDataTransferProgressHandler(OnBinaryDataTransferProgress); _system.SetKeepAliveOptions(cbEnableKeepAlive.Checked, 3000, 1000); _system.Connect(); } catch (Exception ex) { CleanupConnection(); AddListItem("Failed to connect: " + ex.ToString()); btnConnect.Enabled = true; } _autoconnect = true; }
private void OnEthSystemDiscovered(EthSystemDiscoverer.SystemInfo systemInfo) { ListOfDiscoveredCam.Add(systemInfo); CamDetected?.Invoke(systemInfo); }