1.9 serial communication - qzind/qz-print GitHub Wiki
- ⛔ 2.x | ✅ 1.9 | ...
Since version 1.6.0, You can send and receive serial port data using the jSSC plugin.
Note: Serial support requires
jssc.jar, which is bundled with both QZ Print and QZ Tray. Note: Some Linux versions requiredialoutgroup membership viasudo adduser $USER dialout. Reboot required.
- Discovering local ports
qz.findPorts();
// Alert COM ports that are available
function qzDoneFindingPorts() {
var ports = qz.getPorts().split(",");
for (p in ports) {
alert(ports[p]);
}
}- Opening a local COM port
qz.openPort("COM1"); //e.g. /dev/ttyS0, /dev/ttyUSB0, depending on platform
function qzDoneOpeningPort(port) {
alert(port + " open");
}- Sending data to an open COM port
// Setup beginning and end patterns for a successful message
qz.setSerialBegin("\x02"); // STX for Mettler Toledo Scale
qz.setSerialEnd("\x0D"); // ETX for Mettler Toledo Scale
// Baud rate, data bits, stop bits, parity, flow control
qz.setSerialProperties("9600", "7", "1", "even", "none");
// Send raw commands to the specified port.
// W = weight on Mettler Toledo Scale
qz.send("COM1", "\nW\n");- Receiving the response
// Retrieve serial response (automatically called)
function qzSerialReturned(port, data) {
alert(port + " returned:\n\t" + data);
}- Closing the COM Port
qz.closePort("COM1"); // e.g. /dev/ttyS0, /dev/ttyUSB0
function qzDoneClosingPort(portName) {
alert(port + " closed");
}