Example #1
0
    // Token: 0x06000129 RID: 297 RVA: 0x000073C4 File Offset: 0x000055C4
    public static YVoltage FirstVoltage()
    {
        int[]  v_fundescr = new int[1];
        int    dev        = 0;
        int    neededsize = 0;
        string serial     = null;
        string funcId     = null;
        string funcName   = null;
        string funcVal    = null;
        string errmsg     = "";
        int    size       = Marshal.SizeOf(v_fundescr[0]);
        IntPtr p          = Marshal.AllocHGlobal(Marshal.SizeOf(v_fundescr[0]));
        int    err        = YAPI.apiGetFunctionsByClass("Voltage", 0, p, size, ref neededsize, ref errmsg);

        Marshal.Copy(p, v_fundescr, 0, 1);
        Marshal.FreeHGlobal(p);
        if (YAPI.YISERR(err) | neededsize == 0)
        {
            return(null);
        }
        serial   = "";
        funcId   = "";
        funcName = "";
        funcVal  = "";
        errmsg   = "";
        if (YAPI.YISERR(YAPI.yapiGetFunctionInfo(v_fundescr[0], ref dev, ref serial, ref funcId, ref funcName, ref funcVal, ref errmsg)))
        {
            return(null);
        }
        return(YVoltage.FindVoltage(serial + "." + funcId));
    }
Example #2
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();
        }
        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YVoltage hwd = YVoltage.FindVoltage(hwdName);

            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }
Example #4
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YMotor       motor;
                YCurrent     current;
                YVoltage     voltage;
                YTemperature temperature;

                if (Target.ToLower() == "any")
                {
                    // find the serial# of the first available motor
                    motor = YMotor.FirstMotor();
                    if (motor == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }

                    Target = await(await motor.get_module()).get_serialNumber();
                }

                int power = Convert.ToInt32(Power);
                motor       = YMotor.FindMotor(Target + ".motor");
                current     = YCurrent.FindCurrent(Target + ".current");
                voltage     = YVoltage.FindVoltage(Target + ".voltage");
                temperature = YTemperature.FindTemperature(Target + ".temperature");

                // lets start the motor
                if (await motor.isOnline())
                {
                    // if motor is in error state, reset it.
                    if (await motor.get_motorStatus() >= YMotor.MOTORSTATUS_LOVOLT)
                    {
                        await motor.resetStatus();
                    }

                    await motor.drivingForceMove(power, 2000); // ramp up to power in 2 seconds

                    while (await motor.isOnline())
                    {
                        // display motor status
                        WriteLine("Status=" + await motor.get_advertisedValue() + "  "
                                  + "Voltage=" + await voltage.get_currentValue() + "V  "
                                  + "Current=" + await current.get_currentValue() / 1000 + "A  "
                                  + "Temp=" + await temperature.get_currentValue() + "deg C");
                        await YAPI.Sleep(1000); // wait for one second
                    }
                }
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
 // perform the 2nd stage setup that requires YoctoAPI object
 protected void init(YVoltage hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering Voltage callback");
     _func.registerValueCallback(valueChangeCallback);
 }
Example #6
0
    // Token: 0x06000128 RID: 296 RVA: 0x00007384 File Offset: 0x00005584
    public static YVoltage FindVoltage(string func)
    {
        if (YVoltage._VoltageCache.ContainsKey(func))
        {
            return((YVoltage)YVoltage._VoltageCache[func]);
        }
        YVoltage res = new YVoltage(func);

        YVoltage._VoltageCache.Add(func, res);
        return(res);
    }
Example #7
0
    /**
     * <summary>
     *   Retrieves a voltage sensor for a given identifier.
     * <para>
     *   The identifier can be specified using several formats:
     * </para>
     * <para>
     * </para>
     * <para>
     *   - FunctionLogicalName
     * </para>
     * <para>
     *   - ModuleSerialNumber.FunctionIdentifier
     * </para>
     * <para>
     *   - ModuleSerialNumber.FunctionLogicalName
     * </para>
     * <para>
     *   - ModuleLogicalName.FunctionIdentifier
     * </para>
     * <para>
     *   - ModuleLogicalName.FunctionLogicalName
     * </para>
     * <para>
     * </para>
     * <para>
     *   This function does not require that the voltage sensor is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YVoltage.isOnline()</c> to test if the voltage sensor is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a voltage sensor by logical name, no error is notified: the first instance
     *   found is returned. The search is performed first by hardware name,
     *   then by logical name.
     * </para>
     * </summary>
     * <param name="func">
     *   a string that uniquely characterizes the voltage sensor
     * </param>
     * <returns>
     *   a <c>YVoltage</c> object allowing you to drive the voltage sensor.
     * </returns>
     */
    public static YVoltage FindVoltage(string func)
    {
        YVoltage obj;

        obj = (YVoltage)YFunction._FindFromCache("Voltage", func);
        if (obj == null)
        {
            obj = new YVoltage(func);
            YFunction._AddToCache("Voltage", func, obj);
        }
        return(obj);
    }
        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());
        }
Example #10
0
    // Token: 0x06000123 RID: 291 RVA: 0x000072F8 File Offset: 0x000054F8
    public YVoltage nextVoltage()
    {
        string hwid = "";

        if (YAPI.YISERR(base._nextFunction(ref hwid)))
        {
            return(null);
        }
        if (hwid == "")
        {
            return(null);
        }
        return(YVoltage.FindVoltage(hwid));
    }
Example #11
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);
        }
Example #12
0
        static void Main(string[] args)
        {
            string       errmsg = "";
            string       target;
            int          power;
            YMotor       motor;
            YCurrent     current;
            YVoltage     voltage;
            YTemperature temperature;

            // parse the  command line
            if (args.Length < 2)
            {
                usage();
            }
            target = args[0].ToUpper();
            power  = Convert.ToInt32(args[1]);

            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }
            if (target == "ANY")
            {
                // find the serial# of the first available motor
                motor = YMotor.FirstMotor();
                if (motor == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
                target = motor.get_module().get_serialNumber();
            }

            motor       = YMotor.FindMotor(target + ".motor");
            current     = YCurrent.FindCurrent(target + ".current");
            voltage     = YVoltage.FindVoltage(target + ".voltage");
            temperature = YTemperature.FindTemperature(target + ".temperature");

            // lets start the motor
            if (motor.isOnline())
            {
                // if motor is in error state, reset it.
                if (motor.get_motorStatus() >= YMotor.MOTORSTATUS_LOVOLT)
                {
                    motor.resetStatus();
                }
                motor.drivingForceMove(power, 2000); // ramp up to power in 2 seconds
                while (motor.isOnline())
                {
                    // display motor status
                    Console.WriteLine("Status=" + motor.get_advertisedValue() + "  " +
                                      "Voltage=" + voltage.get_currentValue() + "V  " +
                                      "Current=" + current.get_currentValue() / 1000 + "A  " +
                                      "Temp=" + temperature.get_currentValue() + "deg C");
                    YAPI.Sleep(1000, ref errmsg); // wait for one second
                }
            }
            YAPI.FreeAPI();
        }
Example #13
0
        private void refreshUI()
        { // draw  the dial.
            double value = -5;
            bool   on    = false;

            if (comboBox1.Enabled)
            { // if a yocto-volt device is connected, lets check it value
                YModule  m  = (YModule)comboBox1.Items[comboBox1.SelectedIndex];
                YVoltage DC = YVoltage.FindVoltage(m.get_serialNumber() + ".voltage1");
                YVoltage AC = YVoltage.FindVoltage(m.get_serialNumber() + ".voltage2");
                if (DC.isOnline())
                { // read DC or AC value, according to ACDCcheckBox
                    if (ACDCcheckBox.Checked)
                    {
                        value = 100 * (AC.get_currentValue() / maxvalue);
                    }
                    else
                    {
                        value = 100 * (DC.get_currentValue() / maxvalue);
                    }
                    on = true;
                }
            }

            // lets use a double buffering technique to avoid flickering
            Bitmap   BackBuffer = new Bitmap(on ? Properties.Resources.bg : Properties.Resources.bgoff);
            Graphics buffer     = Graphics.FromImage(BackBuffer);

            buffer.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            int DialWidth  = BackBuffer.Width;
            int DialHeight = BackBuffer.Height;

            // add inertia to the needle
            needleposition = needleposition + (value - needleposition) / 10;

            // make sure une needle won't go off chart
            if (needleposition < -5)
            {
                needleposition = -5;
            }
            if (needleposition > 105)
            {
                needleposition = 105;
            }

            double angle = 3.1416 * (180 - 30 - 120 * (needleposition / 100)) / 180;
            int    x     = Convert.ToInt32(DialWidth / 2 + Math.Cos(angle) * (DialHeight - 15));
            int    y     = Convert.ToInt32(DialHeight * 1.066 - Math.Sin(angle) * (DialHeight - 15));

            // draw the needle shadow
            Pen   shadow = new Pen(Color.FromArgb(16, 0, 0, 00), 3);
            Point point1 = new Point(DialWidth / 2 - 3, DialHeight + 3);
            Point point2 = new Point(Convert.ToInt32(x) - 3, Convert.ToInt32(y) + 3);

            buffer.DrawLine(shadow, point1, point2);

            // draw the needle
            Pen red = new Pen(on ? Color.FromArgb(255, 255, 0, 00) : Color.FromArgb(255, 64, 0, 00), 3);

            point1 = new Point(DialWidth / 2, DialHeight);
            point2 = new Point(Convert.ToInt32(x), Convert.ToInt32(y));
            buffer.DrawLine(red, point1, point2);

            // draw the scale
            FontFamily fontFamily = new FontFamily("Arial");
            Font       font       = new Font(fontFamily, DialHeight / 10, FontStyle.Regular, GraphicsUnit.Pixel);

            buffer.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            SolidBrush solidBrush = new SolidBrush(Color.FromArgb(255, 20, 20, 20));

            for (int i = 0; i <= 10; i++)
            {
                double dvalue = (maxvalue * i / 10);
                angle = 3.1416 * (180 - 30 - 120 * (i / 10.0)) / 180;
                string text = dvalue.ToString();
                SizeF  size = buffer.MeasureString(text, font);
                int    tx   = Convert.ToInt32(DialWidth / 2 + Math.Cos(angle) * DialHeight * 1.01 - size.Width / 2);
                int    ty   = Convert.ToInt32(DialHeight * 1.066 - Math.Sin(angle) * DialHeight * 0.98 - size.Height / 2);
                buffer.DrawString(dvalue.ToString(), font, solidBrush, new PointF(tx, ty));
            }

            Bitmap frame = new Bitmap(Properties.Resources.frame);

            buffer.DrawImage(frame, 0, 0);

            Graphics Viewable = pictureBox1.CreateGraphics();

            // fast rendering
            //Viewable.DrawImageUnscaled(BackBuffer, 0, 0);

            // slower, but pictureBox can be resized, rendering will still be ok,
            // try to respect a 2:1 ratio anyway
            Viewable.DrawImage(BackBuffer, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));

            Viewable.Dispose();
        }
Example #14
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";
     }
 }
Example #15
0
 // --- (end of YVoltage implementation)
 // --- (Voltage functions)
 /**
    * <summary>
    *   Retrieves a voltage sensor for a given identifier.
    * <para>
    *   The identifier can be specified using several formats:
    * </para>
    * <para>
    * </para>
    * <para>
    *   - FunctionLogicalName
    * </para>
    * <para>
    *   - ModuleSerialNumber.FunctionIdentifier
    * </para>
    * <para>
    *   - ModuleSerialNumber.FunctionLogicalName
    * </para>
    * <para>
    *   - ModuleLogicalName.FunctionIdentifier
    * </para>
    * <para>
    *   - ModuleLogicalName.FunctionLogicalName
    * </para>
    * <para>
    * </para>
    * <para>
    *   This function does not require that the voltage sensor is online at the time
    *   it is invoked. The returned object is nevertheless valid.
    *   Use the method <c>YVoltage.isOnline()</c> to test if the voltage sensor is
    *   indeed online at a given time. In case of ambiguity when looking for
    *   a voltage sensor by logical name, no error is notified: the first instance
    *   found is returned. The search is performed first by hardware name,
    *   then by logical name.
    * </para>
    * </summary>
    * <param name="func">
    *   a string that uniquely characterizes the voltage sensor
    * </param>
    * <returns>
    *   a <c>YVoltage</c> object allowing you to drive the voltage sensor.
    * </returns>
    */
 public static YVoltage FindVoltage(string func)
 {
     YVoltage res;
     if (_VoltageCache.ContainsKey(func))
       return (YVoltage)_VoltageCache[func];
     res = new YVoltage(func);
     _VoltageCache.Add(func, res);
     return res;
 }
 /**
  * <summary>
  *   Retrieves a voltage sensor for a given identifier.
  * <para>
  *   The identifier can be specified using several formats:
  * </para>
  * <para>
  * </para>
  * <para>
  *   - FunctionLogicalName
  * </para>
  * <para>
  *   - ModuleSerialNumber.FunctionIdentifier
  * </para>
  * <para>
  *   - ModuleSerialNumber.FunctionLogicalName
  * </para>
  * <para>
  *   - ModuleLogicalName.FunctionIdentifier
  * </para>
  * <para>
  *   - ModuleLogicalName.FunctionLogicalName
  * </para>
  * <para>
  * </para>
  * <para>
  *   This function does not require that the voltage sensor is online at the time
  *   it is invoked. The returned object is nevertheless valid.
  *   Use the method <c>YVoltage.isOnline()</c> to test if the voltage sensor is
  *   indeed online at a given time. In case of ambiguity when looking for
  *   a voltage sensor by logical name, no error is notified: the first instance
  *   found is returned. The search is performed first by hardware name,
  *   then by logical name.
  * </para>
  * </summary>
  * <param name="func">
  *   a string that uniquely characterizes the voltage sensor
  * </param>
  * <returns>
  *   a <c>YVoltage</c> object allowing you to drive the voltage sensor.
  * </returns>
  */
 public static YVoltage FindVoltage(string func)
 {
     YVoltage obj;
     obj = (YVoltage) YFunction._FindFromCache("Voltage", func);
     if (obj == null) {
         obj = new YVoltage(func);
         YFunction._AddToCache("Voltage", func, obj);
     }
     return obj;
 }
 // perform the initial setup that may be done without a YoctoAPI object (hwd can be null)
 internal override void base_init(YFunction hwd, string instantiationName)
 {
     _func = (YVoltage)hwd;
     base.base_init(hwd, instantiationName);
 }
        //--- (end of YVoltage definitions)

        //--- (YVoltage implementation)
        internal YVoltageProxy(YVoltage hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("Voltage " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }