internal Servo(CommandRunner runner, Arm arm, int servoID) { //set fields _runner = runner; _arm = arm; _servoID = servoID; }
private void Connection_ConnectionUnavailible(object sender, ConnectionEventArgs e) { //send events PortScanned?.Invoke(this, new PortScannedEventArgs() { Port = e.Port, IsRemoved = true }); //remove from the arm list Arm arm; if (!_arms.TryRemove(e.Port, out arm)) { return; } //close connection try { arm.Communication.Disconnect(); } catch { } //update current arm if (CurrentArm == arm) { CurrentArm = (_arms.Count != 0) ? _arms.First().Value : null; } }
internal Led(CommandRunner runner, Arm arm) { //set fields _runner = runner; _arm = arm; //register responses _runner.RegisterForResponse <LedStatusResponse>(StatusResponse); }
internal Sound(CommandRunner runner, Arm arm) { //set fields _runner = runner; _arm = arm; //register responses _runner.RegisterForResponse <SoundPlayNotesResponse>(PlayNotesResponse); _runner.RegisterForResponse <SoundStatusResponse>(StatusResponse); }
internal Knob(CommandRunner runner, Arm arm) { //set fields _runner = runner; _arm = arm; //register responses _runner.RegisterForResponse <KnobPositionChangedResponse>(PositionChangedResponse); _runner.RegisterForResponse <KnobPositionResponse>(PositionResponse); _runner.RegisterForResponse <KnobRangeResponse>(RangeResponse); }
internal Button(CommandRunner runner, Arm arm) { //set fields _runner = runner; _arm = arm; //register responses _runner.RegisterForResponse <ButtonDownResponse>(DownResponse); _runner.RegisterForResponse <ButtonUpResponse>(UpResponse); _runner.RegisterForResponse <ButtonStatusResponse>(StatusResponse); }
internal Servos(CommandRunner runner, Arm arm, int servoCount) { //set fields _runner = runner; _arm = arm; _servoCount = servoCount; //add servos for (int i = 1; i <= servoCount; i++) { Add(new Servo(_runner, _arm, i)); } //register responses _runner.RegisterForResponse <ServoPositionChangedResponse>(PositionChangedResponse); _runner.RegisterForResponse <ServoStatusResponse>(StatusResponse); _runner.RegisterForResponse <MoveResponse>(MoveResponse); _runner.RegisterForResponse <ServoOnResponse>(OnResponse); _runner.RegisterForResponse <ServoOffResponse>(OffResponse); }
private void Connection_ConnectionAvailible(object sender, ConnectionEventArgs e) { //send scanning event if (_scanningCount == 0) { ScanningChanges?.Invoke(this, new ScanningChangesEventArgs() { Scanning = true }); } _scanningCount++; Task.Run(async() => { var portScan = new PortScannedEventArgs() { Port = e.Port, PossibleArm = e.PossibleArm }; Arm addArm = null; //open the connection var arm = new Arm(e.Communication); try { e.Communication.Connect(e.Port); } catch (CommunicationException ex) { portScan.ErrorMessage = ex.Message; } catch { } if (e.Communication.IsConnected) { portScan.CanOpen = true; //ping if (!e.ExistingDevice) { await Task.Delay(2000); //wait 2 seconds after plug in to load usb driver - bug fix } var ping = await arm.PingAsync(); //try one more time if (!ping) { await Task.Delay(2000); ping = await arm.PingAsync(); } if (!ping) { e.Communication.Disconnect(); } else { portScan.HasArm = true; portScan.Arm = arm; //get all settings await arm.LoadSettingsAsync(); //reload the arm if the servo count should be diffrent if (arm.Settings != null) { if (arm.Settings.ActiveServos.HasValue && arm.Settings.ActiveServos.Value != arm.Servos.Count) { arm = new Arm(arm.Communication, arm.Settings.ActiveServos.Value); await arm.LoadSettingsAsync(); } portScan.Model = arm.Settings.ModelNumber; portScan.NickName = arm.Settings.NickName; //add the Arm addArm = arm; } else { portScan.NeedsSettingsReset = true; portScan.Arm.Communication.Disconnect(); } } } //send port scanned event PortScanned?.Invoke(this, portScan); //add to the arm list if (addArm != null) { _arms.TryAdd(e.Port, addArm); if (CurrentArm == null) { CurrentArm = addArm; } } //send finished scanning event _scanningCount--; if (_scanningCount == 0) { ScanningChanges?.Invoke(this, new ScanningChangesEventArgs() { Scanning = false }); } }); }