Get Value not giving me values C#

Post your .Net discussions here
Post Reply
simonwait
Newbie
Posts: 0
Joined: Sat Nov 03, 2012 9:06 am

Get Value not giving me values C#

Post by simonwait »

Hi

I seem to have the example C# working nicely but then when i try to plagiarise it i clearly am missing something. Im just trying to write something simple which polls the CM3 every 0.5s and then enters the values for the 3 channels in txtL1,txtL2 and txtL3. All seems ok, it opens the device but then always returns 0 values. The ip is fixed and the channel setting is mv so these can be hard coded.

Thanks for any help in advance..

Code: Select all

using System;
using System.Collections.Generic;
//using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using OnlineSigmatek;
using PLCM3Example;

namespace STS_Current_Clamp_Logger
{
    public partial class frmMain : Form
    {

        public const int NUM_CHANNELS = 3;

        public short handle;

        public static short status;
        public frmMain()
        {
            InitializeComponent();
            string IPAddress = "";


            System.Text.StringBuilder str = new System.Text.StringBuilder(80);
            str = null;

            IPAddress = "10.0.0.57:80";
            status = Imports.OpenUnitViaIp(out handle, str, IPAddress);

            if (handle == 0)
            {
                MessageBox.Show("Unable to open device");
            }
            else
            {
                MessageBox.Show("Device opened successfully");
            }

        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Imports.CloseUnit(handle);
            Application.Exit();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            uint[] values = new uint[NUM_CHANNELS];

                status = Imports.GetValue(handle, (Imports.enPLCM3Channels)1, out values[0]);
                txtL1.Text = Convert.ToString(values[0]/1000);
               
                status = Imports.GetValue(handle, (Imports.enPLCM3Channels)2, out values[1]);
                txtL2.Text = Convert.ToString(values[1] / 1000);

                status = Imports.GetValue(handle, (Imports.enPLCM3Channels)3, out values[2]);
                txtL3.Text = Convert.ToString(values[2] / 1000);

        }
    }
}

Hitesh

Re: Get Value not giving me values C#

Post by Hitesh »

Hi simonwait,

The reading on each channel takes 720 ms to convert so with all 3 channels enabled you should wait for an appropriate period of time before taking a reading.

Have you used the example from our GitHub repository as the basis for your code?

Regards,

simonwait
Newbie
Posts: 0
Joined: Sat Nov 03, 2012 9:06 am

Re: Get Value not giving me values C#

Post by simonwait »

Hi

So I eventually realised I wasn't setting any channels to take samples from. Thanks for your help

Hitesh

Re: Get Value not giving me values C#

Post by Hitesh »

Hi Simon,

It happens - good to hear you resolved the issue :D

Regards,

Post Reply