Last active
September 13, 2020 10:15
-
-
Save tresf/65a6054a660c20feb69d6520840e0b34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"> | |
<title>QZ Tray Sample Page</title> | |
</head> | |
<!-- Required scripts --> | |
<script type="text/javascript" src="js/dependencies/rsvp-3.1.0.min.js"></script> | |
<script type="text/javascript" src="js/dependencies/sha-256.min.js"></script> | |
<script type="text/javascript" src="js/qz-tray.js"></script> | |
<body onload="start();">Check console! | |
<a href="javascript:serial();">do serial</a> | |
</body> | |
<script> | |
var start = function() { | |
qz.websocket.connect(); | |
} | |
var serial = function() { | |
qz.serial.setSerialCallbacks(function(evt) { | |
if (evt.type !== 'ERROR') console.log('Serial', evt.portName, 'received output', evt.output); | |
else console.error(evt.exception); | |
}); | |
var bounds = { | |
start: '\x02', | |
end: '\x0D', | |
width: null | |
}; | |
var props = { | |
//baudRate: 9600, | |
dataBits: 7, | |
stopBits: 1, | |
parity: 'EVEN', | |
flowControl: 'NONE' | |
}; | |
var propsBounds = { | |
start: bounds.start, | |
end: bounds.end, | |
width: bounds.width, | |
// baudRate: props.baudRate, | |
dataBits: props.dataBits, | |
stopBits: props.stopBits, | |
parity: props.parity, | |
flowControl: props.flowControl | |
} | |
var port = null; | |
qz.serial.findPorts().then(function(ports) { | |
port = ports[0]; | |
// NEW BEHAVIOR | |
return qz.serial.openPort(port, propsBounds); | |
// OLD BEHAVIOR | |
// return qz.serial.openPort(port, bounds); | |
}).then(function() { | |
// NEW BEHAVIOR | |
return qz.serial.sendData(port, 'W\n'); | |
// OLD BEHAVIOR | |
// return qz.serial.sendData(port, 'W\n', props); | |
}).catch(function(err) { | |
console.error(err); | |
}); | |
}; | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment