private void ReceiveAndProcessNextCommand()
        {
            var lineRead = _serialPortAdapter.ReadLine();

            LogCommandReceived(lineRead);
            ProcessCommandReceived(lineRead);
        }
示例#2
0
        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);
        }