public Plc() { omronPlc = new OmronPLC(mcOMRON.TransportType.Tcp); tcpCommand = ((mcOMRON.tcpFINSCommand)omronPlc.FinsCommand); connectionMonitor = new Timer(); connectionMonitor.Elapsed += ConnectionMonitor_Elapsed;; connectionMonitor.Interval = 2000; connectionMonitor.Enabled = false; ConnectionStatus = ConnectionStatusEnum.DISCONNECTED; AutoReconnectAfterConnectionLostCounter = 0; }
private bool tryAndConnect() { Func <bool> testDataRead = (() => { try { if (omronPlc.finsConnectionDataRead(0)) { return(true); } } catch (Exception e) { return(false); } return(false); }); Func <bool> testNewConnect = (() => { try { omronPlc = new OmronPLC(mcOMRON.TransportType.Tcp); tcpCommand = ((mcOMRON.tcpFINSCommand)omronPlc.FinsCommand); tcpCommand.SetTCPParams(ip, port); if (omronPlc.Connect()) //why exception //omronPlc.Close(); { return(true); } } catch (Exception e) { return(false); } return(false); }); if (testDataRead()) { return(true); } else if (testNewConnect()) { return(true); } return(false); }