public async Task <IActionResult> InsertDevice([FromBody] DeviceSchema schema) { if (!ModelState.IsValid) { return(BadRequest("Invalid Request")); } var res = await _device.InsertOneAsync(new Devices() { CreatedAt = DateTime.Now, mac = schema.mac, name = schema.name, userId = schema.userId }); if (res) { var usr = _user.Users.Where(x => x.UserName == schema.userId).FirstOrDefault(); await _log.InsertOneAsync( new Logs() { userId = usr.Id, message = "Device " + schema.name + " is Added Successfully", events = "Event", subject = "Insertion", CreatedAt = DateTime.Now }); return(Ok(new { status = "Device " + schema.name + " is Added Successfully" })); } return(BadRequest("Invalid Request")); }
static async Task MyAsyncFunc() { var deviceMonitor = DeviceMonitor.Instance; var foundDevice = deviceMonitor.AvailableDevices.FirstOrDefault(); var schema = new DeviceSchema(); if (foundDevice == null) { throw new Exception("Could not find any suitable devices to connect to"); } using (var oDrive = new Device(foundDevice, DeviceSchema.SchemaChecksum)) { bool connectSuccess = false; try { connectSuccess = await oDrive.Connect(); } catch (Exception ex) { System.Diagnostics.Debugger.Break(); } // var download = await oDrive.DownloadSchema(); while (!Console.KeyAvailable) { var x = await oDrive.GetProperty(schema.Config.Gpio1PwmMapping.Endpoint); Console.WriteLine($"{x.EndpointID}, {x.JsonCRC}"); //await oDrive.SetProperty(schema.Motor0.Config.CalibrationCurrent, 1); //await oDrive.GetExecutionDelegate(schema.SaveConfiguration)(); Application.DoEvents(); } } }