Last active
December 14, 2015 20:19
-
-
Save kahagon/5143467 to your computer and use it in GitHub Desktop.
$port->open() でのエラー処理について。
https://twitter.com/waseda_fablab/status/311402456552722433
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* シリアルポートオブジェクトを作ります。 | |
| * この段階ではまだ open していません。 */ | |
| $port = new SerialPort(); | |
| /* open に失敗すると例外がスローされるので | |
| * try catch で例外を補足し、例外処理を適宜行います。 */ | |
| try { | |
| /* ここでは仮に存在しないポートを指定してします。*/ | |
| $port->open('COM3'); | |
| } catch (Exception $e) { | |
| /* このブロックに例外処理を記述します。 | |
| * ここでは単に Exception を var_dump() するにとどめています。 */ | |
| var_dump($e); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment