Serial port access via php

I tried to play with serial port access with PHP, but didn't have much luck.

I tried using fsockopen, fopen, proc_openetc. I can not read or write to the socket.

Example:

$fp = fopen("/dev/ttyUSB0", "w+");
fwrite("enable");
echo fread($fp, 1024);
+5
source share
1 answer

I have come across this many times in the past. A control interface was once created for the Cisco 2811. This might work for you, although I'm not sure about your version of IOS (assuming that Cisco is because of yours fwrite();through the console).

See if the user has first access to the device. Easy, this can be done with screen /dev/ttyUSB0. Run your commands to disconnect, press ctrl+a, then d.

stream_* - .

:

$stream = stream_socket_client("udg:///dev/ttyUSB0", $errno, $errstr, 30);
fwrite($stream, "enable");

while(true){
    $line = stream_get_contents( $stream );
    if($line == 'exit'){
        break;
    }
}

stream_socket_client , .

, , , - DirectIO. , , .

: http://code.google.com/p/php-serial/source/browse/trunk/

+3

All Articles