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 void SendRelayCommand(Light light, bool turnOn) { var relayId = (int)light; var commandToSend = string.Format("{0} {1}", relayId, (turnOn ? 1 : 0)); _serialPortAdapter.WriteLine(commandToSend); LogCommandSent(commandToSend); }