Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Web Control

Status
Not open for further replies.

AtomSoft

Well-Known Member
I wasnt sure on where to place this but here it goes....

I want to control my serial port via web page. Meaning i want to host a site and serve a page (this part is done...not the page tho) that when i log in i can send signals to my servers Serial Port. The server is my main PC... Which has the software.. I use WampServer... which is Apache, MYSQL, PHP combined in a simple install package.

what language do you think i can use to interface to my PCs Serial Port?

JavaScript, PHP ? Need some help here. Thanks for taking the time to check this post out.

THE MORE SPECIFIC MAIN QUESTION ::::

what language do you think i can use to interface to my PCs Serial Port?

I already have a server setup and most items just need to know which or where to look.
 
Last edited:
THE MOST F***ING THING YOU DID WAS USING PHP....
now go and get some library for c where you get controls on your serial ports called port programming , connect it to your php ,(you can get so many modules to connect php to c)
or else go for asp.net where the things are in access..
now get a usb wireless connector or some wireless dongle on both sides...can also use bluetooth dongle...many options........
then go on and learn programming for ports....
however the best language supposed for port programming is MATLAB if you can do it then you are at your best....
PHP-->C--->SERIAL PORTS OR PHP--->MATLAB--->PROGRAM NOW!!!!

FOR ASP.NET AND C#....**broken link removed**
 
Last edited:
Reloadron thanks but i want to control from a PC WEB PAGE not program :D

PerilBrain thanks even tho the foul language isnt needed :D

I can program in C for PC without too much issue but how can i connect PHP to my C program?

I just downloaded Visual Studio Web Express 2010 ... Hoping this will help me out. Going to read now...
 
Reloadron thanks but i want to control from a PC WEB PAGE not program

Me thinks me is missing something here. :)

When you say control from a PC web page do you mean just open a form on a PC and control outputs to the serial port? As in working from the same PC you are sitting at?

Ron
 
Got it working with PHP but only to send data not to receive but heh its a great start. I can turn on a LED from my web site... Also using a FTDI board so its USB now :D
 
Hi Jason,

I've done this kind of thing before but not on Windows. On Unix-based systems it's much easier since the ports (all devices, actually) are represented as files you can just write to and read from. It's more complicated in Windows.

I think your best bet starting out would be php_ser.dll. I haven't used it personally but it claims to do what you want.

Another route is serproxy. I haven't personally used it but there seems to be quite a few people who do, even though it hasn't been updated in a while.

If you need any help with the PHP/MySQL end of things I can give you a hand (PM me if I'm not active). Interfacing web to hardware is a pretty large part of how I've made my living for most of this century. :)


Torben
 
Got it working with PHP but only to send data not to receive but heh its a great start. I can turn on a LED from my web site... Also using a FTDI board so its USB now :D

Heh. You wrote that while I was writing my response. Yeah, that package only writes on Windows. Works on other platforms though. Not sure about USB on Windows (again on *nix it's just reading and writing a file) and I'm too hungry to Google it right now. I'll check back later.


Torben
 
Thanks i think Linux/Unix for a OS for web serving is he best idea anyway. Since they are so fast.

I have another PC here i will install some linux on it and see what i can do also.
 
I have been using Debian LAMP for a long time. Just cmd line apps. It works well but a person who wants to with with GUI's will not like it. Works fine but I have not used any others to compare to. I expect that by now someone must have packaged it with GUI's but have not bothered with it.
 
yeah. Thanks for the tip!! I will be setting up one today. Do you know of any good Linux OS to start with?

I'd second 3v0 on Debian. If you want a nice GUI by default then you could go with Ubuntu or Mint (Mint is based on Ubuntu but is more favoured by the technical crowd). Raw Debian can give you pretty much everything Ubuntu and Mint do--it's just that Ubuntu and Mint include a bunch of desktop software by default. If the machine you're going to install on is on the less-powerful side I'd go with raw Debian.

I'll warn you beforehand that it seems that the thing that bites most new Linux users in the *ss is the hardware drivers--specifically, wireless network drivers and graphics card drivers--but these days even those are covered pretty well.


Torben
 
I was doing further testing on multiple Characters on the PHP thing and it sux... It works sometime which means its a sync issue. I know its the PHP because it works fine in hyper terminal...

going to do a test install of debian on a Virtual Environment first
 
I was doing further testing on multiple Characters on the PHP thing and it sux... It works sometime which means its a sync issue. I know its the PHP because it works fine in hyper terminal...

going to do a test install of debian on a Virtual Environment first

Could also be port settings. What are the port settings on each end? Do you have a small snippet of the code which shows the problem?


Torben
 
9600-8-N-1:

PHP CODE:
Code:
    //Set the serial port parameters. The documentation says 9600 8-N-1, so
    $serial->confBaudRate(9600); //Baud rate: 9600
    $serial->confParity("none");  //Parity (this is the "N" in "8-N-1")
    $serial->confCharacterLength(8); //Character length   (this is the "8" in "8-N-1")
    $serial->confStopBits(1);  //Stop bits (this is the "1" in "8-N-1")
    $serial->confFlowControl("none");
//Device does not support flow control of any kind, 
//so set it to none.

NOTHING SHOWS A ISSUE. the data received in the buffer on PIC is not correct... But if i use a terminal program directly it works. But the web part isnt working since the data sometimes gets OR'ed with 0x80 and sometimes AND'ed with 0x7F
 
Last edited:
9600-8-N-1:

PHP CODE:
Code:
    //Set the serial port parameters. The documentation says 9600 8-N-1, so
    $serial->confBaudRate(9600); //Baud rate: 9600
    $serial->confParity("none");  //Parity (this is the "N" in "8-N-1")
    $serial->confCharacterLength(8); //Character length   (this is the "8" in "8-N-1")
    $serial->confStopBits(1);  //Stop bits (this is the "1" in "8-N-1")
    $serial->confFlowControl("none");
//Device does not support flow control of any kind, 
//so set it to none.

NOTHING SHOWS A ISSUE. the data received in the buffer on PIC is not correct... But if i use a terminal program directly it works. But the web part isnt working since the data sometimes gets OR'ed with 0x80 and sometimes AND'ed with 0x7F

Right--that code wouldn't show an issue. That's not nearly enough to do any kind of diagnosis. Are you using the php_serial class? As noted, that doesn't work properly on Windows.

If I get a chance I'll try to whip something up later tonight. I don't have Windows to test on but I'll see about a small test script for Linux. Should help eliminate some variables, anyway.


Cheers,

Torben
 
  • Like
Reactions: 3v0
OK, here's a simple test form/script. There are notes and comments in the code. This just writes, via a serial port, to a certain kind of power controller. For full duplex control you'd probably want to look into the select() function but this illustrates that communicating with a serial port in PHP under Linux is quite simple.

The command format should be easily modified to use your project's command language.

Code:
<html>
 <head>
  <title>PHP Testing: <?php echo phpversion(); ?></title>
  <style type="text/css">
     body {
       font-family: Helvetica, Verdana, sans-serif;
       font-size: 10pt;
       width: 500px;
     }
     h1 {
       font-size: 14pt;
     }
     .warning {
       color: red;
     }
  </style>
 </head>
 <body>
  <h1>Testing serial communication in PHP.</h1>
  <p>
   A simple serial port write test in a PHP form. The zone/level stuff is just
   because the first serial device I found uses that format. In this example I
   use /dev/ttyUSB0 as my serial port because I have a USB to RS-232 dongle on 
   a USB port since my laptop has no RS-232 ports.
  </p>
  <p class="warning">
   Warning: This is pretty much guaranteed NOT to work in Windows.
  </p> 
  <p class="warning">
   Disclaimer: This is test code only. NEVER use code like this in production.
   This code mixes logic and presentation and doesn't sanitize its inputs. It's
   insecure and hard to maintain.
  </p>
  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
   Zone: 
   <select name="zone">
<?php
     for ($i = 1; $i <= 16; $i++) {
         $selected = ((@$_POST['zone'] == $i) ? ' selected="selected"' : '');
         echo "   <option value='$i'$selected>$i</option>\n";
     }
?>
   </select>
   Level: 
   <select name="level">
<?php
     for ($i = 0; $i <= 255; $i++) {
         $selected = ((@$_POST['level'] == $i) ? ' selected="selected"' : '');
         echo "   <option value='$i'$selected>$i</option>\n";
     }
?>
   </select>
   <input type="submit" value="Set level" />
  </form>
  <hr />
  <pre>
<?php

/**
 * The real work happens here.
 */

if (!empty($_POST['level'])) {
    $port = '/dev/ttyUSB0';

    // Set up for 9600 bps, 8-n-1, no flow control.
    `stty -F $port`;
    `stty -F $port 96`; // 9600 bps
    `stty -F $port cs 8`; // character length 8
    `stty -F $port -parenb`; // no parity
    `stty -F $port -cstopb`; // no stop bit
    `stty -F $port clocal -crtscts -ixon -ixoff`; // no flow control
    
    $fp = fopen($port, 'w');

    // The next line just encodes the form data as the hardware requires.
    // This can easily be changed to support other command formats or textual
    // communication.
    $dsend = sprintf("%c%c%c%s\n", $_POST['zone'], $_POST['zone'], $_POST['zone'], $_POST['level']); 

    fwrite($fp, $dsend);
    fclose($fp);
}

?>
  </pre>
 </body>
</html>


Regards,

Torben
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top