static public uint ReadRegister(ONIXDeviceDescriptor descriptor, uint address) { using (var c = ONIContextManager.ReserveContext(descriptor.Address.HardwareSlot)) { return(c.Context.ReadRegister((uint)descriptor.Address.Address, address)); } }
static public void WriteRegister(ONIXDeviceDescriptor descriptor, uint address, uint value) { using (var c = ONIContextManager.ReserveContext(descriptor.Address.HardwareSlot)) { c.Context.WriteRegister((uint)descriptor.Address.Address, address, value); } }
public I2CConfiguration(ONIDeviceAddress address, DeviceID id, uint i2cAddress) { Valid = ONIXDeviceDescriptor.IsValid(id, address); context = ONIContextManager.ReserveContext(address.HardwareSlot); deviceAddress = address.Address; I2CAddress = i2cAddress; #if DEBUG Console.WriteLine("I2C context reserved by " + this.GetType()); #endif }
public IObservable <TSource> Process(IObservable <TSource> source) { return(Observable.Using( cancellationToken => ONIContextManager.ReserveOpenContextAsync(DeviceAddress.HardwareSlot), (contextDisposable, cancellationToken) => { return ONIXDeviceDescriptor.IsValid(ID, DeviceAddress) ? Task.FromResult(source .Do(input => { OnNext(contextDisposable.Context, input); }) .Finally(() => OnFinally(contextDisposable.Context))) : throw new WorkflowException("Selected device address is invalid."); } )); }
protected void WriteRegister(uint address, uint value, bool silent = true) { // NB: This is a redundant check but is here even throwing and catching within the // function body results in a huge UI performance hit. if (silent && !ONIXDeviceDescriptor.IsValid(ID, DeviceAddress)) { Console.Error.WriteLine("Register write was attempted with an invalid device " + "descriptor. Device ID: " + ID + ", Address: " + DeviceAddress.ToString() + "."); } try { WriteRegister(new ONIXDeviceDescriptor(ID, DeviceAddress), address, value); } catch (Exception ex) when(silent && (ex is ArgumentException || ex is oni.ONIException)) { System.Console.Error.WriteLine(ex.Message); } }