Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Basics of OSGi and Phidgets May 24, 2007 Department of Computer Science Guillermo Hernandez, Jose Reyes Alamo Understanding the basics of OSGi and Phidgets Programming Smart Home Lab Iowa State University Department of Computer Science Basics of OSGi and Phidgets May 24, 2007 Guillermo Hernández, José M. Reyes Álamo Phidgets • Definition - User-friendly system available for controlling and sensing the environment from your computer. No hardware knowledge needed, just a matter of plugging into the USB port on your computer and use Phidgets software libraries to access these devices. Department of Computer Science Basics of OSGi and Phidgets May 24, 2007 Guillermo Hernández, José M. Reyes Álamo Phidgets Hardware Installation 1. Connect one end of a USB cable to the phidget and the other end to the computer. 2. (Optional) If the phidget requires power make sure to plug it to a power source. Department of Computer Science Basics of OSGi and Phidgets May 24, 2007 Guillermo Hernández, José M. Reyes Álamo Phidgets Software Intallation 1. 2. 3. 4. Go to www.phidget.com and click on downloads. Click on the link for Phidget21 Downloads Download the file PHIDGET.MSI Install the PHIDGET.MSI. This file allows your OS to easily interact with the Phidgets. 5. Download Java JNI Library - Phidget21 to a known location. This is a .jar file that will be used later for application development. Department of Computer Science Basics of OSGi and Phidgets May 24, 2007 Guillermo Hernández, José M. Reyes Álamo Using Phidgets – RFID Project 1. 2. 3. 4. 5. 6. 7. 8. 9. Open Eclipse and go to File NewProject and select Java Project Click Next and give an appropriate name to the project and click Finish. RIGHT click under you project name and click on Properties On the menu to the left, click on Java Build Path On the Tab Menu click on Libraries Click on Add External JARs. Locate the file called phidget21.jar (just downloaded) Create a new Class Import the following packages: com.phidget.* and com.phidget.event.* Department of Computer Science Guillermo Hernández, José M. Reyes Álamo • • • • • • • • • • • • • • • • • • • • • • import com.phidgets.*; import com.phidgets.event.*; public class RFIDExample{ public static final void main(String args[]) throws Exception { RFIDPhidget rfid; rfid = new RFIDPhidget(); rfid.addTagGainListener(new TagGainListener(){ public void tagGained(TagGainEvent oe){ System.out.println(oe); } }); rfid.openAny(); rfid.waitForAttachment(); System.out.println("Serial: " + rfid.getSerialNumber()); System.out.println("Outputs: " + rfid.getOutputCount()); rfid.setAntennaOn(true); rfid.setLEDOn(true); System.in.read(); rfid.close(); rfid = null; } } Basics of OSGi and Phidgets May 24, 2007 Department of Computer Science Basics of OSGi and Phidgets May 24, 2007 Guillermo Hernández, José M. Reyes Álamo OSGi • What is OSGi? – OSGi stands for Open Services Gateway Initiative. – It is an open standards organization composed of companies like Sun Microsystems, IBM, Motorola among many others. – Provides a Java based service platform that can be remotely managed. Department of Computer Science Basics of OSGi and Phidgets May 24, 2007 Guillermo Hernández, José M. Reyes Álamo OSGi • Key terms in OSGi – Bundle- a java JAR file that contains service definition and implementation. – Service- a function provided by a bundle. (e.g. reading the temperature of a temperature sensor). – Framework- the central component of OSGi. It is the execution environment for services and bundles. Basics of OSGi and Phidgets May 24, 2007 Department of Computer Science Guillermo Hernández, José M. Reyes Álamo OSGi Figure 1- OSGi Framework Basics of OSGi and Phidgets May 24, 2007 Department of Computer Science Guillermo Hernández, José M. Reyes Álamo OSGi Smart Home Application Application Layer Use services published by bundles Service Layer Use service published by other bundles Service Service Service Services published by bundles Knoplerfish OSGI Framework Bundles deployed to framework Bundle Bundle Bundle Bundle Actuator Actuator Atlas Node Physical Layer . . . . . Sensor Sensor Figure 2- Service Oriented Framework Department of Computer Science Basics of OSGi and Phidgets May 24, 2007 Guillermo Hernández, José M. Reyes Álamo OSGi Code Demonstration •How to create a bundle •How to create and publish a service •How to use a service Department of Computer Science Guillermo Hernández, José M. Reyes Álamo Questions Basics of OSGi and Phidgets May 24, 2007