public static string[] getPLCList(bool aRomote, string aIP, int aIPPort) { SInstanceInfo[] lPLC; if (aRomote) { var lConnectionStr = aIP + ":" + aIPPort.ToString(); try { var lRRManager = SimulationRuntimeManager.RemoteConnect(lConnectionStr); lPLC = lRRManager.RegisteredInstanceInfo; lRRManager.Disconnect(); lRRManager.Dispose(); } catch (SimulationRuntimeException lExc) { throw new InvalidOperationException("Connection '" + lConnectionStr + "'. " + ErrorCodeMessage(lExc.RuntimeErrorCode), lExc); } } else { try { lPLC = SimulationRuntimeManager.RegisteredInstanceInfo; } catch (SimulationRuntimeException lExc) { throw new InvalidOperationException(ErrorCodeMessage(lExc.RuntimeErrorCode), lExc); } } return(lPLC.Select(x => x.Name).ToArray()); }
public void TogglePower() { try { //EnableVirtualSwitch(); SimulationRuntimeManager.OnRunTimemanagerLost += SimulationRuntimeManager_OnRunTimemanagerLost; SimulationRuntimeManager.OnConfigurationChanged += SimulationRuntimeManager_OnConfigurationChanged; if (HasName(Name)) { Instance = SimulationRuntimeManager.CreateInterface(Name); } else { Instance = SimulationRuntimeManager.RegisterInstance(ECPUType.CPU1513, Name); } if (Instance.OperatingState != EOperatingState.Run) { Instance.CommunicationInterface = ECommunicationInterface.TCPIP; Instance.StoragePath = VPLCStoragePath; Instance.IsSendSyncEventInDefaultModeEnabled = true; Instance.OnConfigurationChanged += Instance_OnConfigurationChanged; Instance.OnConfigurationChanging += Instance_OnConfigurationChanging; Instance.OnLedChanged += Instance_OnLedChanged; Instance.OnOperatingStateChanged += Instance_OnOperatingStateChanged; Instance.OnSyncPointReached += Instance_OnSyncPointReached; Instance.OnProcessEventDone += Instance_OnProcessEventDone; Instance.OnUpdateEventDone += Instance_OnUpdateEventDone; var result = Instance.PowerOn(5000); switch (result) { case ERuntimeErrorCode.OK: AfterPowerOnOK(); break; case ERuntimeErrorCode.Timeout: break; } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); Growl.Error(ex.ToString()); } finally { } }
public PlcInstance(string instanceName) { var kuku = SimulationRuntimeManager.RegisteredInstanceInfo; instance = SimulationRuntimeManager.CreateInterface(kuku[0].ID); //return; //instance = SimulationRuntimeManager.RegisterInstance(ECPUType.ET200SP_Unspecified, instanceName); instance.IsAlwaysSendOnEndOfCycleEnabled = true; instance.CommunicationInterface = ECommunicationInterface.Softbus; instance.OnConfigurationChanged += instance_OnConfigurationChanged; instance.OnEndOfCycle += instance_OnEndOfCycle; }
public void connect() { if (mTagBrowserForm != null) { mTagBrowserForm.Dispose(); mTagBrowserForm = null; } if (mPLC != null) { mPLC.OnConfigurationChanged -= onConfigurationChanged; mPLC.OnConfigurationChanging -= onConfigurationChanging; mPLC.Dispose(); mPLC = null; } if (mRRManager != null) { mRRManager.OnConnectionLost -= onRemoteConnectionLost; mRRManager.Disconnect(); mRRManager.Dispose(); mRRManager = null; } if (String.IsNullOrWhiteSpace(mPLCName)) { throw new InvalidOperationException("PLC name is empty. "); } if (mRemote) { var lConnectionStr = mIP + ":" + mIPPort.ToString(); if (String.IsNullOrWhiteSpace(lConnectionStr)) { throw new InvalidOperationException("Connection string is empty. "); } try { mRRManager = SimulationRuntimeManager.RemoteConnect(lConnectionStr); } catch (SimulationRuntimeException lExc) { throw new InvalidOperationException("Connection '" + lConnectionStr + "'. " + ErrorCodeMessage(lExc.RuntimeErrorCode), lExc); } try { mPLC = mRRManager.CreateInterface(mPLCName); } catch (SimulationRuntimeException lExc) { mRRManager.Dispose(); mRRManager = null; throw new InvalidOperationException("PLC instance '" + mPLCName + "'. " + ErrorCodeMessage(lExc.RuntimeErrorCode), lExc); } mRRManager.OnConnectionLost += onRemoteConnectionLost; } else { try { mPLC = SimulationRuntimeManager.CreateInterface(mPLCName); } catch (SimulationRuntimeException lExc) { throw new InvalidOperationException("PLC instance '" + mPLCName + "'. " + ErrorCodeMessage(lExc.RuntimeErrorCode), lExc); } } if (mMainCycleTimer == null) { mMainCycleTimer = new System.Timers.Timer(MiscUtils.TimeSlice); mMainCycleTimer.Elapsed += new ElapsedEventHandler(MainCycle); mMainCycleTimer.AutoReset = false; } mPLC.UpdateTagList(); mPLC.OnConfigurationChanged += onConfigurationChanged; mPLC.OnConfigurationChanging += onConfigurationChanging; mConnected = true; mDisconnect = false; mReconnect = false; mWriteRequests = 0; mMainCycleTimer.Start(); raiseConnectionState(); }