Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

how to find the number and types of LabJacks connected


  • Please log in to reply
10 replies to this topic

#1 yamahabest

yamahabest
  • Members
  • 2 posts

Posted 18 October 2006 - 01:42 AM

Hey, I'm writing an application which logs data and writes it to an CSV-file. It is possible for the user to connect multiple LabJack U3 and UE9 and configure these. Now i'm wondering how to find out which LabJack's are connected from within the code (C#). Does anyone have an answer to this question?

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 18 October 2006 - 02:09 PM

Hey,

I'm writing an application which logs data and writes it to an CSV-file.
It is possible for the user to connect multiple LabJack U3 and UE9 and configure these.

Now i'm wondering how to find out which LabJack's are connected from within the code (C#).
Does anyone have an answer to this question?


You can use the ListAll function to detect the number of each labjacks connected. You can also get the local ids and serial number of each unit. In C# this can be done by

int numfound = 0;
int[] sernums = new int[128];
int[] ids = new int[128];
double[] address = new double[128];

int err = (int) LJUD.ListAll(LJUD.DEVICE.UE9, LJUD.CONNECTION.USB, ref numfound, sernums, ids, address);

for the U3 simply change the first parameter to:

int numfound = 0;
int[] sernums = new int[128];
int[] ids = new int[128];
double[] address = new double[128];

int err = (int) LJUD.ListAll(LJUD.DEVICE.U3, LJUD.CONNECTION.USB, ref numfound, sernums, ids, address);


#3 Trader451

Trader451
  • Members
  • 8 posts

Posted 23 February 2014 - 04:19 PM

In C# I wrote:

 

        public double LabJackListAll()
        {
            //long DeviceType;
            int pNumFound = 0;
            int[] pSerialNumbers = new int[128];
            int[] pIDs = new int[128];
            double[] pAddresses = new double[128];
            LJUD.ListAll(LJUD.DEVICE.U3, LJUD.CONNECTION.USB, ref pNumFound, pSerialNumbers, pIDs, pAddresses);
            return pAddresses[];
        }
 
My output and usage is definitely not correct. Any ideas ?
 
Appreciate !


#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 24 February 2014 - 03:37 PM

You might have to do something like this:

   public double[] LabJackListAll()
        {
            //long DeviceType;
            int pNumFound = 0;
            int[] pSerialNumbers = new int[128];
            int[] pIDs = new int[128];
            double[] pAddresses = new double[128];
            LJUD.ListAll(LJUD.DEVICE.U3, LJUD.CONNECTION.USB, ref pNumFound, pSerialNumbers, pIDs, pAddresses);
            return pAddresses;
        }

If that doesn't work, can you tell us what errors you are getting or why it isn't working?



#5 Trader451

Trader451
  • Members
  • 8 posts

Posted 24 February 2014 - 04:23 PM

Thank you again,

 

In Visual Studio 2010 I get a pre-compile error of "Cannot implicitly convert type 'double[]' to 'double' (in reference to return pAddresses). If I change return pAddresses to return pAddresses[] I get a Syntax error: value expected and if I change it again to reflect a value say return pAddresses[128] I am able to compile and start without debug I get a run time unhandled exception with a System.IndexOutOf RangeException: Index was outside the bounds of the array. Making the index larger also gives the same error. (Pheewww !)

 

After further thought my error might be generated from the the way I am calling it.

             textBox1.Text += String.Format("The LabJack Driver Version is {0:0.000}\r\n", MyLabJack.LabJackVersion());

 

Appreciate your time !!



#6 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 25 February 2014 - 04:26 PM

Did you also change the function definition to

 public double[] LabJackListAll()

 when returning just pAddresses?

 

I believe that should work.  If you send us your code to [email protected] we can take a look for you.  There might be something else going on.



#7 Trader451

Trader451
  • Members
  • 8 posts

Posted 25 February 2014 - 06:46 PM

Yes, that did the trick for the method - just didn't see it. Now all I have to do is call and use the returned [] correctly.



#8 Trader451

Trader451
  • Members
  • 8 posts

Posted 27 February 2014 - 04:50 PM

Drats ! I am having difficulty with getting to the information. Any examples in C# ?



#9 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 28 February 2014 - 02:58 PM

We have examples in C# and VB.NET for the LabJackUD library here: http://labjack.com/s...examples/dotnet

 

I would recomend starting with the U3_simple example or U3_EFunctions example (from the examples folder, then U3, then C#).  However, there's a good number of examples there that cover various features of the U3 that you can draw from. 



#10 Trader451

Trader451
  • Members
  • 8 posts

Posted 02 March 2014 - 06:01 PM

Unfortunately, to the best of my recollection none of the example code uses ListAll; however, after some experimentation I have come up with these methods that do the job with ListAll:

 

        /// <summary>
        /// Lists All the Number of LabJacks Found.
        /// </summary>
        /// <returns> pNumFound </returns>
        public int LabJackListAllNumFound()
        {
            int pNumFound = 0;
            int[] pSerialNumbers = new int[128];
            int[] pIDs = new int[128];
            double[] pAddresses = new double[128];
            LJUD.ListAll(LJUD.DEVICE.U3, LJUD.CONNECTION.USB, ref pNumFound, pSerialNumbers, pIDs, pAddresses);
 
            return pNumFound;
        }
 
        /// <summary>
        /// Lists All the LabJack Serial Numbers Found.
        /// </summary>
        /// <returns> pSerialNumbers </returns>
        public int[] LabJackListAllSerialNumbers()
        {
            int pNumFound = 0;
            int[] pSerialNumbers = new int[128];
            int[] pIDs = new int[128];
            double[] pAddresses = new double[128];
            LJUD.ListAll(LJUD.DEVICE.U3, LJUD.CONNECTION.USB, ref pNumFound, pSerialNumbers, pIDs, pAddresses);
 
            return pSerialNumbers;
        }
 
        /// <summary>
        /// Lists All the Product Identifiers Found.
        /// </summary>
        /// <returns> pIDs </returns>
        public int[] LabJackListAllID()
        {
            int pNumFound = 0;
            int[] pSerialNumbers = new int[128];
            int[] pIDs = new int[128];
            double[] pAddresses = new double[128];
            LJUD.ListAll(LJUD.DEVICE.U3, LJUD.CONNECTION.USB, ref pNumFound, pSerialNumbers, pIDs, pAddresses);
 
            return pIDs;
        }
 
        /// <summary>
        /// Lists All the Addresses Found.
        /// </summary>
        /// <returns> pAddresses </returns>
        public double[] LabJackListAllAddress()
        {
            int pNumFound = 0;
            int[] pSerialNumbers = new int[128];
            int[] pIDs = new int[128];
            double[] pAddresses = new double[128];
            LJUD.ListAll(LJUD.DEVICE.U3, LJUD.CONNECTION.USB, ref pNumFound, pSerialNumbers, pIDs, pAddresses);
 
            return pAddresses;
        }
 
I call these methods like this:
 
#region ListAll
            textBox1.Text += String.Format("The LabJack Driver Version is {0}\r\n", MyLabJack.LabJackVersion());
 
            int pNumFound = MyLabJack.LabJackListAllNumFound();
            textBox1.Text += String.Format("The LabJack number is {0}\r\n", pNumFound);
 
            int[] pSerialNumbers = MyLabJack.LabJackListAllSerialNumbers();
            textBox1.Text += String.Format("The LabJack serial number is {0}\r\n", pSerialNumbers[0]);
 
            int[] pIDs = MyLabJack.LabJackListAllID();
            textBox1.Text += String.Format("The LabJack id is {0}\r\n", pIDs[0]);
 
            double[] pAddresses = MyLabJack.LabJackListAllAddress();
            textBox1.Text += String.Format("The LabJack address is {0}\r\n", pAddresses[0]);
            #endregion ListAll
 
In my most humble opinion, I would seriously consider deprecating the ListAll and expanding the LJUD.eGet instead. The LJUD eGet already has the Serial Number as given:
 
       /// <summary>
        /// Gets and returns the Labjack Serial Number.
        /// </summary>
        /// <returns> dblSerialNumber </returns>
        public double LabJackSerialNumber()
        {
            LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.SERIAL_NUMBER, ref dblValue, 0);
            double dblSerialNumber = dblValue;
            return dblSerialNumber;
        }
 
As called by:
 
            textBox1.Text += String.Format("The Serial Number is: {0}\r\n", MyLabJack.LabJackSerialNumber());
 
ListAll is rather painful whereas LJUD.eGet is more straightforward.
 
Once again, Appreciate all your help !


#11 Trader451

Trader451
  • Members
  • 8 posts

Posted 05 March 2014 - 08:51 AM

Following up for anyone More useful information can be found in the LabJackM.h and LabJackUD.h files too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users