Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Serial Port Communication
Old 09-21-2007, 02:16 PM Serial Port Communication
Zork's Avatar
Extreme Talker

Posts: 201
Trades: 0
Hi all,

Firstly, thank you for taking the time to read my problem.

I need to connect to an RPS-10 (remote power switch) on COM1 and send the following HEX commands:
02 18 18 02 18 18 30 31 0D

02 = ^B, 18 = ^X, 30 = 0, 30 = 1, 0D = ^M.

I can do this using hyperterminal or other demo programs, but I need to do it from a web application.

I've been trying to use ActiveX's ActiveComport, but none of their web apps have a way to specify sending the data as HEX.

Thanks a lot for your help,

Devin
__________________
"Computer games don't affect kids. I mean, if Pacman affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music..."
Zork is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-21-2007, 05:16 PM Re: Serial Port Communication
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Forget activeX...

Use a server side language, like asp or php.
I don't know about asp, but with php, you can use fopen('COM1:', 'w+') to open a connection to a com port, and then, you simply write to it.

From http://www.php.net/fopen
Quote:
jared at dctkc dot com
22-Apr-2002 10:33
PHP Code:
    <?php
// HOW TO USE PHP TO WRITE TO YOUR SERIAL PORT: TWO METHODS
$serproxy=true;
if (
$serproxy) {
    
// Use this code in conjunction with SERPROXY.EXE 
    // (http://www.lspace.nildram.co.uk/freeware.html)
    // which converts a Serial stream to a TCP/IP stream
    
$fp fsockopen ("localhost"5331$errno$errstr30);
    if (!
$fp) {
        echo 
"$errstr ($errno)";
    } else {
        
$e chr(27);
        
$string  $e "A" $e "H300";
        
$string .= $e "V100" $e "XL1SATO";
        
$string .= $e "Q1" $e "Z";
        echo 
$string;
        
fputs ($fp$string );
        
fclose ($fp);
    }
} elseif (
$com1) {
    
// Use this code to write directly to the COM1 serial port
    // First, you want to set the mode of the port. You need to set
    // it only once; it will remain the same until you reboot.
    // Note: the backticks on the following line will execute the 
    // DOS 'mode' command from within PHP
    
`mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=off`;
    
$fp fopen ("COM1:""w+");
    if (!
$fp) {
        echo 
"Uh-oh. Port not opened.";
    } else {
        
$e chr(27);
        
$string  $e "A" $e "H300";
        
$string .= $e "V100" $e "XL1SATO";
        
$string .= $e "Q1" $e "Z";
        echo 
$string;
        
fputs ($fp$string );
        
fclose ($fp);
    }
}
?>
I know of an old collegue of mine (which I lost contact with) that used this method to control a power switch to his hosting local, in conjunction with a serial console.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-24-2007, 02:43 PM Re: Serial Port Communication
Zork's Avatar
Extreme Talker

Posts: 201
Trades: 0
Thank you so much your insight on this problem. I've managed to establish a connection with my RPS (I can see the link light blink). However, I can't seem to send it the proper hex values. Is there anyway to specify in php that chr(02) is actually hex, not decimal?

Thanks much!
__________________
"Computer games don't affect kids. I mean, if Pacman affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music..."
Zork is offline
Reply With Quote
View Public Profile
 
Old 09-24-2007, 03:05 PM Re: Serial Port Communication
Zork's Avatar
Extreme Talker

Posts: 201
Trades: 0
Finally! I did it! Using hexdec() I converted my hex into decimal and stuffed it into the darn thing it worked!

Mind you I had to throw a sleep() before it was written to allow the RPS to be "Ready".

Thanks a lot!!
__________________
"Computer games don't affect kids. I mean, if Pacman affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music..."
Zork is offline
Reply With Quote
View Public Profile
 
Old 09-24-2007, 06:12 PM Re: Serial Port Communication
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Well, glad you found out by yourself, and that it's working.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-24-2007, 06:22 PM Re: Serial Port Communication
Zork's Avatar
Extreme Talker

Posts: 201
Trades: 0
Well, you did most of the work.. however, I've run into a problem.

I'd like to avoid the need for sleep() entirely right now. Here's how things are set up currently:

open com1,
sleep(9)
write to com1
close com1.


You see with this RPS it takes exactly 9 seconds to be "Ready" for input, so I have to wait before I can write to the port after opening it. However, once it is open, I can write as often as I like. So, I'm wondering, is there is some way of opening com1 once and then just writing to it again and again? In this application I don't have to close the browser, but I need to navigate web pages within the server.
__________________
"Computer games don't affect kids. I mean, if Pacman affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music..."
Zork is offline
Reply With Quote
View Public Profile
 
Old 09-25-2007, 07:36 PM Re: Serial Port Communication
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
you could use vars or define after the first connect of the time,

if you know the time out settings, write a script that would run the first connect, after succesfull store a cookie with a value of first connect, then each time the you view a page increase the time on the cookie, or set it so when the user closes the browser it will terminate the cookie

then after the first cookie is store write something allong the lines of checking the cookie if it exists the skip sleep and go right to write to com but if cookie is invalid or expired run sleep then write to com
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1

Last edited by amw_drizz; 09-25-2007 at 07:37 PM..
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 09-25-2007, 07:55 PM Re: Serial Port Communication
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Sorry Zork, I didn't saw your reply...
But I've answered in your other post ==> http://www.webmaster-talk.com/php-fo...-that-way.html
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Serial Port Communication
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.56329 seconds with 12 queries