private void InitializeDevices()
        {
            Connection = new IPConnection();
            Connection.Connect("localhost", 4223);

            ServoBrick = new BrickServo("ap6zRki6edN", Connection);
            SetupServoBrick();
            DistanceBricklet = new BrickletDistanceIR("8XU", Connection);
            var distanceCollection = new ClosestDistanceSensorCollection();
            distanceCollection.AddSensor(new ImmediateDistanceIRSensor(DistanceBricklet));
            Distances = distanceCollection;

            var drivingStrategy = new SimpleDistanceDrivingStrategy(Engine, Distances);
            drivingStrategy.MinimumDrivingDistance = 30.Centimeters();
            drivingStrategy.ReversalDistance = 11.Centimeters();
            drivingStrategy.RefreshInterval = 10;
            this.DrivingStrategy = drivingStrategy;
        }
示例#2
0
		public static bool init(ref IPConnection brick_connection) {
			
			// get UIDs of bricks and bricklets
			AppSettingsReader config = new AppSettingsReader();
			
			host = (string)config.GetValue("host", typeof(string));
			port = (int)config.GetValue("port", typeof(int));
			server_port = (int)config.GetValue("server_port", typeof(int));
			string master_brick_uid = (string)config.GetValue("master_brick_uid", typeof(string));
			string ambient_bricklet_uid = (string)config.GetValue("ambient_light_bricklet_uid", typeof(string));
			string temperature_bricklet_uid = (string)config.GetValue("temperature_bricklet_uid", typeof(string));
			string lcd_20x4_bricklet_uid = (string)config.GetValue("lcd_20x4_bricklet_uid", typeof(string));
			
#if DEBUG
			Console.WriteLine("Master Brick Host:Port ...: {0}:{1}", host, port);
			Console.WriteLine("Serverport (udp msgs).....: :{0}", server_port);
			Console.WriteLine("Master Brick UID .........: {0}", master_brick_uid);
			Console.WriteLine("Ambient Bricklet UID .....: {0}", ambient_bricklet_uid);
			Console.WriteLine("Temperature Bricklet UID .: {0}", temperature_bricklet_uid);
			Console.WriteLine("LCD 20x4 Bricklet UID ....: {0}", lcd_20x4_bricklet_uid);
#endif
			
			// setup connection to master und bricklets
			try {
				brick_connection = new IPConnection(host, port);
				
				ambient_light = new BrickletAmbientLight(ambient_bricklet_uid);
				temperature = new BrickletTemperature(temperature_bricklet_uid);
				lcd = new BrickletLCD20x4(lcd_20x4_bricklet_uid);
				displayHelper = new LCDisplayHelper(lcd);
			
				brick_connection.AddDevice(ambient_light);
				brick_connection.AddDevice(temperature);
				brick_connection.AddDevice(lcd);
			} catch (Tinkerforge.TimeoutException te) {
				Console.WriteLine(te.Message);
				return false;
			}
			
			return true;
		}
示例#3
0
        private void ConnectWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string[] argument = e.Argument as string[];

            ipcon = new IPConnection();

            try
            {
                relay = new BrickletIndustrialQuadRelay(argument[2], ipcon);
            }
            catch (ArgumentOutOfRangeException)
            {
                e.Result = ConnectResult.NO_DEVICE;
                return;
            }

            try
            {
                ipcon.Connect(argument[0], Convert.ToInt32(argument[1]));
            }
            catch (System.IO.IOException)
            {
                e.Result = ConnectResult.NO_CONNECTION;
                return;
            }
            catch (ArgumentOutOfRangeException)
            {
                e.Result = ConnectResult.NO_CONNECTION;
                return;
            }

            try
            {
                string uid;
                string connectedUid;
                char position;
                byte[] hardwareVersion;
                byte[] firmwareVersion;
                int deviceIdentifier;

                relay.GetIdentity(out uid, out connectedUid, out position,
                                  out hardwareVersion, out firmwareVersion, out deviceIdentifier);

                if (deviceIdentifier != BrickletIndustrialQuadRelay.DEVICE_IDENTIFIER)
                {
                    ipcon.Disconnect();
                    e.Result = ConnectResult.NO_DEVICE;
                    return;
                }
            }
            catch (TinkerforgeException)
            {
                try
                {
                    ipcon.Disconnect();
                }
                catch (NotConnectedException)
                {
                }

                e.Result = ConnectResult.NO_DEVICE;
                return;
            }

            e.Result = ConnectResult.SUCCESS;
        }
        /// <summary>
        ///  Creates an object with the unique device ID <c>uid</c> and adds  it to
        ///  the IPConnection <c>ipcon</c>.
        /// </summary>
        public BrickletIndustrialQuadRelay(string uid, IPConnection ipcon)
            : base(uid, ipcon)
        {
            this.apiVersion[0] = 2;
            this.apiVersion[1] = 0;
            this.apiVersion[2] = 0;
            callbackWrappers[CALLBACK_MONOFLOP_DONE] = new CallbackWrapper(OnMonoflopDone);

            responseExpected[FUNCTION_SET_VALUE] = ResponseExpectedFlag.FALSE;
            responseExpected[FUNCTION_GET_VALUE] = ResponseExpectedFlag.ALWAYS_TRUE;
            responseExpected[FUNCTION_SET_MONOFLOP] = ResponseExpectedFlag.FALSE;
            responseExpected[FUNCTION_GET_MONOFLOP] = ResponseExpectedFlag.ALWAYS_TRUE;
            responseExpected[FUNCTION_SET_GROUP] = ResponseExpectedFlag.FALSE;
            responseExpected[FUNCTION_GET_GROUP] = ResponseExpectedFlag.ALWAYS_TRUE;
            responseExpected[FUNCTION_GET_AVAILABLE_FOR_GROUP] = ResponseExpectedFlag.ALWAYS_TRUE;
            responseExpected[FUNCTION_SET_SELECTED_VALUES] = ResponseExpectedFlag.FALSE;
            responseExpected[FUNCTION_GET_IDENTITY] = ResponseExpectedFlag.ALWAYS_TRUE;
            responseExpected[CALLBACK_MONOFLOP_DONE] = ResponseExpectedFlag.ALWAYS_FALSE;
        }