Professional Documents
Culture Documents
com/print/51837
BLOG Other
As I mentioned in the resource book of EE Software [1], the JavaScript code can connect to the
local serial port. The JavaScript is officially not allowed to access any local resources but the
web browser.
I also survey the Java Applet connection to serial port. The system requires a certificate for such
Applet, the code can have a fake certificate, but the system will prompt the users that the Applet
is suspicious and untrustworthy.
Here is a sample PHP code connects to the serial port. You can easily change the PHP code to
meet your demand. However, please don't embed the serial communication module into final
PHP web page as user UI part. We must remind that serial communication is a slow
asynchronous data communication between two entities, while web is state-less communication
method. And PHP code can not run forever to wait for a data, it has own timeout limitation. So it
is better to cache the two way communication datum in a "buffer" even in a fast local connection.
Otherwise the user will find the page halts very often. It is a bad user experience, they will give
up finally.
<?php
include "php_serial.class.php";
// Let's start the class
$serial = new phpSerial;
// First we must specify the device. This works on both linux and windows (if
// your linux serial device is /dev/ttyS0 for COM1, etc)
$serial->deviceSet("COM1");
// Then we need to open it
$serial->deviceOpen();
// To write into
$serial->sendMessage("Hello !");
// Or to read from
$read = $serial->readPort();
// If you want to change the configuration, the device must be closed
$serial->deviceClose();
// We can change the baud rate
$serial->confBaudRate(2400);
// etc...
?>
I believe that the connection between the web services and the local devices will be more and
more popular. Hopefully we can find more efficient methods to meet the design challenge.
Reference
[3]
[4]
Trademarks
Links:
[1] http://dev.emcelettronica.com/ee-software-development
[2] http://developer.garmin.com/web-device/garmin-communicator-plugin/
[3] http://www.activexperts.com/activcomport/howto/html/
[4] http://www.activexperts.com/support/kb/index.asp?ProductCode=003&IDCategory=325