private void ConnectToSimulator() { try { mdbClient = new MdbClient("localhost", 502); if (mdbClient.Connected) { return; } mdbClient.Connect("localhost", 502); } catch (SocketException e) { Thread.Sleep(2000); ConnectToSimulator(); } catch (Exception) { throw; } }
private void ConnectToSimulator() { try { modbusClient = new MdbClient("localhost", 502); modbusClient.Connect(); } catch (SocketException) { //Start simulator EasyModbusServerSimulator.exe string appPath = Path.GetFullPath("..\\..\\..\\..\\..\\"); Process.Start(appPath + "EasyModbusServerSimulator.exe"); Thread.Sleep(2000); ConnectToSimulator(); } catch (Exception) { throw; } }