TC-08 in a Java application

Post your Java discussions here
Post Reply
Metzsch
Newbie
Posts: 0
Joined: Fri Oct 12, 2012 10:57 am

TC-08 in a Java application

Post by Metzsch »

I have a problem reading the temperature from a PicoLog TC08. I access the unit with Java Native Access (http://jna.java.net/), because there is no original dll-file for Java. I can see that Java can communicate with the TC08, but I can't read any temperature. Can you help me, so I can use the TC08 in my Java application?

Below is the code for connection to TC08

Initaite via JNA
-------------------------
public FloatByReference fbr = new FloatByReference();
public LongByReference lbr = new LongByReference();
public ShortByReference sbr = new ShortByReference();
-------------------------

Run this code:

PicoLog picolog = (PicoLog) Native.loadLibrary(System.getProperty("user.dir") + "\\usbtc08.dll", PicoLog.class);//initiate via JNA

short handle = picolog.usb_tc08_open_unit();
short channel = 0;
short measureUnit = 0; // 0=celcius
short fillMissing = 1; // 1=previous good reading

System.out.println("Handle for TC08 = " + handle);
System.out.println("Set channel 1=OK = " + picolog.usb_tc08_set_channel(handle, channel, 'K'));
System.out.println("TC08 Run - Allowed interval = " + picolog.usb_tc08_run(handle, 50));
System.out.println("Minimum interval = " + picolog.usb_tc08_get_minimum_interval_ms(handle));
System.out.println("Returnvalue > 0 = OK = " + picolog.usb_tc08_get_temp(handle, fbr, lbr, 1, sbr, channel, measureUnit, fillMissing));
System.out.println("temperatur = " + fbr.getValue());
System.out.println("Convert time = " + lbr.getValue());
System.out.println("Overflow = " + sbr.getValue());
System.out.println("Shut down = " + picolog.usb_tc08_close_unit(handle));

--------------------------------------------
Returnvalues:

Handle for TC08 = 1
Set channel 1=OK = 1
TC08 Run - Allowed interval = 100
Minimum interval = 360556938221584484
Returnvalue > 0 = OK = 8589934591
temperatur = 0.0
Convert time = 0
Overflow = 0
Shut down = 1
BUILD SUCCESSFUL (total time: 4 seconds)

Hitesh

Re: TC-08 in a Java application

Post by Hitesh »

Hi Metzsch,

Which version of the SDK are you using? Please ensure that you download the latest SDK (R10.4.3.1) from http://www.picotech.com/software.html.

The minimum interval being returned doesn't look right - what happens if you try to call it before the run function? Also, set the time interval to the minimum 100ms instead of 50.

Also, are you passing arrays for the temp_buffer and times_ms_buffer in the usb_tc08_get_temp() function call?

There may be an issue with the way parameters are being passed. Does your PicoLog class show the specification for each of the methods it has available?

Thanks,

Metzsch
Newbie
Posts: 0
Joined: Fri Oct 12, 2012 10:57 am

Re: TC-08 in a Java application

Post by Metzsch »

Now I pass the temp_buffer and the times_ms_buffer as arrays with the length of 9. I did not do that before. But still, it is as if the TC08 does not write any values in the buffer-array. It just passes through the function without changing the value in the array.

I have changed the data types to something that should match the Native data types. (I got help from the Java Native Access user group)

I do not use the Picotech SDK. I use only Java and Java Native Access.I have an interface in wich I declare only the functions I use in the .dll file.

The Minimum interval is now looking more correct after I changed the data types, but I can't get any readings on the temperature.

Any suggestions?? Hope that we can solve this, as I need the temperature readings for an application.

Below is the new code
------------------------

Code: Select all

FloatByReference[] ArrayFBR = new FloatByReference[9];
NativeLongByReference[] ArrayNLBR = new NativeLongByReference[9];
ShortByReference overflowFlag = new ShortByReference();

PicoLog picolog = (PicoLog) Native.loadLibrary(System.getProperty("user.dir") + "\\usbtc08.dll", PicoLog.class);

short handle = picolog.usb_tc08_open_unit();
short channel = 1; //set channel 0=cold junction
short measureUnit = 0; // 0=celcius
short fillMissing = 1; // 1=previous good reading
ArrayFBR[1] = new FloatByReference(); //new FloatByReference();
ArrayNLBR[1] = new NativeLongByReference();
NativeLong nl_interval_run = new NativeLong(300);//interval settings in run function
NativeLong nl_bufferlength_getTemp = new NativeLong(1);//size of array in get_temp

System.out.println("Handle for TC08     = " + handle);
System.out.println("Set channel 1=OK     = " + picolog.usb_tc08_set_channel(handle, channel, 'K'));
System.out.println("TC08 Run - Allowed interval    = " + picolog.usb_tc08_run(handle, nl_interval_run));
System.out.println("Minimum interval     = " + picolog.usb_tc08_get_minimum_interval_ms(handle));

System.out.println("Get temp returnvalue > 0 = OK  || Value = " + picolog.usb_tc08_get_temp(handle, ArrayFBR, ArrayNLBR, nl_bufferlength_getTemp,   

overflowFlag, channel, measureUnit, fillMissing));

System.out.println("temperatur = " + ArrayFBR[1].getValue());
System.out.println("Convert time = " + ArrayNLBR[1].getValue());
System.out.println("Overflow = " + overflowFlag.getValue());
System.out.println("Shut down = " + picolog.usb_tc08_close_unit(handle));
------------------------------------

new return values

Handle for TC08 = 1
Set channel 1=OK = 1
TC08 Run - Allowed interval = 300
Minimum interval = 200
Get temp returnvalue > 0 = OK || Value = 1
temperatur = 0.0
Convert time = 0
Overflow = 0
Shut down = 1
BUILD SUCCESSFUL (total time: 5 seconds)

Thanks...
Kenneth Metzsch

Hitesh

Re: TC-08 in a Java application

Post by Hitesh »

Hi Kenneth,

I have some questions about your code:-

With regards to the following lines:

Code: Select all

ArrayFBR[1] = new FloatByReference(); //new FloatByReference();
ArrayNLBR[1] = new NativeLongByReference();
Are you creating an array within an array above as you have:

Code: Select all

FloatByReference[] ArrayFBR = new FloatByReference[9];
NativeLongByReference[] ArrayNLBR = new NativeLongByReference[9];
I am not familiar with JNA but I have used the JNI interface with the SDK for one or two of our oscilloscope ranges. Have you tried using JNI as well to communicate with the device? I have written an example in the Java forum:

http://www.picotech.com/support/topic9931.html

Please note that for the times_ms_buffer argument to usb_tc08_get_temp() (ArrayNLBR in your case), it only needs to be set to a 1 by x array where x is the number of samples per channel you are capturing. This is because it records the time that it captures the reading for channel 1 for each sample set.

Also, have you tried calling the usb_tc08_get_single() function to get a single reading - you can call this instead of the usb_tc08_run() and usb_tc08_get_temp() functions to try getting a reading on channel 1.

I've pasted in some code from the console example that might help:

Code: Select all

long interval;
	float temp_buffer [9][BUFFER_SIZE];
	long times_ms_buffer[BUFFER_SIZE];
	short overflows[9];
	long numberOfReadings;
	long buffer_length;

	short channel;
	long i;

	// Get minimum interval
	min_interval_ms = usb_tc08_get_minimum_interval_ms(handle);

	buffer_length = BUFFER_SIZE;

	printf("Min. interval (ms): %d\n", min_interval_ms);

	//Interval
	interval = usb_tc08_run(handle, min_interval_ms);

	printf("Interval: %d\n", interval);

	printf("Press any key to start\n");

	_getch();

	//Loop
	while (!_kbhit())
	{
		// Obtain a set of readings
		for (channel = 0; channel <= USBTC08_MAX_CHANNELS; channel++)
		{
			numberOfReadings = usb_tc08_get_temp( handle, temp_buffer[channel], &times_ms_buffer[channel],
				buffer_length, &overflows[channel], channel, 0, // degrees Celsius units 
				0); // do not fill missing readings
		}
        }
Please note that when capturing streaming data, you need to read data from the buffer periodically, and also call the usb_tc08_stop() function when you have finished collecting data.

Hope this helps.
Last edited by Hitesh on Mon Oct 15, 2012 11:34 am, edited 2 times in total.
Reason: Updating message.

Metzsch
Newbie
Posts: 0
Joined: Fri Oct 12, 2012 10:57 am

Re: TC-08 in a Java application

Post by Metzsch »

I only use one array, but I put a value in the array before handing it over. Se the examples below.

I have seen ypu example, but I am not familiar with writing the wrapper.dll in C og C++, so thats why I chose JNA, as their code works fine with other dll-files I use for my application.

I have tried many differetn things now to make this work, and I still don't get the temperature. I think the problem lies in the datatype Float * temp_buffer vs FloatByReference[], and likewise between the long * times_ms_buffer and NativeLongByReference[]

------------------------------------------
The following cod gives me a java.lang.NullPointerException:
//make the array with space for 9 numbers and hand it over to the TC-08 in the function
FloatByReference[] ArrayFBR = new FloatByReference[9];

System.out.println("temperature = " + ArrayFBR[0].getValue());

Error...Exception

-------------------------------------------

Then I tried to put a FloatByReference number in the first entry in the arrray (Place zero).

//make the array with space for 9 numbers
FloatByReference[] ArrayFBR = new FloatByReference[9];

//put a FloatByReference in the array, and hand it over to the TC-08
ArrayFBR[0] = new FloatByReference();

System.out.println("temperature = " + ArrayFBR[0].getValue());

That gives me a fatal Runtime Error:
# Problematic frame:
# C [jna9070206901260664096.dll+0x63a4]

-------------------------------------------

Then I tried to put a FloatByReference number in the second entry in the arrray (Place 1).

//make the array with space for 9 numbers
FloatByReference[] ArrayFBR = new FloatByReference[9];

//put a FloatByReference in the array, and hand it over to the TC-08
ArrayFBR[1] = new FloatByReference();

System.out.println("temperature = " + ArrayFBR[1].getValue());

Print on screen = temperature = 0.0
(No crash or exceptions)

--------------------------------------------

Then I tried to assign a value to the FloatByReference number in the second entry in the arrray (Place 1).

//make the array with space for 9 numbers
FloatByReference[] ArrayFBR = new FloatByReference[9];

//put a FloatByReference in the array, and hand it over to the TC-08
ArrayFBR[1] = new FloatByReference(123);

System.out.println("temperature = " + ArrayFBR[1].getValue());

Print on screen = temperature = 123.0
(No crash or exceptions, but it went through without changing the value)

---------------------------------------------

I hope you can tell me what is going on in the code between my java code and the TC-08, or perhaps I am doing something wrong.
Please help.

Metzsch
Newbie
Posts: 0
Joined: Fri Oct 12, 2012 10:57 am

Re: TC-08 in a Java application

Post by Metzsch »

Finally I got it running in Java...

Got help from the JNA group, and it turned out that all I had to do to get the temperature readings now was to change:

FloatByReference[] ArrayFBR = new FloatByReference[9];

With:

float[] ArrayFBR = new float[9];

And then the TC-08 understood the datatype I handed to it.

Thank you very much for the time you spend on helping me.

Hitesh

Re: TC-08 in a Java application

Post by Hitesh »

Hi Kenneth,

It might be some kind of memory issue.

I found this on the JNA API pages:

http://jna.java.net/javadoc/overview-su ... tml#arrays

Are you not able to use just a standard float or long array? The text does mention:
To map a native multi-dimensional array, use a single-dimensional Java array with a number of elements equivalent to the full native array
So for 2 channels and 100 samples each could you use the following?

Code: Select all

float[] tempArray = new float[200]
Regards,
Last edited by Hitesh on Wed Oct 17, 2012 4:35 pm, edited 1 time in total.
Reason: Updated text with code example

Post Reply