Beispiel #1
0
        static void Main(string[] args)
        {
            string   errmsg = "";
            string   target;
            YVoltage sensor;
            YVoltage sensorDC = null;
            YVoltage 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 = YVoltage.FirstVoltage();
                if (sensor == null)
                {
                    die("No module connected");
                }
            }
            else
            {
                sensor = YVoltage.FindVoltage(target + ".voltage1");
            }

            // we need to retreive both DC and AC voltage from the device.
            if (sensor.isOnline())
            {
                m        = sensor.get_module();
                sensorDC = YVoltage.FindVoltage(m.get_serialNumber() + ".voltage1");
                sensorAC = YVoltage.FindVoltage(m.get_serialNumber() + ".voltage2");
            }
            else
            {
                die("Module not connected");
            }

            while (m.isOnline())
            {
                Console.Write("DC: " + sensorDC.get_currentValue().ToString() + " v ");
                Console.Write("AC: " + sensorAC.get_currentValue().ToString() + " v ");

                Console.WriteLine("  (press Ctrl-C to exit)");

                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
        public static YVoltageProxy FindVoltage(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YVoltage      func = null;
            YVoltageProxy res  = (YVoltageProxy)YFunctionProxy.FindSimilarUnknownFunction("YVoltageProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YVoltageProxy)YFunctionProxy.FindSimilarKnownFunction("YVoltageProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YVoltage.FirstVoltage();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YVoltageProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YVoltage.FindVoltage(name);
                if (func.get_userData() != null)
                {
                    return((YVoltageProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YVoltageProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
        /**
         * <summary>
         *   Enumerates all functions of type Voltage 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>YVoltage.FindVoltage</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>();
            YVoltage      it  = YVoltage.FirstVoltage();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextVoltage();
            }
            return(res.ToArray());
        }
Beispiel #4
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YVoltage sensor;
                YVoltage sensorDC = null;
                YVoltage sensorAC = null;

                if (Target.ToLower() == "any")
                {
                    // retreive any voltage sensor (can be AC or DC)
                    sensor = YVoltage.FirstVoltage();
                    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 voltage from the device.
                sensorDC = YVoltage.FindVoltage(Target + ".voltage1");
                sensorAC = YVoltage.FindVoltage(Target + ".voltage2");

                while (await sensorDC.isOnline())
                {
                    Write("DC: " + await sensorDC.get_currentValue() + " v ");
                    WriteLine("AC: " + await sensorAC.get_currentValue() + " v ");
                    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);
        }
Beispiel #5
0
 // 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";
     }
 }