FAQ TWedge
JavaScript Commands for Common Operations (processData)
JavaScript Commands for Common Operations (processData)
Menu (TWedge V3) Device - Configure - Advanced - Script Editor - Edit Code in "processData"
Remove Carrige Return / Line FeedsData = sData.replace(/\x0D\x0A/g, ""); // remove CR/LFRemove leading whitespace
sData = sData.replace(/^\s+/, ""); // trim leading whitespaceReplace characters (via Hex Code)
sData = sData.replace(/\x2E/g, ","); // replace . => ,Remove character sequences
sData = sData.replace(/ d/, ""); // remove " d"Parse a single value from a CSV sequence
// sample data: 200, 177.50,mm ,01
if (sData.indexOf(',') > 0)
{
sData = sData.split(',');
sData = sData[1]; // take 2nd value
sData = sData.replace(/^\s+/, ""); // trim leading whitespace
}
// result will be 177.50
Parse a numeric value from a fixed data format.
// extract weight from scale data format: [STX] 13400 kg S Gross[CR]
var myRegexp = /^[\x02]\s(\d{1,5})\skg S Gross[\r\n]/;
var match = myRegexp.exec(sData);
if (match && match.length >= 2)
Print("Weight: " + match[1]); // first group value
else
Print("Weight does not match data format: [STX] nnnnn kg S Gross[CR]");
Add a time delay
function onHotkey ()
{
Print("onHotkey!");
hInstance.Sleep (300); // wait 0.3 secs
...
}