// perform the 2nd stage setup that requires YoctoAPI object
 protected void init(YWeighScale hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering WeighScale callback");
     _func.registerValueCallback(valueChangeCallback);
 }
예제 #2
0
        private async void onLoad(object sender, RoutedEventArgs e)
        {
            try {
                await YAPI.RegisterHub("usb");

                sensor = YWeighScale.FirstWeighScale();
                if (sensor == null)
                {
                    await FatalError("No WeighScale connected");
                }

                display = YDisplay.FirstDisplay();
                if (display != null)
                {
                    //clean up
                    await display.resetAll();

                    // retreive the display size
                    w = await display.get_displayWidth();

                    h = await display.get_displayHeight();

                    // reteive the first layer
                    l0 = await display.get_displayLayer(0);

                    l1 = await display.get_displayLayer(1);

                    // display a text in the middle of the screen
                    await l0.selectFont("Large.yfm");
                }
                await sensor.set_excitation(YWeighScale.EXCITATION_AC);

                await YAPI.Sleep(3000);

                await sensor.tare();

                unit = await sensor.get_unit();

                await sensor.registerValueCallback(sensorValueChangeCallBack);
            } catch (YAPI_Exception ex) {
                await FatalError(ex.Message);
            }

            timer          = new NonReentrantDispatcherTimer();
            timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
            timer.TickTask = async() => { await dispatcherTimer_Tick(); };
            timer.Start();
        }