public static uint InitInpOutDriver() { uint nResult = 0; try { try { Console.WriteLine("load 32 driver"); // 打开32位驱动,如果失败了,会引发异常,再加载64位驱动 nResult = IT8786GPIO.IsInpOutDriverOpen(); Console.WriteLine("nResult1: " + nResult); } catch (BadImageFormatException) { Console.WriteLine("load 64 driver"); nResult = IT8786GPIO.IsInpOutDriverOpen_x64(); if (nResult != 0) { m_bX64 = true; } Console.WriteLine("nResult2: " + nResult); } return(nResult); } catch (DllNotFoundException ex) // dll查找是失败异常 { Console.WriteLine("异常:" + ex.Message); return(nResult); } }
private void ReadGPIOAttr() { short c = IT8786GPIO.ReadGpioMode(); lab_mode.Text = "GPIO MODE:" + Convert.ToInt32(c).ToString("X2"); short c1 = IT8786GPIO.ReadGpioVal(); lab_val.Text = "GPIO VALUE:" + Convert.ToInt32(c1).ToString("X2"); Console.WriteLine(lab_mode.Text + "----" + lab_val.Text); }
private void btn_mode_Click(object sender, EventArgs e) { try { short iData = Convert.ToInt16(gp_mode.Text.Trim(), 16); Console.WriteLine("gpio mode:" + iData); IT8786GPIO.SetGpioMode(iData); ReadGPIOAttr(); gp_mode.Text = ""; } catch (Exception ex) { MessageBox.Show("An error occured:\n" + ex.Message); } }
public Form1() { InitializeComponent(); uint nResult = IT8786GPIO.InitInpOutDriver(); if (nResult == 0) { label4.Text = "Unable to open InpOut driver."; label4.ForeColor = System.Drawing.Color.Red; btn_mode.Enabled = false; btn_gpio.Enabled = false; } else { label4.Text = "Load InpOut driver successfully."; IT8786GPIO.InitGPIO(); ReadGPIOAttr(); } }
private void Form1_FormClosed(object sender, FormClosedEventArgs e) { IT8786GPIO.FreeGPIO(); }