我正在尝试将以下小型QBASIC程序(可以100%工作)移植到PHP:
OPEN "com1:2400,n,8,1,DS," FOR RANDOM AS #3
OPEN "data.dat" FOR OUTPUT AS #2
REM read 17 chars from the port
scale$ = INPUT$(17, #3)
PRINT scale$
WRITE #2, scale$
CLOSE #2
CLOSE #3
SYSTEM
Run Code Online (Sandbox Code Playgroud)
目前我从PHP(在WAMP5上)以编译(exe)形式调用它,但我想摆脱QBASIC并直接从PHP调用它.
我写了这个PHP函数,但它只是挂在fgets()行:
function read_port($port='COM1:', $length=17, $setmode=TRUE, $simulate='') {
if ($simulate){
$buffer = '"'.strval(rand(1000, 2000));
return $buffer;
}
if ($setmode){
shell_exec('mode com1: baud=2400 parity=n data=8 stop=1 to=on xon=off odsr=on octs=on dtr=on rts=on idsr=on');
}
$fp = fopen($port, "rb+");
if (!$fp) {
file_put_contents('debug1.log','COM1: could not open'."\n",FILE_APPEND);
} else …Run Code Online (Sandbox Code Playgroud)