I need to access COM port (console) via script to access our DSL modem.
It should access in such a way that I can read all the messages printed on the console and i should also send commands to the console via script .
Please let me know if it is possible in TCL or php .
Platform : Windows XP.
Also is there any way I can access the com port through script and console software such as teraterm simultaneously ?
Regards,
Mithun
It is possible to use TCL to access a serial (COM) port using the standard TCL input and output commands. The main ones that you need to look at are the open and fconfigure commands. A google search for 'tcl open com1' will bring back lots of examples.
One thing worth noting is that the open and fconfigure commands changed in recent versions of TCL, TCL 8.5 I think, so depending on the version of TCL and age of the example some rework might be needed.
You just need to open the com1: device and fconfigure it to use the communications settings that the other side expects. For example:
set fd [open "com1:" r+]
fconfigure $fd -mode 9600,n,8,1
Be aware that it can be messy to use event-driven IO with serial ports on all platforms.
Sounds like a job for Expect.
Related
I'm looking for a way to read/write a PC's serial com port using PHP/IIS on Windows 10. I've experimented for a few days now, but every attempt failed.
I tried to use php_dio.php, only to find out this dll misses some essential implementation on Windows. Through StackOverflow I also read that it would impossible for PHP on Windows to do this.
I can use Powershell on Windows to perform the tasks I want using scripts, but I'm not able to gets it output. Also, I fail to start this from PHP using exec or shell_exec.
So, at the moment, I'm stuck. My goal is to create a PHP-file which is able to receive requests from the web. That request would than be translated into a command which I would send to a device which is connected on my com-port. The response on the com-port would then be sent back to the server which did the request. It's just simple serial I/O, like 9600 bd, No parity etc. The setup works, but like I said, every attempt to use PHP to access the com port fails.
Is there a way?
Suggestions are appreciated.
Thanks.
Tried php_dio, exec, shell_exec
I am using the following js plugin which allows me to use WebSockets on android and iOS with apps written in html5 (via phonegap in my case).
https://github.com/FreakDev/PhoneGap-Android-HTML5-WebSocket
What else do I need in order to use a websocket?
I have a basic server with bluehost that has PHP and MySQL installed.. What am I going to need to do?
First you can use a library like this one:
http://code.google.com/p/phpwebsocket/
Second, your host must let you create sockets. This mean PHP must have php_sockets.dll (Win) or sockets.so (Linux) extension enabled and a forwarded port from your server.
Also you need to run your php from commend line or somehow keep it alive for ever.
It is just like creating a normal socket in PHP.
*Edit:
WebSockets are just some sort of normal sockets. In websocket you can connect to a endpoint which is listening for connections and then communicate with it. Just like normal sockets but with simple differences in protocol and more limitations. For doing so you need a script or application to run for ever and handle all connections from webpages. But a php file will end just after request ended. For keeping a php file running for ever you need to run it from commend line which mean you need to have shell access, or you can use this code to run your php script for ever: (But you must think about a mechanism to call it only once)
ignore_user_abort(true);
ini_set('max_execution_time', 0);
set_time_limit(0);
You can test. If your application fail with error messages about not knowing a function like socket_connect or socket_bind then you don't have socket extension for php.
Here is phpwebsocket files for download:
http://phpwebsocket.googlecode.com/svn/trunk/%20phpwebsocket/
There is an example there too.
As "Tom van der Woerdt" said PHP is not designed for doing socket programming. Go for a non-scripting language and use a dedicated server or at least a vps for opening and managing sockets.
Does PHP has access to the parallel ? I'm trying to write data to the LPT1 port using PHP, but not having luck finding anything.
Writing to the parallel port is as simple as:
file_put_contents("/dev/lp0", "See that was easy.");
Your real problem however sounds to be:
Does PHP has access to the parallel ?
Since PHP usually runs under Apache, the permissions for this device file are insufficient. On Debian systems you would add the www-data user to the lp group to make it work.
By enabling Wake-on-LAN on my PC, I can remotely power it on.
Suppose I want to send the "magic packet" from a PHP script. How would I do this? Would I need to use the cURL functions?
You can peek at: http://sourceforge.net/projects/wolviaphp/files/ (uses fsockopen() with 'udp://')
I have used WMI in the past, for the remote management of machines running windows.
So WMI from MS or http://www.openwbem.org/ (the open standard) might be what you are looking for.
Good luck.
Does anyone know of a JS-based terminal client? Either something that initiates an SSH connection with a remote host or even something that simply communicates with a remote PHP script to execute commands and retrieve output. Does such a thing exist?
Check Anyterm, it uses a XmlHttpRequest channel to communicate with a daemon that uses a pseudo-terminal to communicate with a shell or other application.
http://www.masswerk.at/termlib/ looks interesting as a base.
http://sourceforge.net/projects/jsterminal
but you'd have to write your own commands to connect with the host
Shell in a box could be used also with a small Asus EEE-PC:
http://code.google.com/p/shellinabox/
It works great also for virtual machines in a cloud.
So far JSDom Shell is the only thing I have found, which seems relatively barebones but practical. If there are any other more substantial options, feel free to share!