示例#1
0
        private static void DataReceivedHandler(
            object sender,
            SerialDataReceivedEventArgs e)
        {
            // TODO: This event is fired on a subthread, need to get the
            //       data handed off to the main thread.
            ArduinoPort port = (ArduinoPort)sender;
            string      data = port.ReadExisting();

            port.OnDataReceived(data);
        }
示例#2
0
        public ArduinoPin(ArduinoPort port, string pinDescription)
        {
            m_port = port;

            string modeString = pinDescription.Substring(0, 2);

            switch (modeString)
            {
            case "AI":
                Mode = ArduinoPinMode.AnalogIn;
                break;

            case "AO":
                Mode = ArduinoPinMode.AnalogOut;
                break;

            case "DI":
                Mode = ArduinoPinMode.DigitalIn;
                break;

            case "DO":
                Mode = ArduinoPinMode.DigitalOut;
                break;

            default:
                throw new Exception("Unknown pin mode");
            }

            int posColon = pinDescription.IndexOf(':');

            if (posColon < 3)
            {
                throw new Exception("Missing pin value or number");
            }

            int posQuote1 = pinDescription.IndexOf('"');

            if (posQuote1 < (posColon + 2))
            {
                throw new Exception("Missing pin name or value");
            }

            Number  = int.Parse(pinDescription.Substring(2, posColon - 2));
            m_value = int.Parse(pinDescription.Substring(posColon + 1, posQuote1 - posColon - 1));

            int posQuote2 = pinDescription.LastIndexOf('"');

            Name = pinDescription.Substring(posQuote1 + 1, posQuote2 - posQuote1 - 1);
        }
示例#3
0
 public void Disconnect()
 {
     m_port = null;
 }