public void Dispose() { try { IsReady = false; if (_workerThread.IsAlive) { _workerThread.Abort(); } _device.Close(); _device.Dispose(); _device = null; } catch (Exception e) { Log.Exception(e); } finally { } }
public UsbFmTmcReader() { _device = USBRadioDevice.FindDevice(PID, VID); _device.PropertyChanged += (s, e) => { if (e.PropertyName == "RDS" && _device.RDS != null) { _device.RDS.PropertyChanged += (s1, e1) => { if (e1.PropertyName == "TMC") { if (TmcTransmissionArrived != null) { TmcTransmissionArrived(this, new TmcTransmissionArrivedEventArgs( _device.Registers[USBFM.USBRDSDeviceMethods.Native.RDSB], _device.Registers[USBFM.USBRDSDeviceMethods.Native.RDSC], _device.Registers[USBFM.USBRDSDeviceMethods.Native.RDSD])); } } }; } }; }
internal static ushort FromFrequency(this double frequency, USBRadioDevice device) { double band = (device.Registers[Native.SYSCONFIG2] & Native.SYSCONFIG2_BAND) != 0 ? 76 : 87.5, spacing = 0.2; switch (device.Registers[Native.SYSCONFIG2] & Native.SYSCONFIG2_SPACE) { case Native.SYSCONFIG2_SPACE_200KHZ: spacing = 0.2; break; case Native.SYSCONFIG2_SPACE_100KHZ: spacing = 0.1; break; case Native.SYSCONFIG2_SPACE_50KHZ: spacing = 0.05; break; } return (ushort)(((frequency - band) / spacing) + .0001); }
internal static double ToFrequency(this ushort channel, USBRadioDevice device) { double frequency = 0; double band = 87.5, spacing = 0.2; //Determine the band and spacing band = (device.Registers[Native.SYSCONFIG2] & Native.SYSCONFIG2_BAND) != 0 ? 76 : 87.5; switch (device.Registers[Native.SYSCONFIG2] & Native.SYSCONFIG2_SPACE) { case Native.SYSCONFIG2_SPACE_200KHZ: spacing = 0.2; break; case Native.SYSCONFIG2_SPACE_100KHZ: spacing = 0.1; break; case Native.SYSCONFIG2_SPACE_50KHZ: spacing = 0.05; break; } //Calculate the frequency and add .0001 to round up numbers not quite close enough to the frequency frequency = (int)(((band + (spacing * channel)) + .0001) * 100.0) / 100.0; return frequency; }