Computing.Net > Forums > Web Development > Remote access to serial port

Remote access to serial port

Reply to Message Icon

Original Message
Name: Larry21
Date: July 19, 2004 at 19:29:44 Pacific
Subject: Remote access to serial port
OS: Windows XP HE
CPU/Ram: P4 2.6+HT 512MB
Comment:

Hi,

I have a serial port served as an IP address with its own port (ie. 134.242.434.443:4444) and I would like to be able to send it commands remotely without the client having to download an interface (though a small applet would be fine...)

Basically, I have some motors that will be connected to the serial port that I want to be accessible through a standard web browser. I was thinking of using Java, but am not clear on how to do this. The details of programming each command is something that I'll work out on my own (hopefully), but the basic principles on how to have this running is something that I need more info on.

If there is a simple java/html/other script that would normally be intended for simple 'up-down-right-left' commands that control output on a remote serial port (ie. to control the pan/tilt of the camera), this would probably work in my case- I just have not found one that is either basic enough to just go up-down etc. or one that is understandable by me to know how to set it up.

Any help would be greatly appreciated.

Thanks,
Larry


Report Offensive Message For Removal


Response Number 1
Name: SN
Date: July 19, 2004 at 20:18:48 Pacific
Subject: Remote access to serial port
Reply: (edit)

Larry-
What do you want to happen on the client side? If this is for a camera, I suppose it's reasonably safe to assume that you want its image displayed?

If you want a large degree of interactivity, then Java is your best choice. If just retrieving a still shot every few seconds is fine, then you might consider just using whichever language is your favorite to control the serial port and use a typical server side script/html solution (like PHP).

Your first step would be to create a console application in your language of choice that takes input from the console and controls the serial port accordingly. Converting this into a program that takes the information from the POST data instead of the console would be reasonably simple.

If you decide to use a java applet, the work gets considerably more difficult, but the end product would be much nicer.

-SN


Report Offensive Follow Up For Removal

Response Number 2
Name: Larry21
Date: July 19, 2004 at 20:43:35 Pacific
Subject: Remote access to serial port
Reply: (edit)

Thanks for replying.

I dont need anything with pictures or videos for this, all I need is for someone to be able to enter the website, (possibly download a little program,) and be able to press the up arrow and a simple 'on' command would flash on one of the serial pins; and pressing the down button would trigger another pin to activate...etc. I currently have the port 'served' via a neat little service that assigns a tcp/ip port number for it (though I dont know if this will be neccessary in the final application...)

I seriously have very little experience in programming in Java and VB, and I certainly cant figure out how to do this with simple HTML. What I need to know is basically either of a link to some server/client software that may do just this type of thing (I would think that many hobbyists would want to remotely control their serial devices...) or a little explanation on how to set the thing up with Java- ie. that I have to write a 'servlet' or a client piece or license it etc... I truly have no clue in this area (once I have the basic idea I would work real hard and figure the rest out, but the basics I would still need as a guideline...)

Thanks,
Larry


Report Offensive Follow Up For Removal

Response Number 3
Name: SN
Date: July 19, 2004 at 21:16:11 Pacific
Subject: Remote access to serial port
Reply: (edit)

Larry-
For java, try taking a few java tutorials, then check out the Java communications API. There are some simple serial port examples there.

Once you get it working as a console application, check out JSP (or any server-side language you want to and just call java applications from inside them) to convert it to a client/server application.

An applet is probably overkill for the situation you've described.

You certainly aren't limited to Java...If you can find any programs that can do what you want from the command line (ie openserial.exe 01001100 or something to set certain serial port pins), then you just have to write a simple server side program in PHP or perl to run the program according to whether the user pushed up, down, etc. This would be the ideal situation. If you find such programs (probably written in C/C++), post back and we will fill in the blanks on how to get it working via the internet.

Luck,
-SN


Report Offensive Follow Up For Removal

Response Number 4
Name: Larry21
Date: July 19, 2004 at 21:19:51 Pacific
Subject: Remote access to serial port
Reply: (edit)

Thanks! I will look into this!


Report Offensive Follow Up For Removal

Response Number 5
Name: Larry21
Date: July 19, 2004 at 22:43:24 Pacific
Subject: Remote access to serial port
Reply: (edit)

Ok I have an app which actually controls the individual pins from the command line. (It is kind of backwards in that it needs the same command twice to do anything- ie. it would have to be lptout 255 <enter> lptout 255 <enter> lptout 0 <enter> lptout 0 <enter> in order to have one set turn on and off instantly. I dont think that this should be a real issue though- if you think it is then I'll look into another app.

So from here I now must get a script to control it I guess. It would be best if there were a way for the commands to be given by the keyboard and not the mouse- ie. that clicking on an 'activate' button (for example) would allow the user to then use the up/down/right/left keys to control the output without having to click on links with the mouse each time.

Thanks,
Larry


Report Offensive Follow Up For Removal


Response Number 6
Name: Larry21
Date: July 19, 2004 at 22:58:00 Pacific
Subject: Remote access to serial port
Reply: (edit)

PS- I decided to use the parallel port because there are more pins to work with and therefore no real need for a Basic Stamp or PIC etc. to interpret commands- all I need for now is 4 or five on/off's.


Report Offensive Follow Up For Removal

Response Number 7
Name: jshonk
Date: July 19, 2004 at 23:00:50 Pacific
Subject: Remote access to serial port
Reply: (edit)

We used digi boards back in the bbs day's, The pe8 or pe16. These were multi port intelligent Serial boards that you could send a simple init string to and make them close or open, Link or Unlink
Mostly used for BBs door’s. The most common was for APCI Doom that would send you out the BBs door to a 4 player doom server, I also seen them used in some of the early ISP server’s and RAS server’s. The down side was that they cost a bundle, How ever with all the mom and pop ISP’s folding up all over the place I would bet you could pick 1 up for near nothing. Just a thought,

Good Luck
Jim


Report Offensive Follow Up For Removal

Response Number 8
Name: Larry21
Date: July 19, 2004 at 23:25:47 Pacific
Subject: Remote access to serial port
Reply: (edit)

I hear ya, but I really dont need anything even remotely complex right now (maybe in the future) At this point, all I need is to have the ability to trigger simple on/off for 4 or 5 pins... I am not looking forward to programming command strings etc. right now (though if this works well, them maybe I'd look into that idea for more extensive control...)

Thanks,
Larry


Report Offensive Follow Up For Removal

Response Number 9
Name: SN
Date: July 20, 2004 at 15:18:27 Pacific
Subject: Remote access to serial port
Reply: (edit)

Larry-
Okay...This app is pretty trivial now that you have your program. Assuming you have that exe installed on c:\, you have PHP working on your computer, 255 corresponds to up, 0 corresponds to down, 128 corresponds to right, and 64 corresponds to left, you would do it like this:

<?php

if ($_POST['up'])
{
    system("c:\lptout 255");
    system("c:\lptout 255");
}

if ($_POST['right'])
{
    system("c:\lptout 128");
    system("c:\lptout 128");
}

if ($_POST['down'])
{
    system("c:\lptout 64");
    system("c:\lptout 64");
}

if ($_POST['left'])
{
    system("c:\lptout 0");
    system("c:\lptout 0");
}

?>
<HTML>
<HEAD><TITLE>webcam controls</TITLE></HEAD>
<BODY>
<FORM action="<?php echo $PHP_SELF ?>" method="POST">
<INPUT type='submit' name='up' value='up'><br>
<INPUT type='submit' name='right' value='Right'><br>
<INPUT type='submit' name='left' value='Left'><br>
<INPUT type='submit' name='down' value='Down'><br>
</form></body></html>

Here are some sites that should help you setting this up and understanding it:
PHP Installation Guide
PHP 'system()' documentation
PHP Tutorial
PHP Manual

Good luck,
-SN


Report Offensive Follow Up For Removal

Response Number 10
Name: Larry21
Date: July 20, 2004 at 22:47:37 Pacific
Subject: Remote access to serial port
Reply: (edit)

Thanks I will try this. I was trying to have it be able to use the actual arrow keys instead of having to press the buttons- do you know of a way to do this? I found a site that has this type of thing but it seems to only move two graphics and not do any actions on the remote server- here is the url: http://www.director-online.com/buildArticle.php?id=321

It seems that I have to install php capability in the server before this would run- I'll try and get that going.

Thanks again,
Larry


Report Offensive Follow Up For Removal

Response Number 11
Name: Larry21
Date: July 21, 2004 at 01:00:29 Pacific
Subject: Remote access to serial port
Reply: (edit)

I tried the above script and it did not seem to work- the buttons displayed but when pressed, I got an error page. Also, it says that lines 3, 9, 15, and 21 are invalid.


Report Offensive Follow Up For Removal

Response Number 12
Name: Larry21
Date: July 21, 2004 at 06:27:33 Pacific
Subject: Remote access to serial port
Reply: (edit)

OK this is where I'm holding: I fixed the code and now it seems to work (there were some errors before but they were ironed out)

Now I assume that I can implement it in the website, but it is somewhat different than what I was hoping. Firstly, it is not very 'real-time'- it takes about 1-2 seconds for each command to be executed. Do you think that there is a way to make it run quicker, or would this be the limit of TCP/IP? Also, (as I wrote before) would there be a way to have it controlled via the arrow keys instead of the mouse clicks? If the solution to both these issues would be found in creating a servlet and an applet, then I might just learn Java for this :-)

I was thinking of possibly using a JavaScript for the keyboard responses (there are several commands I believe that do that) and that it should 'call' the PHP script for the actual execution...

Thanks,
Larry


Report Offensive Follow Up For Removal

Response Number 13
Name: Larry21
Date: July 21, 2004 at 06:30:36 Pacific
Subject: Remote access to serial port
Reply: (edit)

For reference, here is the code that works (it seems that PHP has some strange rules for different situations):

<?php
{
if (isset($_POST['up']))
system("lptout 255");
system("lptout 255");
}
if (isset($_POST['right']))
{
system("lptout 128");
system("lptout 128");
}
if (isset($_POST['down']))
{
system("lptout 64");
system("lptout 64");
}
if (isset($_POST['left']))
{
system("lptout 0");
system("lptout 0");
}
?>
<HTML>
<HEAD><TITLE>webcam controls</TITLE></HEAD>
<BODY>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<INPUT type='submit' name='up' value="up">

<INPUT type='submit' name='right' value='Right'>

<INPUT type='submit' name='left' value='Left'>

<INPUT type='submit' name='down' value='Down'>

</form></body></html>


Report Offensive Follow Up For Removal

Response Number 14
Name: SN
Date: July 21, 2004 at 07:53:15 Pacific
Subject: Remote access to serial port
Reply: (edit)

Larry-
Yes, you should be able to use javascript to get the arrow key effect you're looking for. I'll write it tonight sometime if you haven't gotten it by then.

The PHP error you were getting is probably some configuration setup option to consider blank or null values as "false."

As I said before, if you need a large degree of interactivity (ie real time), then you may need a java applet...of course you'll still get some lag, but probably less. Some of the guys here probably have more experience in this than I do.

Good luck,
-SN


Report Offensive Follow Up For Removal

Response Number 15
Name: Larry21
Date: July 21, 2004 at 14:10:24 Pacific
Subject: Remote access to serial port
Reply: (edit)

Guys- any input?


Report Offensive Follow Up For Removal

Response Number 16
Name: Larry21
Date: July 22, 2004 at 22:10:19 Pacific
Subject: Remote access to serial port
Reply: (edit)

OK, this si the script that I have so far:

<HTML>
<HEAD>

<TITLE>webcam controls</TITLE>
<script type="text/javascript">


function register(e) {
if (!e) var e=window.event;

var keyHit=false;
if (e['keyCode']==38) document.keyForm.dire.value="up";keyHit=true;
if (e['keyCode']==40) document.keyForm.dire.value="down";keyHit=true;
if (e['keyCode']==39) document.keyForm.dire.value="right";keyHit=true;
if (e['keyCode']==37) document.keyForm.dire.value="left";keyHit=true;

if (keyHit==true) document.keyForm.submit();
}

function init() {
document.onkeydown = register;
//document.getElementById('FocusBox').focus();
}
</script>

</HEAD>
<BODY onload="init();">

<form name="keyForm" action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<input type="hidden" name="dire" value="null">
</form


<?php

if ($_POST['dire']=="up") {
system("lptout 253");
system("lptout 253");
system("lptout 255");
system("lptout 255");
}

if ($_POST['dire']=="down") {
system("lptout 251");
system("lptout 251");
system("lptout 255");
system("lptout 255");
}

if ($_POST['dire']=="right") {
system("lptout 254");
system("lptout 254");
system("lptout 255");
system("lptout 255");
}
if ($_POST['dire']=="left") {
system("lptout 247");
system("lptout 247");
system("lptout 255");
system("lptout 255");
}

?>
</body></html>


There are several issues though that I cannot figure out:

#1- When a key is pressed, it executes the command a thousand times over for as long as the key is pressed- something which is pretty backwards for this application. Do you know of a way for it to issue only one command maybe on an 'onkeyup' it would issue another (to terminate the command)?

#2- (Related to #1) How would one set it to execute a command onkeydown and execute another command on onkeyup? (I dont know how to program it in)

#3- (A 'major' issue) It seems to only allow one key press at a time. Thus, when one would press, say, the right arrow AND the up arrow, it will only use one of them and not both. In effect, one can only move in one direction at a time. How can this be changed? (If it is not possible to create simultanious actions, then a way around it may be to have a script which says 'if arrow up and arrow right are pressed together, then execute php command 'x'' If this is the only solution and anyone knows how to program this, it would be greatly appreciated!

Thanks,
Larry


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Remote access to serial port

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software