Some Scriptel ScripTouch devices come with a magnetic strip reader (for example the ST1525). When someone swipes a card it triggers OmniScript to send the strip data to a currently connected application.
This example shows how to deal with CardSwipe events:
function tutorial() {
var socket = new WebSocket("ws://localhost:8080");
socket.onopen = function() {
console.log("Web Socket Open");
};
socket.onclose = function() {
console.log("Web Socket Closed");
};
socket.onmessage = function(evt) {
var msg = JSON.parse(evt.data);
if(msg._class==="ConnectionOpen") {
//We've just connected to the server.
if(msg.serverInfo.devices.length>0) {
//Lets open the first available device:
var device = msg.serverInfo.devices[0];
console.log("Opening device",device.uuid,": ",device.manufacturer,device.product);
var obj = {"_class":"DeviceOpenRequest","uuid":device.uuid};
socket.send(JSON.stringify(obj));
}
} else if(msg._class==="CardSwipe") {
console.log("Track One: ",((!msg.trackOneError)?msg.trackOne:"ERROR: "+msg.trackOneError));
console.log("Track Two: ",((!msg.trackTwoError)?msg.trackTwo:"ERROR: "+msg.trackTwoError));
console.log("Track Three: ",((!msg.trackThreeError)?msg.trackThree:"ERROR: "+msg.trackThreeError));
}
};
}
The CardSwipe contains a member for each track and a member to check to see if any of the tracks contained errors. If the error members are false the track members are usable and should contain valid data. If the error members are not false there still may be partially correct data in their respective fields.
Each track will come back as a string. For financial cards there is a (semi-)standard format defined in ISO/IEC 7813. For identification cards (United States drivers licenses) the format is described here.