Help sending commands to rs232/Comm1

Discussion in 'PHP' started by DiaboloMaster, Aug 1, 2006.

  1. #1
    I am trying to talk to a motor connected to comm1 of my computer. I want to send it the command "MA 25600". It is connected to Comm1. I am using fsockopen and fwrite. The code is as follows.

    <?php
    $a="";
    $b="";
    $c="localhost";

    if (!$fp=fsockopen($c,1, $a, $b , 15))
    {
    echo 'this did not work';
    }

    $out = "MA 256000";

    if(fwrite($fp, $out))
    {
    echo 'this worked';
    }
    ?>

    Please help to fix this.
     
    DiaboloMaster, Aug 1, 2006 IP
  2. DiaboloMaster

    DiaboloMaster Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I also tried this

    <?php
    $a="";
    $b="";
    $c="localhost";

    if (!$fp=fopen("COM1:", "w"))
    {
    echo 'this does not work';
    }

    $out = "MA 256000";

    if(fwrite($fp, $out))
    {
    echo 'this is working';
    }
    ?>

    This gives me the error
    Warning: fopen(COM1:): failed to open stream: Permission denied in c:\program files\easyphp1-8\www\sim\run.php on line 6
    and
    Warning: fwrite(): supplied argument is not a valid stream resource in c:\program files\easyphp1-8\www\sim\run.php on line 15
     
    DiaboloMaster, Aug 1, 2006 IP
  3. coderlinks

    coderlinks Peon

    Messages:
    282
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0