/// <summary> /// Store the passed in "boot vars" as the system's current "boot vars". /// </summary> /// <param name="bootVars"></param> internal static void Save(BootVars bootVars) { bool success = false; try { unsafe { success = bootvars_write(ref bootVars); // Will set LastError on failure. } if (!success) { int lastError = WinCeApi.GetLastError(); throw new ConfigurationException(string.Format("Error {0} writing BootVars", lastError)); } } catch (ConfigurationException) { throw; } catch (Exception ex) { throw new ConfigurationException("Error writing BootVars", ex); } finally { bootvars_deinit(); } }
/// <summary> /// Checks a given pressure switch and returns. /// </summary> /// <param name="position">The position of the switch to check</param> /// <returns>True, if the pressure is good</returns> public static bool CheckPressureSwitch(int position) { if (!IsPressureSwitchPresent(position)) { return(true); } int success = 0; ushort data = 0; for (int attempt = 1; attempt <= 10; attempt++) { unsafe { success = GetPressureSwitchState(Convert.ToByte(position), &data); // returns 1 on success, 0 on error } if (success != 0) // success? { break; } Log.Error(string.Format("Error calling GetPressureSwitchState({0}), attempt {1}, GetLastError={2}", position, attempt, WinCeApi.GetLastError())); Thread.Sleep(100); } if (success == 0) // error? { int lastError = WinCeApi.GetLastError(); Log.Error(string.Format("Failure in GetPressureSwitchState({0}), GetLastError={1}", position, lastError)); throw new DeviceDriverException(DeviceHardware.PressureSwitchState, position, lastError); } return(data == 0); }
/// <summary> /// Return the system's current "boot vars" /// </summary> /// <returns></returns> static internal BootVars Load() { BootVars bootVars = new BootVars(); bool success = false; try { unsafe { success = bootvars_read(ref bootVars); // Will set LastError on failure. } if (!success) { int lastError = WinCeApi.GetLastError(); throw new ConfigurationException(string.Format("Error {0} reading BootVars", lastError)); } } catch (ConfigurationException) { throw; } catch (Exception ex) { throw new ConfigurationException("Error reading BootVars", ex); } finally { bootvars_deinit(); } return(bootVars); }
/// <summary> /// Returns a value indicating whether there is smart card present in a given slot. /// </summary> /// <param name="position">The card slot number</param> /// <returns>True if there is a card in the slot, 0 if not.</returns> public static bool IsCardPresent(int position) { ushort data = 0; int error = 0; for (int attempt = 1; attempt <= 10; attempt++) { unsafe { error = GetSmartCardPresence(Convert.ToByte(position), &data); // returns 1 on error, 0 on success } if (error == 0) // success? { break; } Log.Error(string.Format("Error calling GetSmartCardPresence({0}), attempt {1}, GetLastError={2}", position, attempt, WinCeApi.GetLastError())); Thread.Sleep(100); } if (error != 0) // error? { int lastError = WinCeApi.GetLastError(); Log.Error(string.Format("Failure in GetSmartCardPresence({0}), GetLastError={1}", position, lastError)); throw new DeviceDriverException(DeviceHardware.SmartCardPresence, position, lastError); } return(data != 0); }