Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Serial Communication

klabarge edited this page Jun 5, 2015 · 11 revisions

###Serial Communication Since version 1.6.0, You can send and receive data using the jSSC plugin (requires /dist/lib/jssc_qz.jar).

// List serial ports
qz.findPorts();

function qzDoneFindingPorts() {
   var ports = qz.getPorts().split(",");
   for (p in ports) {
      alert(ports[p]);
   }
}

qz.openPort("COM1"); //Can be dev/ttyS0, /dev/ttyUSB0, depending on platform
   
function qzDoneOpeningPort(portName) {
   alert("Port [" + portName +  "] is open!");
}

// Send serial data
// Beggining and ending patterns that signify port has responded
// chr(2) and chr(13) surround data on a Mettler Toledo Scale
qz.setSerialBegin(chr(2));
qz.setSerialEnd(chr(13));
// Baud rate, data bits, stop bits, parity, flow control
// "9600", "7", "1", "even", "none" = Default for Mettler Toledo Scale
qz.setSerialProperties("9600", "7", "1", "even", "none");
// Send raw commands to the specified port.
// W = weight on Mettler Toledo Scale
qz.send(document.getElementById("port_name").value, "\nW\n");
   
   
// Retrieve serial response (automatically called)
function qzSerialReturned(portName, data) {
   alert("Port [" + portName + "] returned data:\n\t" + data);
}
   
qz.closePort("COM1"); //Can be dev/ttyS0, /dev/ttyUSB0, depending on platform
   
function qzDoneClosingPort(portName) {
   alert("Port [" + portName +  "] is open!");
}