private static void OnDeviceAdded(NXT nxt) { if (RobotAdded != null) { RobotAdded(nxt, new AvailableDevicesChangedEventArgs(nxt)); } }
public NXTViewModel(NXT robot) { this.robot = robot; robot.PropertyChanged += new PropertyChangedEventHandler(robot_PropertyChanged); robot.Disconnected += new NXT.AvailableRobotsChangedEventHandler(robot_Disconnected); robot.Reconnected += new NXT.AvailableRobotsChangedEventHandler(robot_Reconnected); connected = false; }
private static void OnDeviceAdded(NXT nxt) { if (RobotAdded != null) RobotAdded(nxt, new AvailableDevicesChangedEventArgs(nxt)); }
public static void FindNXTDevices(object sender, DoWorkEventArgs eventArgs) { while (continueDeviceDiscovery) { if (!availableRobots.ContainsKey("USB")) // If a usb was not connected before test it now { NXT usbNXT = new NXT("USB", new NXTUsbConnection()); if (usbNXT.nxtConn.IsConnected) { availableRobots.Add("USB", usbNXT); OnDeviceAdded(usbNXT); } } var btClient = new BluetoothClient(); List<BluetoothClient> btRobots = new List<BluetoothClient>(); btClient.InquiryLength = new TimeSpan(0, 0, 4); BluetoothDeviceInfo[] btDevices = btClient.DiscoverDevicesInRange(); foreach (BluetoothDeviceInfo btDevice in btDevices) { try { // The property InstalledServices only lists services for devices that have been paired with // the computer already (rather than requesting it from the device). This is fine in our // scenario since you cant get a service list off the devices unless it is already paired. if (btDevice.InstalledServices.Contains(NXT32FeetBT.NXT_BT_SERVICE)) { String nxtIdentifier = btDevice.DeviceAddress.ToString(); if (!availableRobots.ContainsKey(nxtIdentifier)) { NXT foundNXT = new NXT(nxtIdentifier, new NXT32FeetBT(btDevice.DeviceAddress)); availableRobots.Add(nxtIdentifier, foundNXT); OnDeviceAdded(foundNXT); } else { if (!availableRobots[nxtIdentifier].connected) { availableRobots[nxtIdentifier].Reconnect(); } } } } catch (SocketException e) { } // Socket exception occurs if the device is not an nxt } // Check if any previously found devices were lost var btAddresses = from btDevice in btDevices select btDevice.DeviceAddress.ToString(); foreach (NXT nxt in AvailableRobots.Values) { if (!btAddresses.Contains(nxt.uniqueID)) { nxt.connected = false; nxt.OnDeviceDisconnected(); } } // Sleep for the designated poll interval Thread.Sleep(DEVICE_DISCOVERY_POLL_RATE); } }
public NXTRobot(NXT robot) { Name = robot.Name; ID = robot.ID; }
public static void FindNXTDevices(object sender, DoWorkEventArgs eventArgs) { while (continueDeviceDiscovery) { if (!availableRobots.ContainsKey("USB")) // If a usb was not connected before test it now { NXT usbNXT = new NXT("USB", new NXTUsbConnection()); if (usbNXT.nxtConn.IsConnected) { availableRobots.Add("USB", usbNXT); OnDeviceAdded(usbNXT); } } var btClient = new BluetoothClient(); List <BluetoothClient> btRobots = new List <BluetoothClient>(); btClient.InquiryLength = new TimeSpan(0, 0, 4); BluetoothDeviceInfo[] btDevices = btClient.DiscoverDevicesInRange(); foreach (BluetoothDeviceInfo btDevice in btDevices) { try { // The property InstalledServices only lists services for devices that have been paired with // the computer already (rather than requesting it from the device). This is fine in our // scenario since you cant get a service list off the devices unless it is already paired. if (btDevice.InstalledServices.Contains(NXT32FeetBT.NXT_BT_SERVICE)) { String nxtIdentifier = btDevice.DeviceAddress.ToString(); if (!availableRobots.ContainsKey(nxtIdentifier)) { NXT foundNXT = new NXT(nxtIdentifier, new NXT32FeetBT(btDevice.DeviceAddress)); availableRobots.Add(nxtIdentifier, foundNXT); OnDeviceAdded(foundNXT); } else { if (!availableRobots[nxtIdentifier].connected) { availableRobots[nxtIdentifier].Reconnect(); } } } } catch (SocketException e) { } // Socket exception occurs if the device is not an nxt } // Check if any previously found devices were lost var btAddresses = from btDevice in btDevices select btDevice.DeviceAddress.ToString(); foreach (NXT nxt in AvailableRobots.Values) { if (!btAddresses.Contains(nxt.uniqueID)) { nxt.connected = false; nxt.OnDeviceDisconnected(); } } // Sleep for the designated poll interval Thread.Sleep(DEVICE_DISCOVERY_POLL_RATE); } }
public AvailableDevicesChangedEventArgs(NXT nxt) { AffectedDevice = nxt; }