Skip to content

Instantly share code, notes, and snippets.

@nsmith
Created August 8, 2012 22:11
Show Gist options
  • Select an option

  • Save nsmith/3299300 to your computer and use it in GitHub Desktop.

Select an option

Save nsmith/3299300 to your computer and use it in GitHub Desktop.
imp
class rfidDevice
{
eventHandler = null;
serPort = null;
enabled = true;
rxData = "";
name = "Source";
type = "string";
constructor(port,handler)
{
eventHandler = handler;
serPort = port;
serPort.configure(115200,8, PARITY_NONE,1,NO_CTSRTS);
enable();
//hardware.uart1289.configure(115200, 8, PARITY_NONE, 1, NO_CTSRTS);
//disable();
}
function enable()
{
rxData = "";
enabled = true;
setUpPoll();
}
function disable()
{
enabled = false;
}
function setUpPoll() {
serPort.write(0x43);
serPort.write(0x03);
serPort.write(0x01);
serPort.write(0xCD);
poll();
}
function poll()
{
if(enabled)
{
imp.wakeup(1.0, poll.bindenv(this));
//hardware.uart1289.write(0x31,0x03,0x01);
//serPort.write(0x10,0x03,0x00);
//server.log("TX: 0x31,0x03,0x01")
//hardware.uart1289.write(0x43,0x04,0x01,0xcd);
local byte = serPort.read();
server.log("Raw:"+byte);
local byte = serPort.read();
server.log("Raw:"+byte);
while(byte != -1)
{
server.log("insideloop");
server.log("Raw:"+byte);
switch(byte)
{
case 0xFF : // Start of data
eventHandler(rxData);
server.log ("Caught Initial Byte");
rxData = "";
break;
default: // ID byte
rxData = (rxData+","+byte);
server.log("Data:"+rxData);
// eventHandler(rxData);
break;
}
// Get the next byte
server.log ("Read Next Byte");
byte = serPort.read();
}
}
}
}
class fetchData
{
output = null;
input = null;
rfid = null;
state = 0;
constructor (rfidDev)
{
server.log("Inside FetchData Constructor")
rfid = rfidDevice(rfidDev, rfidEvent.bindenv(this))
output = OutputPort("Activity", "number");
server.log(" Before Input Call Constructor")
input = ("a"); //inputRecieve(this);
imp.configure("Sticker Reader",[input],[output]);
}
function rfidEvent(id)
{
// rfid.disable();
server.log("ScannedIDs:"+id);
}
}
server.log("Starting Scan");
//imp.configure("Sticker Reader",[input],[output]);
inputSticker2 <- fetchData(hardware.uart1289)
// local input = gatherIDs();
// Register with the server
// imp.configure("I/O", [input], [output]);
// End of code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment