Loading...
Thursday, August 16, 2012

LabView with Android


android
download the labview library download the labview library
android technical specifications will familiarize you with the concepts of bluetooth communication.
hacking with labview how to hack with labview instructions

download the labview library
install jki's vi package manager -> jki's vi package manager
download the android package -> labviewhacker_lib_android_bluetooth_library-1.0.0.9.vip or the 2010 edition labviewhacker_lib_android_2010-1.0.0.3.vip
install the package using jki's package manager

other downloads:
sendsensor.apk

technical specifications
the sensors available on an android platform -> http://developer.android.com/reference/android/hardware/sensor.html

int type_accelerometer a constant describing an accelerometer sensor type.

int type_all a constant describing all sensor types.

int type_gravity a constant describing a gravity sensor type.

int type_gyroscope a constant describing a gyroscope sensor type

int type_light a constant describing an light sensor type.

int type_linear_acceleration a constant describing a linear acceleration sensor type.

int type_magnetic_field a constant describing a magnetic field sensor type.

int type_orientation this constant is deprecated. use sensormanager.getorientation() instead.

int type_pressure a constant describing a pressure sensor type

int type_proximity a constant describing an proximity sensor type.

int type_rotation_vector a constant describing a rotation vector sensor type.

int type_temperature a constant describing a temperature sensor type


labview running on a pc communicates with the android platform using bluetooth. the relationship between two bluetooth devices is known as a client and server or master and slave. in a piconet (a collection of these devices), there can be one server and 7 clients communicating with it at one time. for our purposes the computer running labview is the server and the android phone is the client.



before transmission of data can happen the following three events must occur.
1. discovering
  • the server makes a discovery request.
  • clients within bluetooth range (<30ft) that are set to the discoverable mode will respond to this request with a set of information about themselves such as device name, class, and unique mac address. [note: the discovery request can also be initiated by a client. in this case the server and all other devices within range will respond to this request].
  • when the server chooses a client to pair with, a request for pairing is automatically sent to that specific client.
2. pairing
  • the server and the client share a link-key which is used for authentication between the two.
  • once the two devices are paired the server and client share more security sensitive information required for an encrypted connection.
3. connecting
  • the server opens a bluetooth server socket and broadcasts a set of services identified by their channel numbers, names, descriptions and most importantly unique universally unique identifiers (uuid). [note: the uuid is a user defined string and can be anything as long as it stays within its standardized 128-bit format.]
  • the server waits and listens for incoming connection requests.
  • the client performs a service discovery protocol (sdp) lookup during which it searches the services provided by the server to find the one it wants to communicate with. the client does this by going through the uuids the server is providing and tries to match one of them with the uuid it has.
  • upon finding a match, the client requests to communicate on that specific channel.
  • the server hears this request and replies with a confirmation or a rejection. if the request is confirmed, the server shares the requested rfcomm channel with the client.
  • the two devices can now be considered connected and are ready for data transmission. data transmission happens until connection is lost or the server or client terminates the connection.


hacking with labview
here, you will get to set up your android phone and computer to transmit sensor data from the phone to labview.

hardware you will need:
  1. a computer with labview.
  2. a bluetooth adapter. (this is required if you computer does not have a built-in bluetooth card. my laptop does not, so i use the iogear bluetooth 2.1 usb micro adapter.)
  3. an android phone with bluetooth capability (e.g. samsung galaxy, htc, droid, etc.)
  4. usb cable to connect phone to computer.

software you will need: (download the following onto your computer)
  1. labview 2010 or above
  2. drivers for your bluetooth adapter
  3. download the android package
  4. android example.vi (the package in step 3 will install here, c:\program files\national instruments\labview 20xx\vi.lib\labviewhacker\android and run android example.vi)
  5. sendsensor.apk

bluetooth communication between computer and your phone
  • confirm your computer has bluetooth connection. (this hack was tested using the iogear bluetooth 2.1 usb micro adapter)
  • adding your android phone as a device to which your computer can connect to: (these instruction are for windows vista, but similar step should be taken for any other versions of windows)
  • go to control panel > hardware and sound > bluetooth device, and under optionstab you will see a section titled "discovery." check the box that says "allow bluetooth device to find this computer".
  • before clicking okay
  • at the same place, in another tab called devices you will see an "add..." button. click. "add bluetooth device wizard" will begin.
  • before proceeding the phone needs to be discoverable.
  • on your android phone turn on bluetooth. then go to settings > wireless & networks > bluetooth settings, and check the box next to "discoverable." your phone will be discoverable for 2 minutes, during which you can complete the pairing process from your computer.
  • back on the computer
  • click next in the bt wizard.
  • select your specific phone and click next.
  • when it asks you "do you need a pass key to add this device?" choose "let me choose my own pass key" and enter a code (e.g. 0101) and click next.
  • on your android phone you will see a pop up window titled "bluetooth pairing request," input the same code you created on your computer and press okay.
  • back on your computer, a window will pop up saying something like "windows needs to install driver software for your bluetooth peripheral device." choose "locate and install drivers." (if windows is unable to find driver software for "bluetooth peripheral devices," do not worry. proceed by clicking "finish" in the bt wizard.)
  • you should now be able to see your phone as a device under the devices tab incontrol panel > hardware and sound > bluetooth device. (your phone should now be paired with your computer. this does not mean your phone is connected to your computer yet.)

put android application on your phone

  • connect android phone to computer as "usb mass storage."
  • from your computer, open the android folder and copy sendsensor.apk onto the sd card.
  • disconnect phone so to have the sd card recognized by the phone.
  • on your phone, find "files" in the applications folder. click on "phone files" and find sendsensor.apk.
  • click and install. press done.
  • run labview application on your computer
  • navigate to c:\program files\national instruments\labview 20xx\vi.lib\labviewhacker\android and run android example.vi 
  • on the front panel find 'my bluetooth address' and make a note of the value underneath it (e.g. 00:02:43:7b:8c:2a). 
  • on your android phone, find and press on sendsensor (application with a fuchsia logo and a black compass). 
  • when you are asked for bluetooth device id, type in the "my bluetooth address" value. 

before clicking ok, press and hold the dialog box and select "copy all." this is so you can simply paste the address if you restart the application).
  • now press okay. 
  • press "search bt devices" in the android application.
  • press on the bluetooth device that has your computer bluetooth name and address (this option will also have the fuchsia logo next to it as opposed to a bluetooth logo).
  • in the application the screen will change from the "search" tab to the "control" tab.
  • you should now be transmitting data to your vi.


1. 'bluetooth name and address' identifies the bluetooth adapter used by the computer. 

2.'android initialize' creates a channel with user defined uuid and service name. this new channel is added on to the end of the services provided by the server. thus, the channel number is not user defined and depends on how long that list is. it then hangs the server vi until there is an incoming connection request from a client. when this request is received the vi continues if the uuid matches the one in the client's request. 

3. 'android data' reads in 144 bytes over the connection. the format the android application prepares the sensor values requires this specification. we then parse the incoming string based on how we have packaged it on the android side using the various parsing vi

0 comments:

Post a Comment

 
TOP