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

ListAll/ListAllS


  • Please log in to reply
9 replies to this topic

#1 porl

porl
  • Members
  • 20 posts

Posted 23 November 2013 - 08:06 PM

Hi

 

How can I use the ListAll or ListAllS functions correctly from Java?

 

I want to return the serial numbers of all found devices. The API documentation says:

 

aSerialNumbers[out]

An array of serial numbers, one for each of the NumFound devices. Must be preallocated to size LJM_LIST_ALL_SIZE

 

What I am unsure of is how to obtain the LJM_LIST_ALL_SIZE value. If I know how many devices there are (only one in my case for now) I am able to preallocate the array size to that. I assume I could preallocate it to some arbitrarily large value (unlikely to have thousands of devices for instance) and then "trim" the array after learning the numFound value but this feels messy.

 

Is there a better way to do this?

 

Thanks



#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 25 November 2013 - 10:58 AM

The LJM_LIST_ALL_SIZE constant is in the LJM.Constants class, and called just LIST_ALL_SIZE. So create your arrays with a size of LJM.Constants.LIST_ALL_SIZE as the LJM library requires it. If you like you can trim the arrays afterwards.

 

Take a look at the Javadoc provided in the Java examples' doc directory for all classes provided by the LJM Java wrapper and their methods and fields/constants. The LJM library's functions and constants that the LJM Java wrapper wraps to are documented in the LJM User's Guide but the LJM class's Javadoc is helpful as it explains the Java specifics, such as the LJM constants and errorcodes are in the Constants class and Errors enum.



#3 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 25 November 2013 - 11:00 AM

Also, the LJM_LIST_ALL_SIZE constant value is 128.



#4 porl

porl
  • Members
  • 20 posts

Posted 26 November 2013 - 09:52 PM

Thanks for that. Unfortunately I seem to be missing the LJM.Constants part of the library. I downloaded the LJMJava.zip file and have been using the ljm.jar file with no problems for the methods (listAllS, open, eStreamRead etc all work as expected) but I cannot access the LJM.Constants class (I get compiler errors stating that it does not exist).

 

Is there another package I need? I noticed that there are a lot less examples in the java zip than the python etc ones but I assumed this was intentional. Have I got everything I need (with the addition of the actual driver etc zip of course).



#5 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 27 November 2013 - 12:42 PM

I checked the Java download and it contains all the files. All you need is the LJM library/driver installed, the ljm.jar that provides the Java interface and the jna.jar that provides the interface to access dlls that ljm.jar needs. The amount of examples is correct, and we plan on releasing more examples like the Python ones.

 

Are you using the ljm.jar with your program? If you extract the ljm.jar files you'll see a com\labjack\LJM$Constants.class where the Constants class is (it's a LJM inner class). Are the examples running for you with no modification as they all use the Constants class in the LJMUtitlities.printDeviceInfo method? All examples also have a commented out LJM.open call which uses Constants to show an alternate way to open a device.

 

Note the class with the namespace is com.labjack.LJM.Constants, but if you "import com.labjack.LJM" you just need "LJM.Constants" when using it. Also, the class is only meant to access static variables, so usage is LJM.Constants.THE_CONSTANT.



#6 porl

porl
  • Members
  • 20 posts

Posted 29 November 2013 - 11:40 PM

I'm actually using scala rather than java. It should be 99% interoperable but it seems to not like the nested class for the Constants. Everything else is working fine so I'll just try to work around it. The class is working fine from Java.



#7 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 02 December 2013 - 10:39 AM

It looks like you can access the nested class's member variables like so in Scala:

import labjack.com.LJM
var ljm = new LJM
ljm.Constants.LIST_ALL_SIZE

Something similar to below will work in Java but doesn't seem to work in Scala:

import labjack.com.LJM
LJM.Constants.LIST_ALL_SIZE

Beyond quick testing this in the Scala console I have no experience with Scala, so there may be other ways to access the static member variables in the LJM.Constants class.



#8 porl

porl
  • Members
  • 20 posts

Posted 02 December 2013 - 03:13 PM

Thanks for that! The IDE I'm using (IntelliJ Idea) is still showing it as an error (so I assumed this wasn't going to work) but scala compiles and runs it fine. I appreciate the help!



#9 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 19 December 2013 - 03:07 PM

 

I noticed that there are a lot less examples in the java zip than the python etc ones but I assumed this was intentional.

We updated the Java examples and it now has the same amount as the Python examples.



#10 porl

porl
  • Members
  • 20 posts

Posted 19 December 2013 - 03:53 PM

Thanks! I'll definitely take a look.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users