justinh Posted January 31, 2009 Share Posted January 31, 2009 I have some hardware (money counting system) connected to my pc (using a serial port). Right now I can send terminal commands to it and everything works fine. Is it possible to send terminal commands via PHP? Quote Link to comment https://forums.phpfreaks.com/topic/143274-possible/ Share on other sites More sharing options...
genericnumber1 Posted January 31, 2009 Share Posted January 31, 2009 many ways... backtick operators: `command` system() exec() shell_exec() etc. See: http://us3.php.net/manual/en/ref.exec.php Quote Link to comment https://forums.phpfreaks.com/topic/143274-possible/#findComment-751383 Share on other sites More sharing options...
justinh Posted January 31, 2009 Author Share Posted January 31, 2009 Okay lets say I have my hardware, I'm connected to it via terminal. If I press the clear command ("Capital C + enter") it clears the money counter. Now how would I begin sending date via PHP to a serial port? A quick hello world example would be lovely, but if you can't, do you have any good tutorial links? Quote Link to comment https://forums.phpfreaks.com/topic/143274-possible/#findComment-751390 Share on other sites More sharing options...
.josh Posted January 31, 2009 Share Posted January 31, 2009 You would need to setup an interface to send commands to be used with those various functions genericnumber provided. You can make a form with a text field or text area or dropdown or whatever, and use the posted info in one of those functions. Or you could make links that send command string via GET method. Or if you're looking for a more real-time solution like if you were to be working from the command prompt, you could look into doing it with ajax. Quote Link to comment https://forums.phpfreaks.com/topic/143274-possible/#findComment-751396 Share on other sites More sharing options...
justinh Posted January 31, 2009 Author Share Posted January 31, 2009 I understand the logic of it all, So basically, If I can type C into Tera Term (terminal freeware) and it clears the display on the hardware, I can easily use a button labeled clear, and some AJAX to do this? Quote Link to comment https://forums.phpfreaks.com/topic/143274-possible/#findComment-751408 Share on other sites More sharing options...
.josh Posted January 31, 2009 Share Posted January 31, 2009 well, you wouldn't technically need ajax. Ajax would just allow you to click the button and send a request to the script without refreshing the whole page. You can do it with a regular html form or link and just have the whole page refresh. Quote Link to comment https://forums.phpfreaks.com/topic/143274-possible/#findComment-751410 Share on other sites More sharing options...
justinh Posted January 31, 2009 Author Share Posted January 31, 2009 Okay well I read over the exec info on php.net this is what I came up with <?php for($i = 1; $i <= 2; ++$i){ if($i == 1){ $command="cd C:\Program Files (x86)\\teraterm\\"; $output=shell_exec($command." 2>&1"); //system call print "<pre>$output</pre>\n"; //show output print "<br />" . $command; } else { $command="TTERMPRO /I"; $output=shell_exec($command." 2>&1"); //system call print "<pre>$output</pre>\n"; //show output print "<br />" . $command; } } ?> I move to the terminal freeware program directory, but once im in the directory I try to execute a command, TTERMPRO /I this is the returns I get cd C:\Program Files (x86)\teraterm\ 'TTERMPRO' is not recognized as an internal or external command, operable program or batch file. TTERMPRO /I http://ttssh2.sourceforge.jp/manual/en/commandline/teraterm.html is a list of commands for tera term Quote Link to comment https://forums.phpfreaks.com/topic/143274-possible/#findComment-751447 Share on other sites More sharing options...
corbin Posted January 31, 2009 Share Posted January 31, 2009 cd C:\Program Files (x86)\teraterm\ should be cd "C:\Program Files (x86)\teraterm\" so: $command='cd "C:\\Program Files (x86)\\teraterm\\"'; I don't think PHP uses shell_exec in a traditional shell sense by the way. What I mean is, if you change the current working directory, I don't know if you will still be in that directory on the next shell_exec call. Guess you can try it though ;p. Quote Link to comment https://forums.phpfreaks.com/topic/143274-possible/#findComment-751457 Share on other sites More sharing options...
justinh Posted January 31, 2009 Author Share Posted January 31, 2009 Okay thank you, <?php chdir("C:\\Program Files (x86)\\teraterm\\"); $cmd = "TTERMPRO /I"; exec($cmd); ?> seems to work. Quote Link to comment https://forums.phpfreaks.com/topic/143274-possible/#findComment-751464 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.