phpphp-socket

Close opened COM port with PHP


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.


Solution

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