private static string GetLastExceptionMessage(short handle) { TC08DeviceImports.ErrorCode error = (TC08DeviceImports.ErrorCode)TC08DeviceImports.GetLastError(handle); switch (error) { case TC08DeviceImports.ErrorCode.USBTC08_ERROR_OK: return("No error occurred."); case TC08DeviceImports.ErrorCode.USBTC08_ERROR_OS_NOT_SUPPORTED: return("The driver supports Windows XP SP2 or later, Windows Vista, and Windows 7."); case TC08DeviceImports.ErrorCode.USBTC08_ERROR_NO_CHANNELS_SET: return("A call to usb_tc08_set_channel is required."); case TC08DeviceImports.ErrorCode.USBTC08_ERROR_INVALID_PARAMETER: return("One or more of the function arguments were invalid."); case TC08DeviceImports.ErrorCode.USBTC08_ERROR_VARIANT_NOT_SUPPORTED: return("The hardware version is not supported. Download the latest driver."); case TC08DeviceImports.ErrorCode.USBTC08_ERROR_INCORRECT_MODE: return ("An incompatible mix of legacy and non-legacy functions was called (or usb_tc08_get_single was called while in streaming mode.)"); case TC08DeviceImports.ErrorCode.USBTC08_ERROR_ENUMERATION_INCOMPLETE: return("usb_tc08_open_unit_async was called again while a background enumeration was already in progress."); case TC08DeviceImports.ErrorCode.USBTC08_ERROR_NOT_RESPONDING: return("Cannot get a reply from a USB TC-08."); case TC08DeviceImports.ErrorCode.USBTC08_ERROR_FW_FAIL: return("Unable to download firmware."); case TC08DeviceImports.ErrorCode.USBTC08_ERROR_CONFIG_FAIL: return("Missing or corrupted EEPROM."); case TC08DeviceImports.ErrorCode.USBTC08_ERROR_NOT_FOUND: return("Cannot find enumerated device."); case TC08DeviceImports.ErrorCode.USBTC08_ERROR_THREAD_FAIL: return("A threading function failed."); case TC08DeviceImports.ErrorCode.USBTC08_ERROR_PIPE_INFO_FAIL: return("Can not get USB pipe information."); case TC08DeviceImports.ErrorCode.USBTC08_ERROR_NOT_CALIBRATED: return("No calibration date was found."); case TC08DeviceImports.ErrorCode.USBTC08_ERROR_PICOPP_TOO_OLD: return("An old picopp.sys driver was found on the system."); case TC08DeviceImports.ErrorCode.USBTC08_ERROR_COMMUNICATION: return("The PC has lost communication with the device."); default: return("Unknown Error"); } }
/// <summary> /// Called when a device closes and wants to notify the device manager /// </summary> /// <param name="handle">The handle.</param> private void OnClosed(short handle) { Trace.WriteLine("Device " + handle + " closed"); TC08DeviceImports.CloseUnit(handle); TC08Device device; _openDevices.TryRemove(handle, out device); }
private void SetChannel(int channel, char thermoType) { short result = TC08DeviceImports.SetChannel(Handle, (short)channel, thermoType); if (result == 0) { throw new TC08Exception(result); } }
/// <summary> /// Configures the device to capture. /// </summary> public void Configure() { TC08DeviceImports.SetRejectionFreq(Handle, (short)FrequencyRejection); for (int i = 1; i < TC08MaxChannels + 1; i++) { TC08ChannelConfig found = EnabledChannels.FirstOrDefault(dev => dev.Number == i); SetChannel(i, found != null ? found.ThermoType : ' '); } }
/// <summary> /// Checks for new devices. /// </summary> /// <returns></returns> private IEnumerable <TC08Device> CheckForNewDevices() { short handle = 0; while ((handle = TC08DeviceImports.OpenUnit()) > 0) { TC08Device device = new TC08Device(handle, OnClosed); Trace.WriteLine("Device Found - \r\n" + device.DeviceInfo); yield return(device); } }
/// <summary> /// Devices poll to detect disconnect /// </summary> private void DevicePollOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs) { TC08DeviceImports.SetChannel(Handle, 0, 'X'); short error = TC08DeviceImports.GetLastError(Handle); if (error > 6 && Connected) { Connected = false; _devicePoll.Stop(); _onClosed(Handle); } }
public TC08Device(short handle, Action <short> onClosed) { Handle = handle; _onClosed = onClosed; StringBuilder builder = new StringBuilder(TC08MaxInfoLength); TC08DeviceImports.GetFormattedInfo(Handle, builder, TC08MaxInfoLength); DeviceInfo = builder.ToString(); EnabledChannels = new List <TC08ChannelConfig>(); _devicePoll = new Timer(2222); _devicePoll.Elapsed += DevicePollOnElapsed; _devicePoll.Start(); Connected = true; }
/// <summary> /// Gets the temperature values. /// </summary> /// <param name="unit">The temperature unit.</param> /// <returns></returns> /// <exception cref="TC08Exception"></exception> public unsafe float[] GetValues(TC08DeviceImports.TempUnit unit) { float[] data = new float[9]; short overflows; short result = TC08DeviceImports.GetSingle(Handle, data, &overflows, unit); if (result == 0) { throw new TC08Exception(result); } for (int i = 0; i < data.Length; i++) { data[i] = (float)Math.Round(data[i], 2); } return(data); }