Friday, March 9, 2007

LPTRA

And for EE fanatics I've implemented the resource adapter (JCA 1.5 with CCI), a right-way to access parallel port from inside EE applications. To use it, you need UParPort library installed. Then, simply deploy this RAR (resource adapter archive) into your application server. When you have done it, create a datasource for the LPTRA. You will have to specify pin names, while you are creating the datasource, like this: 1PinName=eye1, 2PinName=eye2 and so on. That's all. You may download the sources of the LPTRA as well.

Example:

@Resource (name = "eis/ParPort")
private ConnectionFactory connFactory;

Connection conn = null;
try {
conn = connFactory.getConnection();
Interaction interaction = conn.createInteraction ();
MappedRecord r =
connFactory.getRecordFactory ().createMappedRecord ("");

r.put ("eye1", true); // turn eye1 pin into the on state
r.put ("eye2", false); // turn eye2 off
interaction.execute (null, r);
} catch (ResourceException e) {
e.printStackTrace (); // Not sexy
} finally {
if (conn != null) {
try {
conn.close();
} catch (ResourceException e) {
e.printStackTrace (); // Not sexy
}
}
}

No comments:

Post a Comment