コード例 #1
0
ファイル: YCurrent.cs プロジェクト: jiachengx/ironmen2020
    // Token: 0x0600010B RID: 267 RVA: 0x00006C88 File Offset: 0x00004E88
    public static YCurrent FirstCurrent()
    {
        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("Current", 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(YCurrent.FindCurrent(serial + "." + funcId));
    }
コード例 #2
0
ファイル: Demo.cs プロジェクト: yoctopuce/yoctolib_uwp
        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);
        }
コード例 #3
0
        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YCurrent hwd = YCurrent.FindCurrent(hwdName);

            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }
コード例 #4
0
 // perform the 2nd stage setup that requires YoctoAPI object
 protected void init(YCurrent hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering Current callback");
     _func.registerValueCallback(valueChangeCallback);
 }
コード例 #5
0
ファイル: YCurrent.cs プロジェクト: jiachengx/ironmen2020
    // Token: 0x0600010A RID: 266 RVA: 0x00006C48 File Offset: 0x00004E48
    public static YCurrent FindCurrent(string func)
    {
        if (YCurrent._CurrentCache.ContainsKey(func))
        {
            return((YCurrent)YCurrent._CurrentCache[func]);
        }
        YCurrent res = new YCurrent(func);

        YCurrent._CurrentCache.Add(func, res);
        return(res);
    }
コード例 #6
0
        /**
         * <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());
        }
コード例 #7
0
        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);
        }
コード例 #8
0
    /**
     * <summary>
     *   Retrieves a current 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 current sensor is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YCurrent.isOnline()</c> to test if the current sensor is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a current 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 current sensor
     * </param>
     * <returns>
     *   a <c>YCurrent</c> object allowing you to drive the current sensor.
     * </returns>
     */
    public static YCurrent FindCurrent(string func)
    {
        YCurrent obj;

        obj = (YCurrent)YFunction._FindFromCache("Current", func);
        if (obj == null)
        {
            obj = new YCurrent(func);
            YFunction._AddToCache("Current", func, obj);
        }
        return(obj);
    }
コード例 #9
0
ファイル: YCurrent.cs プロジェクト: jiachengx/ironmen2020
    // Token: 0x06000105 RID: 261 RVA: 0x00006BBC File Offset: 0x00004DBC
    public YCurrent nextCurrent()
    {
        string hwid = "";

        if (YAPI.YISERR(base._nextFunction(ref hwid)))
        {
            return(null);
        }
        if (hwid == "")
        {
            return(null);
        }
        return(YCurrent.FindCurrent(hwid));
    }
コード例 #10
0
ファイル: Demo.cs プロジェクト: yoctopuce/yoctolib_uwp
        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);
        }
コード例 #11
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();
        }
コード例 #12
0
 // --- (end of YCurrent implementation)
 // --- (Current functions)
 /**
    * <summary>
    *   Retrieves a current 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 current sensor is online at the time
    *   it is invoked. The returned object is nevertheless valid.
    *   Use the method <c>YCurrent.isOnline()</c> to test if the current sensor is
    *   indeed online at a given time. In case of ambiguity when looking for
    *   a current 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 current sensor
    * </param>
    * <returns>
    *   a <c>YCurrent</c> object allowing you to drive the current sensor.
    * </returns>
    */
 public static YCurrent FindCurrent(string func)
 {
     YCurrent res;
     if (_CurrentCache.ContainsKey(func))
       return (YCurrent)_CurrentCache[func];
     res = new YCurrent(func);
     _CurrentCache.Add(func, res);
     return res;
 }
コード例 #13
0
ファイル: main.cs プロジェクト: yoctopuce/yoctolib_cs
        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();
        }
コード例 #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";
     }
 }
コード例 #15
0
 /**
  * <summary>
  *   Retrieves a current 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 current sensor is online at the time
  *   it is invoked. The returned object is nevertheless valid.
  *   Use the method <c>YCurrent.isOnline()</c> to test if the current sensor is
  *   indeed online at a given time. In case of ambiguity when looking for
  *   a current 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 current sensor
  * </param>
  * <returns>
  *   a <c>YCurrent</c> object allowing you to drive the current sensor.
  * </returns>
  */
 public static YCurrent FindCurrent(string func)
 {
     YCurrent obj;
     obj = (YCurrent) YFunction._FindFromCache("Current", func);
     if (obj == null) {
         obj = new YCurrent(func);
         YFunction._AddToCache("Current", func, obj);
     }
     return obj;
 }
コード例 #16
0
ファイル: Form1.cs プロジェクト: yoctopuce/yoctolib_cs
        private void refreshUI()
        { // draw  the dial.
            double value = -5;
            bool   on    = false;

            if (comboBox1.Enabled)
            { // if a yocto-amp device is connected, lets check it value
                YModule  m  = (YModule)comboBox1.Items[comboBox1.SelectedIndex];
                YCurrent DC = YCurrent.FindCurrent(m.get_serialNumber() + ".current1");
                YCurrent AC = YCurrent.FindCurrent(m.get_serialNumber() + ".current2");
                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 / 1000) * 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();
        }
コード例 #17
0
 // 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 = (YCurrent)hwd;
     base.base_init(hwd, instantiationName);
 }
コード例 #18
0
        //--- (end of YCurrent definitions)

        //--- (YCurrent implementation)
        internal YCurrentProxy(YCurrent hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("Current " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }