Link to home
Start Free TrialLog in
Avatar of jvalescu
jvalescuFlag for United States of America

asked on

Can't access a class developed outside of native namespace

OK, I've looked at this much too long and am only breaking it further.  I have a class I generated outside of my solution namespace.  I've add its project to my solution, I've add the reference .dll for the class as well.  I cannot "get" to the methods or properties defined within the class.  They are declared public, not sure what to do.........:

Class code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;


//using System.Text.Encoding;

namespace Keithley2701ClassLib
{
    //class General
    //{
    //}

    public static class General
    {

        //
        // Version 1.1
        // EEB
        //
        public const Int16 port = 1394;

        public static System.Net.Sockets.TcpClient KI2701Client = new System.Net.Sockets.TcpClient();

        public static System.Net.Sockets.NetworkStream KI2701Stream;

        public static string KIstatus;

        public static bool connected = false;

        public static string ip = "192.168.254.54";

        public static byte[] KIByte;

        public static string KIData;

        public static bool front = false;

        private static bool dis = false;




        public static void send(string KIData)
        {
            KI2701Stream = KI2701Client.GetStream();
            KIData = (KIData + "\r");
            //  Add control reset to the command line
            KIByte = System.Text.ASCIIEncoding.ASCII.GetBytes(KIData);
            //  Convert to byte
            KI2701Stream.Write(KIByte, 0, KIData.Length);
            //  Send data
        }

        public static void connect(string ip)
        {
            object zz;
            object z;
            try
            {
                KI2701Client.Connect(ip, port);
                KI2701Stream = KI2701Client.GetStream();
                if ((KI2701Stream.CanWrite && KI2701Stream.CanRead))
                {
                    connected = true;
                }
                else
                {
                    connected = false;
                }
            }
            catch (Exception e)
            {
                System.Net.Sockets.SocketException errnum = new System.Net.Sockets.SocketException();
                // .ErrorCode()
                string aa;
                switch (errnum.ErrorCode)
                {
                    case 10060:
                        MessageBox.Show("Could not connect to the 2701, please recheck your connections and network settings and try again ", "Time Out Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                    case 10061:
                        MessageBox.Show("Could not open connection because instrument has an open connection to another application.  Close th" +
                             "e connected application or power cycle the instrument to close existing connection", "Connection Refused !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        MessageBox.Show(("Error has occured:  "
                              + (errnum.ErrorCode + ("  " + e.Message))), "Error has been detected !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                }
            }
        }



        public static void disconnect()
        {
            if ((connected == true))
            {
                send("*rst");
                connected = false;
                KI2701Stream.Close();
                KI2701Client.Close();
                KI2701Client = null;
                dis = true;
            }
            connected = false;
        }

        public static void KI2701send(string data)
        {
            // Send data
            byte senddata;
        }

        public static void KIInput(ref string KIstatus)
        {
            send("SYST:FRSW?");
            KI2701Read(ref KIData);
            if ((KIData == "1"))
            {
                KIstatus = "Front";
            }
            else
            {
                KIstatus = "Rear";
            }
        }

        public static void KI2701Read(ref string KIdata)
        {
            //  Read network stream into byte buffer
            byte[] bytes = new byte[KI2701Client.ReceiveBufferSize];
            KI2701Stream.Read(bytes, 0, KI2701Client.ReceiveBufferSize);
            KIdata = System.Text.ASCIIEncoding.ASCII.GetString(bytes);
            //  Debug.WriteLine(KIdata)
        }
    }



}
 


<Snippets of calling form code>
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Dart.PowerTCP.Sockets;
using System.Diagnostics;
using System.Data;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using System.Threading;
using Syncfusion.Windows.Forms.Tools;
using Dart.PowerTCP;

using global::Keithley2701ClassLib;



namespace Inhallation
{
    public partial class frmVoltmeter : Form
    {
        public frmVoltmeter()
        {
            InitializeComponent();
        }

        #region Windows Control stuff
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label11;
        private System.Windows.Forms.TextBox txtStatus;
        private System.Windows.Forms.Label label12;
        private System.Windows.Forms.Label label13;
        private System.Windows.Forms.Label label14;
        private System.Windows.Forms.TextBox txtStartTime;
        private System.Windows.Forms.TextBox txtElapsedTime;
        private System.Windows.Forms.TextBox textBox4;
        private System.Windows.Forms.Label label15;
        private System.Windows.Forms.ComboBox cboPeakView;
        private System.Windows.Forms.Button btnStop;
        private System.Windows.Forms.Button btnStartExposure;
        private System.Windows.Forms.Timer timerGap;
        //private System.ComponentModel.IContainer components;
        #endregion
        public byte[] buffer = new byte[1024];
        public byte[] HPbuffer = new byte[1024];
        public byte[] DAQbuffer = new byte[1024];
        public bool HPInit = true;
        public bool DAQInit = true;
        //private Dart.PowerTCP.Sockets.Tcp tcpValve;
        //private Dart.PowerTCP.Sockets.Tcp tcpHP;
        private bool ValveConnected = false;
        private bool HPConnected = false;
        private bool DAQConnected = false;
        public int prevValvepos = 0;
        private Dart.PowerTCP.Sockets.Tcp tcp2701;
        private System.Windows.Forms.TextBox txt2701;
        private System.Windows.Forms.TextBox txtDisplay1;
        // private Dart.PowerTCP.Sockets.Tcp tcpValve;
        //private Dart.PowerTCP.Sockets.Tcp tcp2701;
        //private Dart.PowerTCP.Sockets.Tcp tcpHP;
        private System.Windows.Forms.Timer timer2701;
        private Dart.PowerTCP.Sockets.Tcp tcp2701Reset;
        string strConn = ConfigurationSettings.AppSettings["DSN"];
        public ArrayList arChamberInfo = new ArrayList();
        public ArrayList arTimers = new ArrayList();

        private global::Keithley2701ClassLib.Class1 K2701 = new Class1();

   
        If I try to access anything under K2701, I get the standard options, not the exposed methods,  What's wrong?  Thanks!


Avatar of Yurich
Yurich
Flag of New Zealand image

Are you sure you listed it in your postage correctly? There is no Class1 defined in the Keithley2701 namespace :( only General. Another point - you have everything static, you don't need to create an instance of the class in this case, just use class-scope, not instance-scope, e.g:

Keithley2701ClassLib.send( "..." );

and lastly, if you added this project to your project, why do you use global? just doing this:

using Keithley2701ClassLib;

Cheers,
Yurich

should give you access to the namespace and enable intellisense for the class.
Avatar of drichards
drichards

And remove the assembly reference if you have put the project into the main solution.  I don't know which one has precedence, but the assembly reference is not per configuration, so you can only reference the debug or release assembly and it will be for both configurations of the dependent project.


ASKER CERTIFIED SOLUTION
Avatar of Yurich
Yurich
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial