120 likes | 258 Views
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.
E N D
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
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. • Basics of OSGi and Phidgets • May 24, 2007 Phidgets Department of Computer Science Guillermo Hernández, José M. Reyes Álamo
Connect one end of a USB cable to the phidget and the other end to the computer. (Optional) If the phidget requires power make sure to plug it to a power source. • Basics of OSGi and Phidgets • May 24, 2007 Phidgets Hardware Installation Department of Computer Science Guillermo Hernández, José M. Reyes Álamo
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. Download Java JNI Library - Phidget21 to a known location. This is a .jar file that will be used later for application development. • Basics of OSGi and Phidgets • May 24, 2007 Phidgets Software Intallation Department of Computer Science Guillermo Hernández, José M. Reyes Álamo
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.* • Basics of OSGi and Phidgets • May 24, 2007 Using Phidgets – RFID Project 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 Guillermo Hernández, José M. Reyes Álamo
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. • Basics of OSGi and Phidgets • May 24, 2007 OSGi Department of Computer Science Guillermo Hernández, José M. Reyes Álamo
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 OSGi Department of Computer Science Guillermo Hernández, José M. Reyes Álamo
Basics of OSGi and Phidgets • May 24, 2007 OSGi Department of Computer Science Guillermo Hernández, José M. Reyes Álamo Figure 1- OSGi Framework
Basics of OSGi and Phidgets • May 24, 2007 OSGi Department of Computer Science Guillermo Hernández, José M. Reyes Álamo Figure 2- Service Oriented Framework
Basics of OSGi and Phidgets • May 24, 2007 OSGi Department of Computer Science Guillermo Hernández, José M. Reyes Álamo Code Demonstration • How to create a bundle • How to create and publish a service • How to use a service
Basics of OSGi and Phidgets • May 24, 2007 Department of Computer Science Guillermo Hernández, José M. Reyes Álamo Questions