Connect A Local Device to A Remote Server

http://dev.emcelettronica.com/print/51837

Your Electronics Open Source
(http://dev.emcelettronica.com)
Home > Blog > allankliu's blog > Content

Connect A Local Device to A Remote Server
By allankliu Created 14/07/2008 - 05:28

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.

JavaScript and ActiveX

ActiveXperts.com offers serial communication software components for a bundle of languages, including HTML/JavaScript. I visited its FAQ page for HTML/JavaScript integration. The software component - ActiveComport, is a DLL for Windows. When user visits the web page, the DLL will try to download to the user's local drive, i.e. system folder. IE can fully support this feature via ActiveX object. But IE is disgraced for the easy to infect by viruses and Trojans and its flexibility. And it is not a cross-platform solution, at least not working for Safari and Opera. I am not sure about the Firefox yet. And definitely it does not support Linux OS. And installation ActiveComport.dll will prompt the users to change the security rules in IE...... Anyway, this approach is not a general purpose solution. We can find the similar solution from Garmin, which is a leading GPS supplier. It offers a browser plug-in for IE/Firefox to allow Garmin GPS to connect to the web page. The users can upload and download POI, GPX file. It is really a good idea, since Web GIS and GPS device can connect to each other without installation dedicated software. However the users must download and

1 din 4

15.07.2008 09:07

Connect A Local Device to A Remote Server

http://dev.emcelettronica.com/print/51837

install browser plug-in anyway. I am not sure about how Garmin solve it. But I believe it should be similar with ActiveXperts' solution. 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.

Alternative Solution with Local Web Server

It is a trend to integrate web service and local device via web widget or web page. We can achieve the goal with general technologies, without breaking browser's security rules and confusing end users. It is very important when the device is designed for regular consumers, instead of geeks. The solution is local web server. The web server is located in every computer. Either Windows or Linux PC can active the local web server easily. There are so many light weight server available everywhere, which the users can download and run it without installation. While server side script languages are free to connect to any local devices via serial port, Bluetooth and USB. The candidate script languages could be PHP, Python, Perl, and JSP. In this approach, there are two servers actually. One local server connects to local resource and device, the user is operated via web page from local server and remote server, the local server will exchange data with remote server. The approach is working independently on any OS and any browser. 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

2 din 4

15.07.2008 09:07

Connect A Local Device to A Remote Server

http://dev.emcelettronica.com/print/51837

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 The Garmin Communicator Plug-in is an exciting new software program that transfers data between websites and Garmin GPS Devices. The Garmin Communicator Plug-in API allows developers to integrate the Communicator Plug-in into any website. The API is a JavaScript library that provides user interface components that will transfer GPS data between a website and a Garmin device. The result is a toolkit that can connect any website’s visitors to Garmin devices with very little development

[2]

effort.

3 din 4

15.07.2008 09:07

Connect A Local Device to A Remote Server

http://dev.emcelettronica.com/print/51837

Using ActiveComport Serial Port Toolkit with HTML forms on a client PC

[3]

FAQ for HTML and Javascript projects of ActiveXperts serial communication.

[4]

Trademarks

Source URL: http://dev.emcelettronica.com/connect-local-device-remote-server 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

4 din 4

15.07.2008 09:07