Пример #1
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            //Bind Buttons
            PointButton.StateChange += PointButton_StateChange;
            JoinButton.StateChange  += JoinButton_StateChange;

            //Open ports
            PointButton.Open();
            JoinButton.Open();
            Output.Open();
        }
    // Start is called before the first frame update
    void Start()
    {
        _oscIn  = gameObject.AddComponent <OscIn>();
        _oscOut = gameObject.AddComponent <OscOut>();

        _oscIn.Open(8000);
        _oscOut.Open(8000, "255.255.255.255");


        _oscIn.MapInt("/resetsem", ResetMachine);

        imageHolder.SetActive(false);
        dataNumber.gameObject.SetActive(false);
        scanning.SetActive(false);
        noSampleScanned.SetActive(false);
        introduction.SetActive(true);



        //MicroscopeBackgroundSource.Play();

        ScanButton.DeviceSerialNumber = 523574;
        ScanButton.Channel            = 0;
        ScanButton.IsLocal            = true;
        ScanButton.Attach            += digitalInput_Attach;
        ScanButton.StateChange       += digitalInput_StateChange;

        RFIDMicroscope.DeviceSerialNumber = 453586;
        RFIDMicroscope.Channel            = 0;
        RFIDMicroscope.IsLocal            = true;
        RFIDMicroscope.Attach            += rfid_Attach;
        RFIDMicroscope.Tag     += rfid_Tag;
        RFIDMicroscope.TagLost += rfid_TagLost;


        try
        {
            ScanButton.Open(5000);
            RFIDMicroscope.Open(5000);
        }
        catch (PhidgetException e)
        {
            Debug.Log("Failed: " + e.Message);
        }

        // StartCoroutine(TurnRFIDAntennaOff());
    }
    // Use this for initialization
    void Start()
    {
        // Get the material from the Renderer component
        renderMat = GetComponent <Renderer>().material;

        // Slider 60mm
        // NOTE: *Most* sensor Phidgets need the hub port, channel, hub port device status, and local status defined
        //       order to work. It's probably better to just be safe about it and be explicit for most Phidgets.
        slider                 = new VoltageRatioInput();
        slider.HubPort         = 0;
        slider.Channel         = 0;
        slider.IsHubPortDevice = true;
        slider.IsLocal         = true;
        slider.Attach         += ratioAttachCallback;      // The Attach callback is called when a device successfully attaches to
                                                           // your object after calling open() on it.
        slider.VoltageRatioChange += ratioChangeCallback;  // The Change callback is called when the device registers a change,
                                                           // which is defined by the data interval of the device. This will probably
                                                           // get called really often, so be wary of that.

        // Dial Phidget
        dial                 = new Encoder();
        dial.HubPort         = 1;
        dial.Attach         += encoderAttachCallback;
        dial.PositionChange += encoderChangeCallback;

        // Thumbstick Phidget
        // Y axis
        thumbstickY                     = new VoltageRatioInput();
        thumbstickY.Channel             = 0; // The Y axis is channel 0, which can be found in the Phidget Control Panel
        thumbstickY.HubPort             = 2;
        thumbstickY.Attach             += ratioAttachCallback;
        thumbstickY.VoltageRatioChange += ratioChangeCallback;
        // X axis
        thumbstickX                     = new VoltageRatioInput();
        thumbstickX.Channel             = 1; // The X axis is channel 1, which can be found in the Phidget Control Panel
        thumbstickX.HubPort             = 2;
        thumbstickX.Attach             += ratioAttachCallback;
        thumbstickX.VoltageRatioChange += ratioChangeCallback;
        // Z axis
        thumbstickZ              = new DigitalInput();
        thumbstickZ.HubPort      = 2;
        thumbstickZ.Attach      += digitalAttachCallback;
        thumbstickZ.StateChange += digitalChangeCallback;

        // Rotation Sensor 10-turn
        turn10                     = new VoltageRatioInput();
        turn10.HubPort             = 3;
        turn10.Channel             = 0;
        turn10.IsHubPortDevice     = true;
        turn10.IsLocal             = true;
        turn10.Attach             += ratioAttachCallback;
        turn10.VoltageRatioChange += ratioChangeCallback;

        // Touch Sensor
        touch                     = new VoltageRatioInput();
        touch.HubPort             = 4;
        touch.Channel             = 0;
        touch.IsHubPortDevice     = true;
        touch.IsLocal             = true;
        touch.Attach             += ratioAttachCallback;
        touch.VoltageRatioChange += ratioChangeCallback;

        // Magnetic Sensor
        magnet                     = new VoltageRatioInput();
        magnet.HubPort             = 5;
        magnet.Channel             = 0;
        magnet.IsHubPortDevice     = true;
        magnet.IsLocal             = true;
        magnet.Attach             += ratioAttachCallback;
        magnet.VoltageRatioChange += ratioChangeCallback;

        // Open all of the devices to be attached to by the physical Phidgets.
        // It's not smart to do all of this in one try-catch, but I'm just lazy.
        try
        {
            slider.Open(1000);
            dial.Open(1000);
            thumbstickX.Open(1000);
            thumbstickY.Open(1000);
            thumbstickZ.Open(1000);
            touch.Open(1000);
            turn10.Open(1000);
            magnet.Open(1000);
        }
        catch (PhidgetException e)
        {
            Debug.Log("Failed: " + e.Message);
        }
    }
Пример #4
0
        static void Main(string[] args)
        {
            var greenButton = new DigitalInput();

            greenButton.IsHubPortDevice = true;
            greenButton.HubPort         = 1;

            var greenLed = new DigitalOutput();

            greenLed.IsHubPortDevice = true;
            greenLed.HubPort         = 3;

            var redButton = new DigitalInput();

            redButton.IsHubPortDevice = true;
            redButton.HubPort         = 0;

            var redLed = new DigitalOutput();

            redLed.IsHubPortDevice = true;
            redLed.HubPort         = 2;

            var sonar = new DistanceSensor();

            sonar.HubPort = 4;

            sonar.Open(1000);
            redButton.Open(1000);
            redLed.Open(1000);
            greenButton.Open(1000);
            greenLed.Open(1000);

            greenButton.StateChange += (o, e) =>
            {
                greenLed.State = e.State;
            };

            redButton.StateChange += (o, e) =>
            {
                redLed.State = e.State;

                if (e.State)
                {
                    var sound = new SoundPlayer(@"C:\windows\media\tada.wav");
                    sound.Play();

                    var random = new Random();

                    Console.WriteLine("The next random number is {0}!", random.Next(0, 10));
                }
            };

            sonar.DistanceChange += (o, e) =>
            {
                if (e.Distance > 100)
                {
                    greenLed.State = true;
                    redLed.State   = false;
                }
                else
                {
                    greenLed.State = false;
                    redLed.State   = true;
                }
            };

            Console.WriteLine("Press enter to exit.");
            Console.ReadLine();

            redButton.Close();
            redLed.Close();
            greenButton.Close();
            greenLed.Close();
        }