Giving PHP permission to access COM port

心已入冬 提交于 2019-12-04 03:26:17

问题


I'm creating a php script that connects to a 3G modem connected via serial connection on COM5.

I'm getting the following error and I believe it is because php does not have r/w access to COM5:

Warning: fopen(COM5:) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\SMStest\test2.php on line 9

// mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=off
$fp = fopen ("COM5:", "w+");
if (!$fp) {
    echo "Uh-oh. Port not opened.";
} else {
    $e = chr(27);
    $string  = $e . "A" . $e . "H300";
    $string .= $e . "V100" . $e . "XL1SATO";
    $string .= $e . "Q1" . $e . "Z";
    echo $string;
    fputs ($fp, $string );
    fclose ($fp);
}

回答1:


There are many ways to access COM ports on windows, alternatives to your method are opening it with the following paths:

\Device\00000123 (You can find the correct value in device manager, properties, details, physical device object name)

\\.\com5 (This is how I would open the port as a file if I was writing a program in C or something)



来源:https://stackoverflow.com/questions/9227219/giving-php-permission-to-access-com-port

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!