By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
463,162 Members | 741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 463,162 IT Pros & Developers. It's quick & easy.

Filter and convert hex characters received through a serial port into keystrokes

P: 547
I am developing an RFID-based timing system for timing cycling races. Currently have an application which was written for manual entry of race numbers using the keyboard. The RFID reader passes hex data to the PC through a serial or TCP port. I need to convert the received data into meaningful race numbers and then transmit these numbers to the app as keystrokes. i.e 0004, or 0005, etc. followed by a comma and "ENTER"
The problem is that there is a lot of other characters which get sent through from the device and these need to be filtered out.
Another challenge is that we need to prevent duplication of numbers. The same number should not be read twice within a specific time period (say 5 minutes).

I am currently experimenting with an app called Twedge by TEC-IT.
It has the ability to filter the data using javascript.
The current code I am using is as follows:

Expand|Select|Wrap|Line Numbers
  1. // This script is executed whenever a data packet is received.
  2. // Use it to send the received data to other applications, to store it in a database 
  3. // or in a file. The actual data is accessed via the variable DATA.
  4. // In order to learn more about programming JavaScript please refer to any JavaScript 
  5. // documentation.
  7. // This is the TWedge default behaviour:
  8. // All data received via the current connection is converted into keystrokes.
  9. // 0-characters (NUL) are replaced with spaces.
  11. SendKeyStrokes (DATA.replace (/[^0-9]/g, ""));
  12. SendKeyStrokes (",");
  13. SendKeyStrokes ("{ENTER}");
Jan 11 '12 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 16,027
The code already filters out non-numeric characters. Is that sufficient?

For the other problem, does the app support cookies? If it does, you can store numbers in a cookie with a timestamp. You can avoid the need for this if the page will not require unloading (use, e.g., arrays in this case).
Jan 16 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.