BITalino on JAVA

Python, Java, Android OS, etc.
jimmyneutron
Posts: 11
Joined: Tue May 31, 2016 1:31 pm

BITalino on JAVA

Postby jimmyneutron » Sun Jul 17, 2016 10:17 am

good day, i recently run the test file on java and this is what i get on my console

BlueCove version 2.1.1-SNAPSHOT on winsock
javax.bluetooth.LocalDevice@19469ea2
[]
Jul 17, 2016 3:00:54 PM BITalino.test main
INFO: Reading 5 samples..
Jul 17, 2016 3:00:54 PM BITalino.test main
INFO: FRAME: BITalino.Frame@4dd8dc3
Jul 17, 2016 3:00:55 PM BITalino.test main
INFO: FRAME: BITalino.Frame@6d03e736
Jul 17, 2016 3:00:56 PM BITalino.test main
INFO: FRAME: BITalino.Frame@568db2f2
Jul 17, 2016 3:00:57 PM BITalino.test main
INFO: FRAME: BITalino.Frame@378bf509
Jul 17, 2016 3:00:58 PM BITalino.test main
INFO: FRAME: BITalino.Frame@5fd0d5ae
Jul 17, 2016 3:01:00 PM BITalino.test main
INFO: Generated bitalino_log.json with frames encoded into JSON.
BlueCove stack shutdown completed


did i successfully run the app? how do i get the values in number form? help would really be appreciated :)

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: BITalino on JAVA

Postby BITalino » Sun Jul 17, 2016 10:23 am

Hi Jimmy,

In principle that output should be indicative that the app has been successfully executed.

The numerical values are available as a matrix or array. Please analyse the example code.

Best regards,
The BITalino Team

jimmyneutron
Posts: 11
Joined: Tue May 31, 2016 1:31 pm

Re: BITalino on JAVA

Postby jimmyneutron » Sun Jul 17, 2016 11:50 am

Hello Team BITalino,

im still not able to make this come out of my console,
BITalinoFrame{crc=0, seq=1, analog=[496,0,0,0,0,0], digital=[1,1,1,1]]}

is the example you're referring to is the test.java?

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: BITalino on JAVA

Postby BITalino » Sun Jul 17, 2016 12:06 pm

Depends on the version of the Java API you are using but it should be a 'test.java' type of file yes.

Best regards,
The BITalino Team

jimmyneutron
Posts: 11
Joined: Tue May 31, 2016 1:31 pm

Re: BITalino on JAVA

Postby jimmyneutron » Sun Jul 17, 2016 12:56 pm

BlueCove version 2.1.1-SNAPSHOT on winsock
javax.bluetooth.LocalDevice@77459877
[]
BlueCove stack shutdown completed

this came out of my console.

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: BITalino on JAVA

Postby BITalino » Sun Jul 17, 2016 1:03 pm

Have you made any changes to the example that would provide a different output on the console?

Best regards,
The BITalino Team

jimmyneutron
Posts: 11
Joined: Tue May 31, 2016 1:31 pm

Re: BITalino on JAVA

Postby jimmyneutron » Sun Jul 17, 2016 1:05 pm

nope. i didnt made any changes, i run it as it is.:)

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: BITalino on JAVA

Postby BITalino » Sun Jul 17, 2016 1:12 pm

There's your answer right there then. You need to analyse the Java code on the example file and adapt it to reproduce your intended behaviour.

By default it demonstrates the methods needed to connect to the device and acquire data from it. Anything beyond that needs to coded.

Best regards,
The BITalino Team

jimmyneutron
Posts: 11
Joined: Tue May 31, 2016 1:31 pm

Re: BITalino on JAVA

Postby jimmyneutron » Sun Jul 17, 2016 1:15 pm

im still a beginner in java programming and im not yet that familiar with the coding but once i see the data itll be easier.
i just wanna see this in my console,

BITalinoFrame{crc=0, seq=1, analog=[496,0,0,0,0,0], digital=[1,1,1,1]]}

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: BITalino on JAVA

Postby BITalino » Sun Jul 17, 2016 2:10 pm

On the example code you'll see a variable (array) called dataAcquired, where the data acquired from the device is stored. That variable belongs to class Frame, which has as member variables CRC, seq, analog and digital.

After the line dataAcquired = device.read(...); on the example, the variable will be populated will all the frames sent by the device. You can use for example System.out.println(...) to output to the content of each member variable console:
https://www.google.com/search?client=safari&rls=en&q=system.out.println&ie=UTF-8&oe=UTF-8

Note that since dataAcquired is an array, it needs to be indexed (e.g. System.out.println(dataAcquired[0].seq)) should output the sequence number of the first frame).

If you want to print all the frames, you need to put the System.out.println(...) statements inside a loop (e.g. a for) that runs from index 0 to the length of dataAcquired.

Furthermore, the analog and digital members of dataAcquired are arrays as well, which means that to print all the channels you'll need an additional loop running from 0 to the length of each (e.g. System.out.println(dataAcquired[0].analog[0]) only prints analog input A1 from the first frame).

Another important aspect to consider is that the example is reading a single batch of frames from the device; after the frames are retrieved the devices will stop the acquisition (as programmed from the calls to device.stop() and device.close()).

To keep acquiring frames the dataAcquired = device.read(...); (and related parts of code you want to be done repeatedly with the frames; e.g. outputting to the console) need to be placed inside a loop.

Given that the device is streaming data in real time, if the operations you place after the dataAcquired = device.read(...); statement take too long (e.g. outputting to the console), the device will not be able to dispatch all the frames at the expected rate and automatically stop acquisition.

Should you experience this issue, a few workarounds are to optimize the code base to take less time, ask more frames in each call to device.read(...), use a lower sampling rate and/or a combination of all these factors.

Our suggestion is that you take this one step at the time. Try first to adapt the example to just output a single batch of frames to the console and work your way from there.

Hope you found this information useful... in case you have any further questions where our support may be of added value just let us know; we'll do our best to support.

Best regards,
The BITalino Team


Return to “Programming APIs”




cron