I use a device driver that captures the input from a reader (RFID) and sends it to the keyboard buffer (keyboard wedge). The captured data can (and must) be transformed intermediately with java script.

This javascript is processed within the driver context - unfortunately the javascript gets the captured "binary" data in a DATA variable of type string.

You can imagine what javascript does: it interprets the input as unicode and thus does not let you address byte by byte within the string - it changes arbitrarily between 1 ...4 bytes length depending on the value.

I simply need to get the binary string transformed to its readable string format: xf9268970 should read "f9268970". Whatever I tried sucked so far.

Thanks for any tip!

share|improve this question
Are you capturing it in a text field, or are you listening to keystrokes and capturing the ASCII values? – Diodeus May 4 at 15:17
Do you have access to the driver source? – Aaron Digulla May 4 at 15:55
Nope - no access to the driver source. It is a generic Windows driver (a keyboard wedge directing COM input to the keyboard - with javascript transformation) – Klaus May 9 at 13:18
feedback

2 Answers

I think you should be listening for keystrokes individually and recording the values in a variable instead of reading a text box.

share|improve this answer
As said: I cannot influence the way the data gets to the javascript as it is a driver-built-in javascript feature. I just get what the scanner reads. -Klaus – Klaus May 9 at 13:17
Because it is a keyboard wedge, you should be able to hook up a key listener in your own JS code. I've done this with a bardcode scanner that uses a keyboard wedge. – Diodeus May 9 at 13:22
You mean a key listener in the receiving input field?? But there are many - some within web pages, could even be an Excel cell ... so this might be the wrong place to do! – Klaus May 9 at 13:43
A key listener is universal. It does not depend of focus on an input, although you CAN make it so it drops out of the function if the input element does not have focus just by setting your own flag. – Diodeus May 9 at 13:55
I am afraid this goes beyond my capabilities ...and exceeds the effort I am willing to spend incl. support as this adjusted wedge should be rolled out to many computers, not just mine – Klaus May 9 at 14:05
feedback

First, a disclaimer. I haven't worked with binary data and javascript but maybe this could help.

Maybe you could loop through the string and use charAt to look at each character. From what I understand charAt returns an ASCII value (not unicode). So instead of 4 bytes you would get 2 bytes(?)

var character;
for (var i = 0; i < str.length; i++) {
    character = str.charAt(i);
}

Maybe this reference will point you in the right direction: charAt reference

share|improve this answer
Unfortunately charAt and string length do not work on a one-character-per-code basis as you can see in the following example html page - it returns length=1 even if the code is 6 bytes long :-( – Klaus May 9 at 13:11
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script> var test = String.fromCharCode(0xFE707f75fe45); var out = '<b>fromCharCode(0xFE707f75fe45):</b>' + '<br>' + 'length= ' + test.length + '<br>' + 'charAt(0)= ' + test.charAt(0) + '<br>' + 'charAt(1)= ' + test.charAt(1) + '<br>' ; document.writeln(out); </script> </head> – Klaus May 9 at 13:15
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.