public string Disconnect() { Modular.Part.IBaseState spBaseState = sp.BaseState; Modular.Part.IBasicAction spGoOfflineAction = sp.CreateGoOfflineAction(); // warning: what to do if the sp has not been started at this point... string ec = null; if (sp.IsRunning) { ec = spGoOfflineAction.Run(); } else { Log.Debug.Emit("Serial Port does not appear to have been started: skipping GoOffline action [{0}]", sp.BaseState); } if (String.IsNullOrEmpty(ec)) { SetBaseState(Modular.Part.ConnState.Disconnected, "Disconnect completed", true); } else { SetBaseState(Modular.Part.ConnState.Disconnected, "Disconnect failed:" + ec, true); } return(ec); }
public string Connect() { if (!BaseState.IsOnline) { SetBaseState(Modular.Part.UseState.AttemptOnline, "Attempting Connect while Offline", true); } Modular.Part.IBaseState spBaseState = sp.BaseState; if (!spBaseState.IsConnected) { SetBaseState(Modular.Part.ConnState.Connecting, "Attempting to Connect", true); } Modular.Part.IBasicAction spGoOnlineAction = sp.CreateGoOnlineAction(); string ec = spGoOnlineAction.Run(); if (String.IsNullOrEmpty(ec)) { SetBaseState(Modular.Part.UseState.Online, Modular.Part.ConnState.Connected, "Connect complete", true); } else if (BaseState.UseState == MosaicLib.Modular.Part.UseState.AttemptOnline) { SetBaseState(Modular.Part.UseState.AttemptOnlineFailed, Modular.Part.ConnState.ConnectFailed, "Connect failed:" + ec, true); } else { SetBaseState(Modular.Part.ConnState.ConnectFailed, "Connect failed:" + ec, true); } return(ec); }