public void OnMbedStatusChanged(MbedStatus status) { Status = status; MbedStatusEventArgs e = new MbedStatusEventArgs {Status = status}; EventHandler<MbedStatusEventArgs> handler = MbedStatusChanged; if (handler != null) handler(this, e); }
public void OnMbedStatusChanged(MbedStatus status) { Status = status; MbedStatusEventArgs e = new MbedStatusEventArgs { Status = status }; EventHandler <MbedStatusEventArgs> handler = MbedStatusChanged; if (handler != null) { handler(this, e); } }
public virtual void Stop() { Status = MbedStatus.Disconnected; OnMbedStatusChanged(new MbedStatusEventArgs() { Status = Status }); }
public string RPC(string function, params int[] arguments) { string response = "128"; if (_serialPortAdapter == null || _serialPortAdapter.IsOpen == false) { return response; } //throw new InvalidOperationException("The Serial port has not been initialized. Did you initialize the port?"); string functionArguments = arguments.Aggregate(string.Empty, (current, argument) => string.Format("{0} {1}", current, argument)); string rpcCommand = string.Format("/{0}/run {1}", function, functionArguments); try { _serialPortAdapter.WriteLine(rpcCommand); response = _serialPortAdapter.ReadLine(); } catch (Exception) { OnMbedStatusChanged(Status = MbedStatus.Disconnected); Stop(); } Debug.WriteLine("Command sent to mbed: {0}", rpcCommand); return response; }
private string GetMbedPortName(string strStartKey = null) { if (string.IsNullOrEmpty(strStartKey)) strStartKey = _settings.PortSearchKey; // ...GetPortNames obtains a list of COM ports that are actually connected. Without using this // list the code will still try to connect to an mbed even if it isn't connected because the registry // seems to remember things even if they are unplugged string[] portNames = SerialPortAdapter.GetPortNames(); RegistryKey currentKey = Registry.LocalMachine.OpenSubKey(strStartKey); if (currentKey == null) //throw new MbedLookupException("No mbed COM port driver found. Please install the latest Windows Serial Port Driver for the mbed."); OnMbedStatusChanged(Status = MbedStatus.NoDriver); string[] subKeyNames = currentKey.GetSubKeyNames(); if (subKeyNames.Contains("Device Parameters")) { string portNameValue = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\" + strStartKey + "\\Device Parameters", "PortName", null); return portNames.Contains(portNameValue) ? portNameValue : null; } var result = (from strSubKey in subKeyNames where GetMbedPortName(strStartKey + "\\" + strSubKey) != null select GetMbedPortName(strStartKey + "\\" + strSubKey)).FirstOrDefault(); if (result == null) //throw new MbedLookupException("Mbed not detected. Please verify the mbed is plugged in and shows in the Device Manager under \"Ports (COM & LPT)\""); OnMbedStatusChanged(MbedStatus.Disconnected ); return result; }