看板 PHP 關於我們 聯絡資訊
※ 引述《chzn (天風)》之銘言: : 最近想要利用php寫一支程式,讓他可以與本機的com1 通訊 : 進而 處理一些事,可是我查書...大部分都是著重與mysql的應用 : 不知有沒有板友,有寫過相關的程式? : 可以請教一下嗎?謝謝!! 找了一下php官網 找到了一些資料 給你參考一下 網址:http://www.php.net/manual/en/function.fopen.php 他裡面提供了兩個方法 第二個方法是直接用fopen跟你的serial port通訊 第一個方法則是利用一個3rd party程式,這支程式可以把 序列資料和TCP/IP的資料互轉 我個人是沒有用過,手邊也沒有機器可以實測 不過我想... 如果你的程式是網頁的話,用第一個方法可能會比較好 如果是執行用的script,第二個可能會比較單純 純屬猜測,也請你有心得的話 跟我們分享一下嚕^^ <?php // HOW TO USE PHP TO WRITE TO YOUR SERIAL PORT: TWO METHODS $serproxy=true; if ($serproxy) { // Use this code in conjunction with SERPROXY.EXE // (http://www.lspace.nildram.co.uk/freeware.html) // which converts a Serial stream to a TCP/IP stream $fp = fsockopen ("localhost", 5331, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)"; } 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); } } elseif ($com1) { // Use this code to write directly to the COM1 serial port // First, you want to set the mode of the port. You need to set // it only once; it will remain the same until you reboot. // Note: the backticks on the following line will execute the // DOS 'mode' command from within PHP `mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=off`; $fp = fopen ("COM1:", "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); } } ?> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.162.72.88
chzn:好的,謝謝你的提供,有心得 我會回來分享的! 06/24 06:57