Read weight of package from a Fedex scale within web application?
I've been asked if I can read the weight from a scale, connected via RS232, and dump it into a web applica开发者_如何学Pythontion. Reading the weight of the scale from the local machine isn't bad (this SO question gives an explanation: RS232 question - how to read weight to PC), but...
How do I then get that data to paste into a box in my web application...? Ideas?
I'm running into a similar-but-reverse situation with Fedex and UPS labels. I can get the label data within the web application, but I need to send that data via a raw printer socket (i.e. I can't just File > Print) to the local printer... how?
FedEx and UPS now how Zebra printers that can be network attached. Printing to them is easy via .NET and the standard Windows Spooler using the UNC path to the printer. The trick is how to expose the printer to your web application. If you web application is on the same network as your printer (intranet), the answer is simple. Send the data to the printer via the Windows Spooler from your web server in a server side call from your web app clients. If your web application is hosted outside of your local network, stand up a web service and write a web service to receive the ZPL (Zebra Printer Language) from your web app. The web service would also use the windows spooler to send to the printer on the same network.
Usually web applications are unable to communicate directly with a PC unless there's a full trust between the server and the client. Even then, web pages lack the ability to talk to peripheral devices for myriad security reasons. For a problem like this, you'd almost have to run some kind of client/service background application on the PC.
For the print from web app functionality, QZ Tray is a little java app that does the heavy lifting for you. You can snakeoil a cert, too, instead of paying for their custom cert for their silent printing.
I've been asked if I can read the weight from a scale, connected via RS232, and dump it into a web application.
Although this can't be done directly through JavaScript, a custom client-side or server-side solution can help. There are some server-side and desktop products which expose this functionality to a webpage (RS232 scales, USB scales)
To elaborate specifically on Gordon's recommended QZ Tray approach (assumes the PC has QZ Tray installed; assumes the page has been configured to use QZ Tray), here's a technique which will work for a serial port connected to a Mettler Toledo scale. The commands vary between scale suppliers, so adapt as needed.
Disclaimer, we're the authors of QZ Tray.
Connect to COM1, send command, disconnect
// MT = Mettler Toledo. Change as needed.
var port = 'COM1'; // <-- COM1, '/dev/ttyUSB0', etc
var cmd = 'W\n'; // <--- MT Weight command
var baud = {
baudRate: 9600,
dataBits: 7, // <--- MT Changed from 8
stopBits: 1,
parity: 'EVEN', // <--- MT Changed from NONE
flowControl: 'NONE'
};
var delims = {
begin: '\x02', // <--- MT start of message
end: '\x0D', // <--- MT end of message
width: null // <--- MT doesn't use width
};
qz.serial.openPort(port, delims).then(function() {
return qz.serial.sendData(port, cmd, baud);
}).catch(function(err) { console.error(err); } );
qz.serial.setSerialCallbacks(function(evt) {
if (evt.type !== 'ERROR') {
console.log('Serial', evt.portName, 'received output', evt.output);
} else {
console.error(evt.exception);
}
// Close port
return qz.serial.closePort(evt.portName);
});
I'm running into a similar-but-reverse situation with Fedex and UPS labels. I can get the label data within the web application, but I need to send that data via a raw printer socket (i.e. I can't just File > Print) to the local printer... how?
Duplicate of https://stackoverflow.com/a/28783269/3196753.
精彩评论