예제 #1
0
        static void Main()
        {
            M2k ctx = libm2k.m2kOpen();

            ctx.calibrateADC();

            // Setup analog in
            M2kAnalogIn ain = ctx.getAnalogIn();

            ain.enableChannel(0, true);

            double voltage = ain.getVoltage(ANALOG_IN_CHANNEL.ANALOG_IN_CHANNEL_1);

            Console.WriteLine(voltage);
            libm2k.contextClose(ctx);
        }
예제 #2
0
        static void Main()
        {
            M2k ctx = libm2k.m2kOpen();

            ctx.calibrateADC();

            // Will turn on the power supply if we need smth to measure
            M2kPowerSupply ps = ctx.getPowerSupply();

            ps.enableChannel(0, true);
            ps.pushChannel(0, 1.7);

            // Setup analog in
            M2kAnalogIn ain = ctx.getAnalogIn();

            ain.enableChannel(0, true);

            double voltage = ain.getVoltage(ANALOG_IN_CHANNEL.ANALOG_IN_CHANNEL_1);

            Console.WriteLine(voltage);
            libm2k.contextClose(ctx);
        }
예제 #3
0
파일: spi.cs 프로젝트: teoperisanu/libm2k
        static void Main()
        {
            M2k context = libm2k.m2kOpen("ip:192.168.2.1");

            if (context == null)
            {
                Console.WriteLine("Connection Error: No ADALM2000 device available/connected to your PC.");
                return;
            }

            context.calibrateADC();

            M2kAnalogIn    analogIn    = context.getAnalogIn();
            M2kPowerSupply powerSupply = context.getPowerSupply();
            M2kDigital     digital     = context.getDigital();

            //setup analog in
            analogIn.setOversamplingRatio(1);
            analogIn.setSampleRate(1000000);
            analogIn.enableChannel(0, true);
            analogIn.enableChannel(1, false);
            analogIn.setRange((ANALOG_IN_CHANNEL)0, M2K_RANGE.PLUS_MINUS_25V);

            //enable LDAC
            digital.setDirection(3, DIO_DIRECTION.DIO_OUTPUT);
            digital.enableChannel(3, true);

            //enable CLR
            digital.setDirection(4, DIO_DIRECTION.DIO_OUTPUT);
            digital.enableChannel(4, true);

            //setup SPI
            var m2kSpiInit = new m2k_spi_init();

            m2kSpiInit.clock         = 1;
            m2kSpiInit.mosi          = 2;
            m2kSpiInit.miso          = 7; //dummy value - miso is not used in this example
            m2kSpiInit.bit_numbering = bit_numbering.MSB;
            m2kSpiInit.context       = context;

            var spiInitParam = new spi_init_param();

            spiInitParam.max_speed_hz = 1000000;
            spiInitParam.mode         = spi_mode.SPI_MODE_3;
            spiInitParam.chip_select  = 0;
            spiInitParam.extra        = m2kSpiInit;

            spi_desc spiDesc = libm2k.spi_init(spiInitParam);

            if (spiDesc == null)
            {
                Console.WriteLine("SPI Error: Could not configure SPI");
                return;
            }

            powerSupply.enableChannel(0, true);
            powerSupply.pushChannel(0, 5);

            //CLR and LDAC high as long as bits are transmitted
            digital.setValueRaw(3, DIO_LEVEL.HIGH);
            digital.setValueRaw(4, DIO_LEVEL.HIGH);

            byte[] data = GetRegisterData(Voltage);
            //transmitting data
            libm2k.spi_write_and_read(spiDesc, data, 2);

            //update with current shift register contents
            digital.setValueRaw(3, DIO_LEVEL.LOW);

            var samples = analogIn.getSamples(100);
            var average = samples[0].Average();

            Console.WriteLine("Average value: " + average);

            libm2k.spi_remove(spiDesc);
            libm2k.contextClose(context, true);
        }
예제 #4
0
        static void Main()
        {
            M2k ctx = libm2k.m2kOpen();

            ctx.calibrateADC();
            ctx.calibrateDAC();

            M2kAnalogIn        ain  = ctx.getAnalogIn();
            M2kAnalogOut       aout = ctx.getAnalogOut();
            M2kHardwareTrigger trig = ain.getTrigger();

            // Setup analog in
            ain.enableChannel(0, true);
            ain.enableChannel(1, true);
            ain.setSampleRate(100000);
            ain.setRange((ANALOG_IN_CHANNEL)0, -10.0, 10.0); // nu are idxchannel
            ain.setRange((ANALOG_IN_CHANNEL)1, M2K_RANGE.PLUS_MINUS_25V);

            // Uncomment the following block to enable triggering
            // trig.setAnalogSource(M2K_TRIGGER_SOURCE.CHANNEL_1);
            // trig.setAnalogCondition(0, M2K_TRIGGER_CONDITION.RISING_EDGE);
            // trig.setAnalogLevel(0, 0.5);
            // trig.setAnalogDelay(0);
            // trig.setAnalogMode(0, M2K_TRIGGER_MODE.ALWAYS);

            // setup analog output
            aout.setSampleRate(0, 750000);
            aout.setSampleRate(1, 750000);
            aout.enableChannel(0, true);
            aout.enableChannel(1, true);

            // create output buffers
            var ch1  = new VectorD();
            var ch2  = new VectorD();
            var both = new VectorVectorD();

            for (int i = 0; i < 1024; i++)
            {
                double val = 4.0;
                ch1.Add(val);
                ch2.Add(3.0);
            }

            both.Add(ch1);
            both.Add(ch2);

            aout.setCyclic(true);
            aout.push(both);

            var data = ain.getSamples(1024);

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(data[0][i] + " ");
            }

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(data[1][i] + " ");
            }

            aout.stop();
            libm2k.contextClose(ctx);
        }