2

I run this PHP code to open my COM port. But i got an error

Warning: fopen(COM2): failed to open stream: Permission denied

Here is my code:

<?php

$fp = fopen('COM2', 'w+');
if (!$fp) {

    echo"Port not accessible";
} else {

    echo "port is open";
    set_time_limit(2);
}

What should i do? I used fclose($fp) function to do it. But it not works.

Jerodev
  • 32,252
  • 11
  • 87
  • 108
Nadishan
  • 580
  • 2
  • 7
  • 21
  • possible duplicate of [PHP COM port connection with DIO](http://stackoverflow.com/questions/23589702/php-com-port-connection-with-dio) – Jonathon Aug 20 '14 at 07:38
  • This method is not use DIO. It uses fopen – Nadishan Aug 20 '14 at 07:42
  • As PHP said, you don't have enough rights to open the COM2 port. And `fclose($fp)` is the good way to close your port. You certainly need to run your script as root/admin. – Kevin Labécot Aug 20 '14 at 07:42
  • I have done with this in admin privileges. – Nadishan Aug 20 '14 at 07:46
  • What OS are you running? Do you have any firewalls up? – DarthCaniac Sep 18 '14 at 15:08
  • fopen(COM2) means windows. You don't know that? – Nadishan Sep 19 '14 at 06:04
  • @Nadishan If you running on linux server (I'm not clear on what system you're running your script) try with this: [PHP Oficial Manual](http://php.net/manual/es/function.fopen.php#112243) – Joseph Collins Sep 21 '14 at 05:51
  • fopen command use different name for COM port on linux. – Nadishan Sep 21 '14 at 18:47
  • Refer to this: [http://stackoverflow.com/questions/5920600/open-com-port-in-php][1] And [http://stackoverflow.com/questions/9227219/giving-php-permission-to-access-com-port?lq=1][2] [1]: http://stackoverflow.com/questions/5920600/open-com-port-in-php [2]: http://stackoverflow.com/questions/9227219/giving-php-permission-to-access-com-port?lq=1 – ZooBoole Sep 25 '14 at 23:12

1 Answers1

2

It looks like windows (based at com name). If it's windows try to use full port name: \.\COM2, or escaping "\\.\COM2"

Styx
  • 1,303
  • 1
  • 19
  • 30