public static YCurrentProxy FindCurrent(string name) { // cases to handle: // name ="" no matching unknwn // name ="" unknown exists // name != "" no matching unknown // name !="" unknown exists YCurrent func = null; YCurrentProxy res = (YCurrentProxy)YFunctionProxy.FindSimilarUnknownFunction("YCurrentProxy"); if (name == "") { if (res != null) { return(res); } res = (YCurrentProxy)YFunctionProxy.FindSimilarKnownFunction("YCurrentProxy"); if (res != null) { return(res); } func = YCurrent.FirstCurrent(); if (func != null) { name = func.get_hardwareId(); if (func.get_userData() != null) { return((YCurrentProxy)func.get_userData()); } } } else { func = YCurrent.FindCurrent(name); if (func.get_userData() != null) { return((YCurrentProxy)func.get_userData()); } } if (res == null) { res = new YCurrentProxy(func, name); } if (func != null) { res.linkToHardware(name); if (func.isOnline()) { res.arrival(); } } return(res); }
/** * <summary> * Enumerates all functions of type Current available on the devices * currently reachable by the library, and returns their unique hardware ID. * <para> * Each of these IDs can be provided as argument to the method * <c>YCurrent.FindCurrent</c> to obtain an object that can control the * corresponding device. * </para> * </summary> * <returns> * an array of strings, each string containing the unique hardwareId * of a device function currently connected. * </returns> */ public static new string[] GetSimilarFunctions() { List <string> res = new List <string>(); YCurrent it = YCurrent.FirstCurrent(); while (it != null) { res.Add(it.get_hardwareId()); it = it.nextCurrent(); } return(res.ToArray()); }
public override async Task <int> Run() { try { await YAPI.RegisterHub(HubURL); YCurrent sensor; YCurrent sensorDC = null; YCurrent sensorAC = null; if (Target.ToLower() == "any") { // retreive any voltage sensor (can be AC or DC) sensor = YCurrent.FirstCurrent(); if (sensor == null) { WriteLine("No module connected"); return(-1); } Target = await(await sensor.get_module()).get_serialNumber(); } WriteLine("using " + Target); // we need to retreive both DC and AC from the device. sensorDC = YCurrent.FindCurrent(Target + ".current1"); sensorAC = YCurrent.FindCurrent(Target + ".current2"); while (await sensorDC.isOnline()) { Write("DC: " + await sensorDC.get_currentValue() + " mA / "); WriteLine("AC: " + await sensorAC.get_currentValue() + " mA "); await YAPI.Sleep(1000); } WriteLine("Module not connected (check identification and USB cable)"); } catch (YAPI_Exception ex) { WriteLine("error: " + ex.Message); } YAPI.FreeAPI(); return(0); }
static void Main(string[] args) { string errmsg = ""; string target; YCurrent sensor; YCurrent sensorDC = null; YCurrent sensorAC = null; YModule m = null; if (args.Length < 1) { usage(); } target = args[0].ToUpper(); // Setup the API to use local USB devices if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } if (target == "ANY") { // retreive any voltage sensor (can be AC or DC) sensor = YCurrent.FirstCurrent(); if (sensor == null) { die("No module connected"); } } else { sensor = YCurrent.FindCurrent(target + ".current1"); } // we need to retreive both DC and AC voltage from the device. if (sensor.isOnline()) { m = sensor.get_module(); sensorDC = YCurrent.FindCurrent(m.get_serialNumber() + ".current1"); sensorAC = YCurrent.FindCurrent(m.get_serialNumber() + ".current2"); } else { die("Module not connected"); } if (!m.isOnline()) { die("Module not connected"); } while (m.isOnline()) { Console.Write("DC: " + sensorDC.get_currentValue().ToString() + " mA "); Console.Write("AC: " + sensorAC.get_currentValue().ToString() + " mA "); Console.WriteLine(" (press Ctrl-C to exit)"); YAPI.Sleep(1000, ref errmsg); } YAPI.FreeAPI(); }
// Token: 0x06000002 RID: 2 RVA: 0x000020B8 File Offset: 0x000002B8 private void startBtn_Click(object sender, EventArgs e) { if (this.startBtn.Text.Equals("Start")) { this.remainTime.Text = ""; this.logVolAl.Clear(); this.logCurrAl.Clear(); this.cSum = 0.0; this.vSum = 0.0; this.ccount = 0; if (this.intervalTB.Text.Trim().Equals("")) { MessageBox.Show("Please insert interval time.", "Warning"); return; } if (this.testTimeTB.Text.Trim().Equals("")) { MessageBox.Show("Please insert test time.", "Warning"); return; } try { this.timer1.Interval = Convert.ToInt32(this.intervalTB.Text.Trim()); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error(Interval Time)"); return; } try { this.timeCount = Convert.ToInt32(this.testTimeTB.Text.Trim()); } catch (Exception ex2) { MessageBox.Show(ex2.Message, "Error(Test Time)"); return; } this.voltageSensor = YVoltage.FirstVoltage(); if (this.voltageSensor == null || !this.voltageSensor.isOnline()) { MessageBox.Show("Voltage module not connected.", "Error"); return; } this.m = this.voltageSensor.get_module(); this.voltageSensorDC = YVoltage.FindVoltage(this.m.get_serialNumber() + ".voltage1"); this.m = null; this.currentSensor = YCurrent.FirstCurrent(); if (this.currentSensor != null && this.currentSensor.isOnline()) { this.m = this.currentSensor.get_module(); this.currentSensorDC = YCurrent.FindCurrent(this.m.get_serialNumber() + ".current1"); this.m = null; this.startBtn.Text = "Stop"; this.timer1.Enabled = true; this.timer2.Enabled = true; this.remainTime.Visible = true; this.intervalTB.Enabled = false; this.testTimeTB.Enabled = false; return; } MessageBox.Show("Current module not connected.", "Error"); return; } else { this.timer1.Enabled = false; this.timer2.Enabled = false; this.remainTime.Visible = false; this.intervalTB.Enabled = true; this.testTimeTB.Enabled = true; this.startBtn.Text = "Start"; } }