Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class rfidDevice extends InputPort
- {
- serPort = null;
- enabled = true;
- rxData = "";
- constructor(port)
- {
- serPort = port;
- serPort.configure(115200,8, PARITY_NONE,1,NO_CTSRTS);
- enable();
- }
- function enable()
- {
- rxData = "";
- enabled = true;
- poll();
- }
- function disable()
- {
- enabled = false;
- }
- // Receive 0 = disable, 1 = enable on our input port
- function set(value)
- {
- if(value == 0)
- {
- disable();
- }
- else
- {
- enable();
- }
- }
- function poll()
- {
- if(enabled)
- {
- imp.wakeup(0.1, poll.bindenv(this));
- serPort.write(0x10);
- serPort.write(0x03);
- serPort.write(0x00);
- local byte = serPort.read();
- while(byte != -1)
- {
- //server.log(format("Raw: %02x", byte));
- switch(byte)
- {
- case 0xFF : // Start of data
- //server.log("Caught Initial Byte");
- rxData = "";
- break;
- default: // ID byte
- rxData += byte;
- // Add some code here to decide when the received data is complete
- // and perhaps send it to an output? e.g.
- if(strlen(rxData) == 8)
- {
- output.set(rxData);
- server.log(format("Got ID: %s", rxData));
- rxData = "";
- }
- break;
- }
- // Get the next byte
- byte = serPort.read();
- }
- }
- }
- }
- local output = OutputPort("Result", "string");
- local rfid = rfidDevice(hardware.uart1289);
- imp.configure("Sticker Reader",[rfid], [output]);
- server.log("Starting Scan");
- // End of code.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement