public static void Main() { // Print library information: PrintInfo.PrintLibraryInfo(); // Enable network search: Network.AutoDetectEnabled = true; // Update device list: DeviceList.Update(); // Try to open an I2C host: I2CHost I2C = null; for (UInt32 i = 0; i < DeviceList.Count; i++) { DeviceListItem item = DeviceList.GetItemByIndex(i); if (item.CanOpen(DeviceType.I2CHost)) { I2C = item.OpenI2CHost(); break; } } if (I2C != null) { try { // Print I2C host info: PrintInfo.PrintDeviceInfo(I2C); // Turn on internal reference for DAC A: I2C.WriteByteWord(AD5667_ADDRESS, AD5667_CMD_REF_SETUP | AD5567_REG_DAC_A, 1); // Set DAC A to mid level: I2C.WriteByteWord(AD5667_ADDRESS, AD5667_CMD_WRITE_UPDATE | AD5567_REG_DAC_A, 0x8000); } catch (System.Exception e) { Console.WriteLine("Exception: " + e.Message); Environment.Exit(1); } // Close I2C host: I2C.Dispose(); I2C = null; } else { Console.WriteLine("No I2C host available!"); Environment.Exit(1); } System.Environment.Exit(0); }
public static void PrintI2CInfo(I2CHost i2c) { try { Console.WriteLine("I2C Host:"); Console.WriteLine(" Internal addresses : " + String.Join(", ", Array.ConvertAll(i2c.InternalAddresses, x => x.ToString()))); Console.WriteLine(" Speed max : " + i2c.SpeedMax.ToString()); Console.WriteLine(" Speed : " + i2c.Speed.ToString()); PrintTriggerInputsInfo(i2c.TriggerInputs); PrintTriggerOutputsInfo(i2c.TriggerOutputs); } catch (System.Exception e) { Console.WriteLine("Exception: " + e.Message); } }
public static void PrintDeviceInfo(Device dev) { try { Console.WriteLine("Device:"); Console.WriteLine(" Name : " + dev.Name); Console.WriteLine(" Short name : " + dev.NameShort); Console.WriteLine(" Serial number : " + dev.SerialNumber.ToString()); try { Console.WriteLine(" Calibration date : " + dev.CalibrationDate); } catch (System.Exception) { } Console.WriteLine(" Product id : " + dev.ProductId.ToString()); Console.WriteLine(" Vendor id : " + dev.VendorId.ToString()); try { Console.WriteLine(" Driver version : " + dev.DriverVersion.ToString()); } catch (System.Exception) { } try { Console.WriteLine(" Firmware version : " + dev.FirmwareVersion.ToString()); } catch (System.Exception) { } try { Console.WriteLine(" IPv4 address : " + dev.IPv4Address.ToString()); } catch (System.Exception) { } try { Console.WriteLine(" IP port : " + dev.IPPort.ToString()); } catch (System.Exception) { } Console.WriteLine(" Has battery : " + dev.HasBattery.ToString()); if (dev.HasBattery) { Console.WriteLine(" Battery:"); try { Console.WriteLine(" Charge : " + dev.BatteryCharge.ToString() + " %"); } catch (System.Exception) { } try { Console.WriteLine(" Time to empty : " + dev.BatteryTimeToEmpty.ToString() + " minutes"); } catch (System.Exception) { } try { Console.WriteLine(" Time to full : " + dev.BatteryTimeToFull.ToString() + " minutes"); } catch (System.Exception) { } try { Console.WriteLine(" Charger connected : " + dev.IsBatteryChargerConnected.ToString()); } catch (System.Exception) { } try { Console.WriteLine(" Charging : " + dev.IsBatteryCharging.ToString()); } catch (System.Exception) { } try { Console.WriteLine(" Broken : " + dev.IsBatteryBroken.ToString()); } catch (System.Exception) { } } Oscilloscope scp = dev as Oscilloscope; if (scp != null) { PrintOscilloscopeInfo(scp); } Generator gen = dev as Generator; if (gen != null) { PrintGeneratorInfo(gen); } I2CHost i2c = dev as I2CHost; if (i2c != null) { PrintI2CInfo(i2c); } } catch (System.Exception e) { Console.WriteLine("Exception: " + e.Message); } }