Control Serial via PHPWritten by admin
You can run mode from Ms DOS command prompt. For example:
C:\> mode com4:/status
The above DOS command display the status of the COM port.
Syntax of mode (display a list of mode commands & options)
Open COM4 in write mode (for Microsoft Windows only)
|$fp =fopen("com4", "w");|
or your can use $fp =fopen("com4", "r+"); for read & write
Open USB serial port for read and write (for Linux)
Open first serial port in read & write (for Linux)
|$fp = fopen('/dev/ttyS0','r+');|
To terminate string with Carriage Return
|fwrite($fp, "string to send\r");|
To terminate string with New Line & Carriage Return
|fwrite($fp, "string to send\n\r");|
Close the serial port
There are many people using php_serial.class. Unfortunately it is not working in my computer. Please let me know if some one can make the following code work.
Latest from admin
Tuesday, 07 February 2017 20:40
posted by Johnny Churne
Thanks for a great article. I want to ask it is possible to send byte as hex from php to serial port?
Tuesday, 07 June 2016 15:03
posted by Mehedi Hasan Polin
Hi i am from bangladesh. i try to develop bridge scale software with Apache/php
i want to read data from com1 port to pc. please help
Friday, 22 January 2016 03:38
posted by Elza
Hello, I want to read data from Arduino, windows 7, 32 bit, Port COM4. I have the following code:
And I have the problem: fopen(COM4): failed to open stream: Permission denied in C:\xampp\htdocs\project\index.php on line 3
Does anyone knows what's the solution?
Thanks in advance..
Wednesday, 15 May 2013 19:47
posted by smching
You can check your com port from device manager too.
Sometime you have to send string terminate with new line or carriage return depend on your Arduino sketch.
fwrite($fp, "string to send\n\r");
Saturday, 11 May 2013 23:46
posted by chethan
i tried the program along with arduino .
the problem that i am facing is that , after the php code is made to run in wamp ,a new file by the name com20( i have connected the arduino to com20)is being created in the wamp server directory and is nothing is being transmitted to board .
can anyone please help me .
Saturday, 11 May 2013 10:54
posted by Subhendu
I can write on the serial port using fwrite($fp,"0");
Can you please provide me with a simple example on how to read from serial port.
I am using Windows 7
I want to display sensor data on my webpage.
Friday, 10 May 2013 22:09
posted by Subhendu Sinha Chaudhuri
I had my arduino attached in COM19 in my Windows 7 64bit. Using ur example I was trying to on the LED on pin 13. But nothing was happening. But the serial monitor of the arduino was showing the result on sending strings.
In fact the c:\>mode com19:/status was telling COM19 is unavailable.
Can u please help me
I have also failed with php_serial.class in Windows after trying for 4 days.
Saturday, 20 April 2013 23:25
posted by okan
i connect my cell phone(nokia 6300). i checked it is in com4. but in php i cannot connect com4 can you help me.