This repository has been archived by the owner on Dec 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
1.9 Serial Communication
klabarge edited this page Sep 7, 2016
·
2 revisions
- ⛔ 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 requiredialout
group 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");
}