예제 #1
0
        } = null;                                    //To be supplied externally

        public ArduinoDeviceManager(ArduinoSession firmata, Action <ADMMessage, ArduinoDeviceManager> listener, String port, String nodeID = null)
        {
            State = ADMState.CONNECTING;

            _devices        = new Dictionary <String, ArduinoDevice>();
            _device2boardID = new Dictionary <String, byte>();
            _boardID2device = new Dictionary <byte, ArduinoDevice>();

            _pin2device = new Dictionary <int, List <ArduinoDevice> >();
            _portStates = new Dictionary <int, DigitalPortState>();

            _session  = firmata;
            _listener = listener;
            _session.MessageReceived         += HandleFirmataMessageReceived;
            _session.ProcessMessageException += HandleFirmataProcessMessageException;

            Port        = port;
            NodeID      = nodeID;
            _session.ID = PortAndNodeID;

            _firmware = _session.GetFirmware();
#if DEBUG
            Debug.Print(String.Format("{0}: Firmware: {1} version {2}.{3}", PortAndNodeID, _firmware.Name, _firmware.MajorVersion, _firmware.MinorVersion));
#endif
            _protocolVersion = _session.GetProtocolVersion();
#if DEBUG
            Debug.Print(String.Format("{0}: Firmata protocol version {1}.{2}", PortAndNodeID, _protocolVersion.Major, _protocolVersion.Minor));
#endif
            _boardCapability = _session.GetBoardCapability();
            State            = ADMState.CONNECTED;

            //if here and no exceptions then the connection should be good
            //so initialise the board
            Initialise();

            //and request board status
            RequestStatus();
        }