Test and Measurement Forum

Get Value not giving me values C#

Post your .Net discussions here

Get Value not giving me values C#

Postby simonwait » Sun May 21, 2017 2:39 pm

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);

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

Re: Get Value not giving me values C#

Postby Hitesh » Mon May 22, 2017 8:24 am

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,
Hitesh

Technical Support Engineer
Hitesh
Site Admin
Site Admin
 
Posts: 2359
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Get Value not giving me values C#

Postby simonwait » Wed May 24, 2017 8:51 pm

Hi

So I eventually realised I wasn't setting any channels to take samples from. Thanks for your help
simonwait
Newbie
 
Posts: 0
Joined: Sat Nov 03, 2012 9:06 am

Re: Get Value not giving me values C#

Postby Hitesh » Thu May 25, 2017 8:37 am

Hi Simon,

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

Regards,
Hitesh

Technical Support Engineer
Hitesh
Site Admin
Site Admin
 
Posts: 2359
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire


Return to .Net Languages (C#, VB.Net, .)

Who is online

Users browsing this forum: No registered users and 0 guests