Wiki - 1.9 Serial Communication

Compatibility

Steps

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 require dialout group membership via sudo adduser $USER dialout. Reboot required.

  1. 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]);
   }
}
  1. Opening a local COM port
qz.openPort("COM1"); //e.g. /dev/ttyS0, /dev/ttyUSB0, depending on platform
   
function qzDoneOpeningPort(port) {
   alert(port + " open");
}
  1. 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");
  1. Receiving the response
// Retrieve serial response (automatically called)
function qzSerialReturned(port, data) {
   alert(port + " returned:\n\t" + data);
}
  1. Closing the COM Port
qz.closePort("COM1"); // e.g. /dev/ttyS0, /dev/ttyUSB0
   
function qzDoneClosingPort(portName) {
   alert(port + " closed");
}
Edit this page