How to use 1135 Voltage sensor (new here)

Supporting Visual Studio on Windows
Post Reply
Filoud
Fresh meat
Posts: 1
Joined: Thu Jun 21, 2018 4:19 am
Contact:

How to use 1135 Voltage sensor (new here)

Post by Filoud »

Hi everybody

I'm pretty new to the phidgets comunity, and to the C# language and to the use of phidgets as well.
I'm here because i'm needing help to use my new Precision Voltage Sensor 1135. It's linked to my PC with a 1011 PhidgetInterfaceKit 8/8/8

Can someone help me with the writing of code with these devices?
I only want to read the value returned by my Phidgets, and I struggle to use the exemples (wich does too much for me) and even with the basics tutorials my codes won't work..
I don't know what I'm doing wrong..



Here is the code i made (surely full of mistakes)

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Phidget22;
using Phidget22.Events;

namespace Phidget22
{
    public enum VoltageSensorType
    {

        PN_1135 = 11350,

    }
}

namespace Phidget22.Events
{
    //
    // Résumé :
    //     VoltageInput SensorChange Event data
    public class VoltageInputSensorChangeEventArgs : EventArgs
    {
        //
        // Résumé :
        //     The sensor value
        public readonly double SensorValue;
        //
        // Résumé :
        //     The sensor unit information corresponding to the sensor value. Helps keep track
        //     of the type of information being calculated from the voltage input.
        public readonly UnitInfo SensorUnit;
    }
}

namespace testLectureTension
{
    class Program
    {
        
        public static double SensorValue { get; }
        public static UnitInfo SensorUnit { get; }
 
        public static VoltageSensorType SensorType { get; set; }


        public static void Vin_SensorChange(object sender, VoltageInputSensorChangeEventArgs e)
        {
            Console.WriteLine(e.SensorValue);
        }

        static void Main(string[] args)
        {
            

        VoltageInput vin = null;
            DigitalInput ch;
            ch = new DigitalInput();
            ch.Open();
            //vin.SensorType = VoltageSensorType.PN_1135;

            while (true)
            {
                Console.WriteLine(Program.SensorValue);
                Console.WriteLine(Program.SensorUnit);
                //Vin_SensorChange(VoltageSensorType.PN_1135, );
                System.Threading.Thread.Sleep(300);
            }
        }
    }
}

Thank you for anyone trying to help me :D
User avatar
mparadis
Site Admin
Posts: 660
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: How to use 1135 Voltage sensor (new here)

Post by mparadis »

As you've noticed, our C# examples are complicated, since it's just the source code for our Phidget Control Panel. If you're just starting with programming I'd recommend that you try a simpler language like C or Python. I took a look at your program but I don't really understand all of the different classes and namespaces you've laid out. You don't need to declare Phidgets enums or events like you have here. I've stripped all of the unnecessary code for the most basic example:

Code: Select all

using System;
using Phidget22;
using Phidget22.Events;


namespace testLectureTension
{
    class Program
    {
        public static void Vin_SensorChange(object sender, VoltageInputSensorChangeEventArgs e)
        {
            Console.WriteLine(e.SensorValue);
        }

        static void Main(string[] args)
        {
            VoltageInput vin;
            vin = new VoltageInput();

            vin.Channel = 0;
            vin.SensorChange += Vin_SensorChange;

            vin.Open(5000);
            vin.SensorType = VoltageSensorType.PN_1135;

            Console.WriteLine("Press any key to stop.");
            Console.ReadKey();
        }
    }
}
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 0 guests