Sending a signal from a web app to a LPT port

2.5k Views Asked by At

I need to make a web app send a signal to a LPT port. The hardware is designed to listen for a 0V or 5V TTL signal.

Do you know any activeX, PHP class, JS, or even a piece of intermediary software, or anything which could allow me to "plug" this LPT feature to a PHP/JS application used locally in a Windows environment?

2

There are 2 best solutions below

2
On

i never worked with this function but php has 1 that you can probably use https://www.php.net/Exec

edit this is an example that i found on the internet

<?php
$cmd = "start /D C:\OpenSA\Apache /B Apache.exe -D SSL";
exec($cmd,$output,$rv);
?>
2
On

We have a browser based ticketing (as in boxoffice tickets for cinemas) system, that uses a serial port to send commands directly to a ticket printer. Here is, how it works:

  • a tiny application, for historical reasons calle "the agent" is started, and reads a config file
  • this config file only contains a workstation ID and the path to the preferred browser executable
  • The agent asks for username and password, and authenticates to the server via plain HTTP (salted hashes, nothing secret going over the wire), sending also the workstation ID from the config file
  • If authentication is granted, the server sends a configuration (e.g. "port=com1", "baud=19200", ...), a session ID and a one-time URL
  • The agent starts the browser, pointing it to this one-time URL
  • The agent then goes into a long-poll loop via HTTP, thereby relaying commands from the server to the serial port, using the settings it got before (and relaying back any input from the printer, such as "paper out")

Basically, this means, that the same session is used by two clients at once: The browser and the agent - a very easy way to share information. In fact it means, the relayed serial port and the browser share a session.

I am sure, this can easily be adapted for your use.

For historical reasons, the agent is written in TCL/TK, as at that time this was the easiest way to get cross-platform HTTP and serial port handling on Windows (9x, NT and CE families), OSX and Linux. It also could most easily be packaged into a self-containing .exe (or the respective .app, ELF executable, ...)

Today, I would use C# for the agent, as Mono is now more than good enough to give you Mac, Linux, Android and iOS