// device needs to be switched on! public override async Task DiscoverAsync(bool enableTrace) { var hub = await Host.CreateByStateAsync <TechnicMediumHub>(ChangeMe_BluetoothAddress); SelectedHub = DirectlyConnectedHub = hub; await hub.ConnectAsync(); }
// device needs to be switched on! public override async Task DiscoverAsync(bool enableTrace) { var hub = await Host.DiscoverAsync <TechnicMediumHub>(); SelectedHub = DirectlyConnectedHub = hub; await hub.ConnectAsync(); }
private static async Task TestTechnicHub(int scanSeconds) { var technichub = await TechnicMediumHub.ScanAndConnect(timeout : TimeSpan.FromSeconds(scanSeconds)); if (technichub == null) { Log.Error("Technic Medium Hub not found."); return; } Log.Information($"Firmware Version: {technichub.FirmwareVersion}"); Log.Information($"Hardware Version: {technichub.HardwareVersion}"); Log.Information($"RSSI: {technichub.RSSI}"); Log.Information($"Battery Voltage: {technichub.BatteryVoltage}"); Log.Information($"Primary MAC Address: {technichub.PrimaryMACAddress}"); await technichub.LED.SetRGB(100, 0, 0); await Task.Delay(TimeSpan.FromSeconds(3)); await technichub.LED.SetColor(Color.PINK); technichub.OnButtonStateChange += async(sender, state) => Log.Information($"ButtonState: {state}"); technichub.OnDeviceAttach += async(sender, device, portId) => { await TestLPF2Device(device); }; var t1 = technichub.FindFirstDevice(LPF2DeviceType.TECHNIC_LARGE_LINEAR_MOTOR) as TachoMotor; var t2 = technichub.FindFirstDevice(LPF2DeviceType.TECHNIC_XLARGE_LINEAR_MOTOR) as TachoMotor; if (t1 != null) { await t1.SetPower(50); } if (t2 != null) { await t2.SetPower(50); } await Task.Delay(TimeSpan.FromSeconds(5)); if (t1 != null) { await t1.Stop(); } if (t2 != null) { await t2.Stop(); } await Task.Delay(TimeSpan.FromSeconds(60)); await technichub.Disconnect(); }
public override async Task ExecuteAsync() { using TechnicMediumHub technicMediumHub1 = DirectlyConnectedHub1; using TwoPortHub technicMediumHub2 = DirectlyConnectedHub2; await technicMediumHub1.VerifyDeploymentModelAsync(modelBuilder => modelBuilder .AddHub <TechnicMediumHub>(hubBuilder => hubBuilder .AddDevice <TechnicXLargeLinearMotor>(technicMediumHub1.A) ) ); await technicMediumHub2.VerifyDeploymentModelAsync(modelBuilder => modelBuilder .AddHub <TwoPortHub>(hubBuilder => hubBuilder .AddDevice <TechnicXLargeLinearMotor>(technicMediumHub2.A) ) ); var motor1 = technicMediumHub1.A.GetDevice <TechnicXLargeLinearMotor>(); var motor2 = technicMediumHub2.A.GetDevice <TechnicXLargeLinearMotor>(); await motor1.SetAccelerationTimeAsync(3000); await motor1.SetDecelerationTimeAsync(1000); await motor2.SetAccelerationTimeAsync(3000); await motor2.SetDecelerationTimeAsync(1000); await motor1.StartSpeedForTimeAsync(6000, 90, 100, SpecialSpeed.Hold, SpeedProfiles.AccelerationProfile | SpeedProfiles.DecelerationProfile); await motor2.StartSpeedForTimeAsync(6000, 90, 100, SpecialSpeed.Hold, SpeedProfiles.AccelerationProfile | SpeedProfiles.DecelerationProfile); await Task.Delay(5_000); await motor1.StartSpeedForDegreesAsync(180, -10, 100, SpecialSpeed.Brake, SpeedProfiles.None); await motor2.StartSpeedForDegreesAsync(180, -10, 100, SpecialSpeed.Brake, SpeedProfiles.None); await Task.Delay(5_000); await motor1.StartSpeedAsync(100, 90, SpeedProfiles.None); await motor2.StartSpeedAsync(100, 90, SpeedProfiles.None); await Task.Delay(5_000); await motor1.StartSpeedAsync(-100, 90, SpeedProfiles.None); await motor2.StartSpeedAsync(-100, 90, SpeedProfiles.None); await Task.Delay(5_000); await motor1.StartSpeedAsync(0, 90, SpeedProfiles.None); await motor2.StartSpeedAsync(0, 90, SpeedProfiles.None); await Task.Delay(5_000); await motor1.GotoPositionAsync(45, 10, 100, SpecialSpeed.Brake, SpeedProfiles.None); await motor2.GotoPositionAsync(45, 10, 100, SpecialSpeed.Brake, SpeedProfiles.None); await Task.Delay(5_000); await motor1.GotoPositionAsync(-45, 10, 100, SpecialSpeed.Brake, SpeedProfiles.None); await motor2.GotoPositionAsync(-45, 10, 100, SpecialSpeed.Brake, SpeedProfiles.None); await technicMediumHub1.SwitchOffAsync(); await technicMediumHub2.SwitchOffAsync(); }