Difference between revisions of "GPIO Tutorial"

From RifidiWiki

Jump to: navigation, search
(New page: ==Getting Started== This page will give a very brief explanation of how to use the GPIO interface for a given reader. For this example we will use an LLRP reader. ==Steps== 1. Refere...)
 
 
(One intermediate revision by the same user not shown)
Line 11: Line 11:
 
filter="(reader=LLRP)" /></pre>
 
filter="(reader=LLRP)" /></pre>
  
2. Inject it into your application class, like so:
+
2. Inject it into your application class, like so (place the 'property' line with 'gpoController' into the 'bean' block for you application):
  
<pre>       <bean id="SampleApp" class="com.sample.app.SampleApp">
+
<pre>       <bean id="SampleApp" class="com.sample.app.SampleApp">
 
<constructor-arg index="0" value="Sample" />
 
<constructor-arg index="0" value="Sample" />
 
<constructor-arg index="1" value="SampleApp" />
 
<constructor-arg index="1" value="SampleApp" />
Line 20: Line 20:
 
</bean></pre>
 
</bean></pre>
  
3. In the
+
3. In the application class, add the "setter" method as specified via the 'name' field of the property object you specified before:
 +
<pre>        public void setGpoController(AbstractGPIOService<?> gpoController) {
 +
this.gpoController = gpoController;
 +
}</pre>
 +
 
 +
4. Now you can use the GPIO service on any reader of the chosen type connected to Rifidi.  Here is a short section of code demonstrating how to use it:
 +
 
 +
<pre>
 +
try {
 +
                        //Flash GPO ports 1, 2, and 4 high on reader LLRP_1 for 7 seconds
 +
this.gpoController.flashGPO("LLRP_1", 7, 1, 2, 4);
 +
                        //Test GPI port 1 on reader LLRP_1.  It will return true if the port is high and false if the port is low. 
 +
System.out.println(this.gpoController.testGPI("LLRP_1", 1));
 +
                        //Test GPI port 4 on reader LLRP_1.  It will return true if the port is high and false if the port is low. 
 +
System.out.println(this.gpoController.testGPI("LLRP_1", 4));
 +
                        //Sets GPO ports 3 and 4 of reader LLRP_1 to high and all other GPO ports on the reader to low. 
 +
this.gpoController.setGPO("LLRP_1", 3, 4);
 +
} catch (CannotExecuteException e) {
 +
e.printStackTrace();
 +
}
 +
</pre>

Latest revision as of 04:05, 5 March 2012

Getting Started

This page will give a very brief explanation of how to use the GPIO interface for a given reader. For this example we will use an LLRP reader.

Steps

1. Reference the abstract GPIO service in spring and filter it by the reader type that you would like to control. In this case, we would like the LLRP GPIO service, so our block of spring code will look like this:

<osgi:reference id="llrpGPIOService"
		interface="org.rifidi.edge.sensors.AbstractGPIOService"
		filter="(reader=LLRP)" />

2. Inject it into your application class, like so (place the 'property' line with 'gpoController' into the 'bean' block for you application):

        <bean id="SampleApp" class="com.sample.app.SampleApp">
		<constructor-arg index="0" value="Sample" />
		<constructor-arg index="1" value="SampleApp" />
		<property name="readZoneMonitoringService" ref="readZoneMonitoringService" />
		<property name="gpoController" ref="llrpGPIOService" />
	</bean>

3. In the application class, add the "setter" method as specified via the 'name' field of the property object you specified before:

        public void setGpoController(AbstractGPIOService<?> gpoController) {
		this.gpoController = gpoController;
	}

4. Now you can use the GPIO service on any reader of the chosen type connected to Rifidi. Here is a short section of code demonstrating how to use it:

		try {
                        //Flash GPO ports 1, 2, and 4 high on reader LLRP_1 for 7 seconds
			this.gpoController.flashGPO("LLRP_1", 7, 1, 2, 4);
                        //Test GPI port 1 on reader LLRP_1.  It will return true if the port is high and false if the port is low.  
			System.out.println(this.gpoController.testGPI("LLRP_1", 1));
                        //Test GPI port 4 on reader LLRP_1.  It will return true if the port is high and false if the port is low.  
			System.out.println(this.gpoController.testGPI("LLRP_1", 4));
                        //Sets GPO ports 3 and 4 of reader LLRP_1 to high and all other GPO ports on the reader to low.  
			this.gpoController.setGPO("LLRP_1", 3, 4);
		} catch (CannotExecuteException e) {
			e.printStackTrace();
		}
Personal tools