1

I am working to connect a Serial COM port to send and receive data through PHP. And I don't have device so i have created a Virtual com port to test data.

I can see my code is sending data as i can see the sent bytes on VSPD interface. But problem is that i can't receive data for testing purpose i want to read as well.

Is there any good Virtual com port emulator or any other suggestion ?

exec("mode COM3 BAUD=9600 PARITY=N data=8 stop=1 xon=off");
$fp = fopen("com3", "w");
if (!$fp) {
    echo "Not open";
} else {
    sleep(10);
    echo "Open";
    fwrite($fp, "jhh0");
    $buff = fread($fp, 10);
    echo ">> ".$buff." <<";
    //fclose($fp);
}
  • 2
    You're opening the port in `w` mode (write-only). Try opening it in `w+` (read/write) mode. – rickdenhaan Jun 09 '17 at 21:55
  • ok then how should i receive data.. i want to display anything even OK message works for me. i just want to test code –  Jun 09 '17 at 22:01
  • If you open in read/write mode, your `fread()` call should work for receiving response data. – rickdenhaan Jun 09 '17 at 22:03
  • Actually i was working on actual device... it hangs while reading so i want to read and display as well.. –  Jun 09 '17 at 22:06
  • https://stackoverflow.com/questions/44439255/php-trying-to-read-data-from-serial-com-port-windows this is also our post .... –  Jun 09 '17 at 22:10
  • https://github.com/Xowap/PHP-Serial/blob/develop/src/PhpSerial.php check out line 597 fread was not working there –  Jun 09 '17 at 22:14
  • Heh, I was just about to post a link to a [simplified version](https://github.com/lepiaf/serialport) of that library. You might want to look into using that, or seeing how they communicate with a serial port. – rickdenhaan Jun 09 '17 at 22:15

0 Answers0