Exemple #1
0
    protected override void OnStarted()
    {
        ratio         = new VoltageRatioInput();
        ratio.Attach += Ratio_Attach;

        try
        {                                      //set all the values grabbed from command line.  these values have defaults that are set in ExampleUtils.cs, you can check there to see them.
            ratio.Channel            = 0;      //selects the channel on the device to open
            ratio.DeviceSerialNumber = 538053; //selects the device or hub to open
            ratio.HubPort            = 0;      //selects the port on the hub to open
            ratio.IsHubPortDevice    = true;   //is the device a port on a VINT hub?

            if (isRemote)                      //are we trying to open a remote device?
            {
                ratio.IsRemote = true;
                Net.EnableServerDiscovery(ServerType.Device); //turn on network scan
                if (phidgetPassword != null && phidgetServerName != null)
                {
                    Net.SetServerPassword(phidgetServerName, phidgetPassword); //set the password if there is one
                }
            }
            else
            {
                ratio.IsLocal = true;
            }

            ratio.Open(); //open the device specified by the above parameters
        }
        catch (PhidgetException ex) { Debug.Log(ex.ToString()); }
        // Start receive datagrams
        ReceiveAsync();
    }
    void ratioAttachCallback(object sender, Phidget22.Events.AttachEventArgs e)
    {
        VoltageRatioInput attachedDevice = (VoltageRatioInput)sender;

        attachedDevice.DataInterval = attachedDevice.MinDataInterval;  // Setting the data interval here too.
        Debug.Log("Attached device " + attachedDevice.DeviceSerialNumber);
    }
Exemple #3
0
            void OnPhidgetAttached(object sender, ManagerAttachEventArgs args)
            {
                if (hashMap == null)
                {
                    hashMap = new Dictionary <int, int>();
                }
                // add device to the list
                VoltageRatioInput input = new VoltageRatioInput();

                input.DeviceSerialNumber = args.Channel.DeviceSerialNumber;
                input.Channel            = args.Channel.Channel;
                input.DeviceLabel        = Phidget.AnyLabel;
                input.HubPort            = Phidget.AnyHubPort;
                input.Error += Input_Error;
                input.VoltageRatioChange += Input_VoltageRatioChange;
                input.Detach             += Input_Detach;
                input.PropertyChange     += Input_PropertyChange;
                input.SensorChange       += Input_SensorChange;

                input.Open(0);
                input.BridgeEnabled = false;

                hashMap.Add(hashMap.Count, input.GetHashCode());
                var info = new InputInfo(input);

                listOfPhidgets.Add(new InputInfo(input));
            }
        void OnPhidgetAttached(object sender, ManagerAttachEventArgs args)
        {
            // add device to the list
            VoltageRatioInput input = new VoltageRatioInput();

            input.DeviceSerialNumber = args.Channel.DeviceSerialNumber;
            input.Channel            = args.Channel.Channel;
            input.DeviceLabel        = Phidget.AnyLabel;
            input.HubPort            = Phidget.AnyHubPort;
            input.Error += Input_Error;
            input.Open(0);
            input.BridgeEnabled = false;



            var info       = new InputInfo(input);
            int targetHash = input.DeviceSerialNumber * 10 + input.Channel;
            int i          = 0;

            for (; hashMap[i] != targetHash; i++)
            {
                if (i >= hashMap.Count)
                {
                    throw new NotImplementedException("wrongHash");
                }
            }
            listOfPhidgets.Add(i, new InputInfo(input));
            listOfPhidgetsReady.Add(i, false);
            System.Diagnostics.Trace.WriteLine("PhidgetReciver OnPhidgetAttached " + input.DeviceSerialNumber + " " + input.Channel);
        }
 public VoltageReader(int channel, Action <double> onNewVoltage, int dataIntervalMs = 10)
 {
     this.dataIntervalMs = dataIntervalMs;
     this.NewVoltage    += onNewVoltage;
     input         = new VoltageRatioInput();
     input.Channel = channel;
     input.Close();
     input.Open();
     input.Attach += OnAttach;
 }
Exemple #6
0
    void Ratio_Attach(object sender, Phidget22.Events.AttachEventArgs e)
    {
        attachedDevice = (VoltageRatioInput)sender;

        try
        {
            attachedDevice.SensorType = VoltageRatioSensorType.PN_1139;
        }
        catch (PhidgetException ex) { Debug.Log(ex.ToString()); }
    }
Exemple #7
0
    IEnumerator InitInputs(int waitMillis)
    {
        defaultInputs = new double[inputs.Length];
        for (int i = 0; i < inputs.Length; i++)
        {
            inputs[i]         = new VoltageRatioInput();
            inputs[i].Channel = i;
            inputs[i].Open(waitMillis);
            yield return(new WaitForSecondsRealtime(waitMillis / 1000));

            defaultInputs[i] = inputs[i].VoltageRatio;
        }
        initializedInputs = true;
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            dcmotor.VelocityUpdate -= onVelocityUpdate;
            dcmotor.Close();
            dcmotor = null;
            vol.VoltageRatioChange -= onVoltageRatioChange;
            vol.Close();
            vol = null;

            Application.Quit();
        }
    }
Exemple #9
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log($"UDP server address: {ip}");
        Debug.Log($"UDP server port: {port}");

        // Create a new TCP chat client
        client = new Client(ip, port);

        ratio         = new VoltageRatioInput();
        ratio.Attach += Ratio_Attach;
        // Connect the client
        Debug.Log("Client connecting...");
        client.Connect();
        Debug.Log("Done!");
        try
        {                                      //set all the values grabbed from command line.  these values have defaults that are set in ExampleUtils.cs, you can check there to see them.
            ratio.Channel            = 0;      //selects the channel on the device to open
            ratio.DeviceSerialNumber = 538053; //selects the device or hub to open
            ratio.HubPort            = 0;      //selects the port on the hub to open
            ratio.IsHubPortDevice    = true;   //is the device a port on a VINT hub?

            if (isRemote)                      //are we trying to open a remote device?
            {
                ratio.IsRemote = true;
                Net.EnableServerDiscovery(ServerType.Device); //turn on network scan
                if (phidgetPassword != null && phidgetServerName != null)
                {
                    Net.SetServerPassword(phidgetServerName, phidgetPassword); //set the password if there is one
                }
            }
            else
            {
                ratio.IsLocal = true;
            }

            ratio.Open(); //open the device specified by the above parameters
        } catch (PhidgetException ex) { Debug.Log(ex.ToString()); }
    }
    // 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);
        }
    }
Exemple #11
0
 IPhidgetViewModel CreateViewModel(VoltageRatioInput phidget)
 {
     return(new VoltageRatioInputViewModel(phidget));
 }
Exemple #12
0
 public InputInfo(VoltageRatioInput inp)
 {
     Input = inp;
 }
Exemple #13
0
 public InputInfo()
 {
     Input = null;
 }
Exemple #14
0
    void IsAttached(object sender, AttachEventArgs e)
    {
        VoltageRatioInput ch = (VoltageRatioInput)sender;

        sensors[ch.Channel].DataInterval = (int)dataInt;
    }
        static void Main(string[] args)
        {
            Log.Enable(LogLevel.Info, "phidgetlog.log");
            DistanceSensor distanceSensor0 = new DistanceSensor();

            distanceSensor0.HubPort = 3;
            //distanceSensor0.DistanceChange += DistanceSensor0_DistanceChange;
            distanceSensor0.Attach += DistanceSensor0_Attach;
            distanceSensor0.Detach += DistanceSensor0_Detach;
            distanceSensor0.Error  += DistanceSensor0_Error;

            DistanceSensor distanceSensor1 = new DistanceSensor();

            distanceSensor1.HubPort = 4;
            //distanceSensor0.DistanceChange += DistanceSensor0_DistanceChange;
            distanceSensor1.Attach += DistanceSensor0_Attach;
            distanceSensor1.Detach += DistanceSensor0_Detach;
            distanceSensor1.Error  += DistanceSensor0_Error;

            //VoltageRatioSensorType voltageRatioSensor = new VoltageRatioSensorType();
            VoltageRatioInput voltageRatioInput = new VoltageRatioInput();

            voltageRatioInput.HubPort         = 0;
            voltageRatioInput.IsHubPortDevice = true;
            voltageRatioInput.Channel         = 0;

            voltageRatioInput.VoltageRatioChange += VoltageRatioInput_VoltageRatioChange;

            try
            {
                InitizlizeMqttClient();

                distanceSensor0.Open(5000);

                distanceSensor0.DataInterval   = 2000;
                distanceSensor0.SonarQuietMode = false;

                distanceSensor1.Open(5000);
                distanceSensor1.DataInterval   = 2000;
                distanceSensor1.SonarQuietMode = false;

                voltageRatioInput.Open(5000);
                //voltageRatioInput.SensorType = VoltageRatioSensorType.PN_1129;

                voltageRatioInput.DataInterval = 100;

                //Console.ReadLine();

                Task.Run(() =>
                {
                    while (true)
                    {
                        Thread.Sleep(2000);

                        checkHandWash(distanceSensor1);
                        checkToiletVisit(distanceSensor0);
                    }
                });

                //Wait until Enter has been pressed before exiting
                Console.ReadLine();

                distanceSensor0.Close();
            }
            catch (PhidgetException ex)
            {
                Console.WriteLine(ex.ToString());
                Console.WriteLine("");
                Console.WriteLine("PhidgetException " + ex.ErrorCode + " (" + ex.Description + "): " + ex.Detail);
                Console.ReadLine();
            }
        }
    private void Start()
    {
        force0 = new VoltageRatioInput
        {
            HubPort         = 0,
            Channel         = 0,
            IsHubPortDevice = true,
            IsLocal         = true
        };
        force0.Attach             += ratioAttachCallback;
        force0.VoltageRatioChange += ratioChangeCallback;

        force1 = new VoltageRatioInput
        {
            HubPort         = 1,
            Channel         = 0,
            IsHubPortDevice = true,
            IsLocal         = true
        };
        force1.Attach             += ratioAttachCallback;
        force1.VoltageRatioChange += ratioChangeCallback;

        force2 = new VoltageRatioInput
        {
            HubPort         = 2,
            Channel         = 0,
            IsHubPortDevice = true,
            IsLocal         = true
        };
        force2.Attach             += ratioAttachCallback;
        force2.VoltageRatioChange += ratioChangeCallback;

        magnet3 = new VoltageRatioInput
        {
            HubPort         = 3,
            Channel         = 0,
            IsHubPortDevice = true,
            IsLocal         = true
        };
        magnet3.Attach             += ratioAttachCallback;
        magnet3.VoltageRatioChange += ratioChangeCallback;

        magnet4 = new VoltageRatioInput
        {
            HubPort         = 4,
            Channel         = 0,
            IsHubPortDevice = true,
            IsLocal         = true
        };
        magnet4.Attach             += ratioAttachCallback;
        magnet4.VoltageRatioChange += ratioChangeCallback;

        magnet5 = new VoltageRatioInput
        {
            HubPort         = 5,
            Channel         = 0,
            IsHubPortDevice = true,
            IsLocal         = true
        };
        magnet5.Attach             += ratioAttachCallback;
        magnet5.VoltageRatioChange += ratioChangeCallback;

        try
        {
            force0.Open(1000);
            force1.Open(1000);
            force2.Open(1000);
            magnet3.Open(1000);
            magnet4.Open(1000);
            magnet5.Open(1000);
        }
        catch (PhidgetException e) { Debug.Log("force0: " + e.Description); }
    }