Php Serial Port Communication Linux Wine

Posted on -

I wonder if there is a way to accomplish reading my serial port via PHP - that works :-)

  1. Serial Port Communication Software
  • The second one was a Java Webstart application which used the Java SerialPort library (from Serialio.com), and could be started/run either from a network within our facility. After some searching, I realised that for Wine to connect Windows COM1 to the Linux serial port (/dev/ttyS0), wine had to be correctly configured.
  • Dec 10, 2015 Set up the serial port in Wine. Still some things that rely on serial port communication. Other Linux application that need serial port access.

Jul 22, 2008. Why I do not know, but it seems to be typical of Linux documentation. Here is what you need to do and why: 1. You will make a symbolic link that points to the hardware DEVICES folder in Fedora called /DEV 2. You will edit win.ini to include a serial ports section [I think it will work without this step, but it.

In practising my Arduino skills, I developed a simple LED ON/OFF sketch. It works by entering on or off in the serial monitor.

Next step, I put together a webpage to act as an GUI interface to click a link and perform the on and off function above. This webbased GUI works via PHP.I am using the PHP SERIAL class to interact with the serial port my Arduino is using.

The issue is I need to find a way of getting feedback from the serial port. Using the Arduino IDE serial monitor, I can see my printed messages in response to each of my serial input and I need to retrieve the same feedback in my PHP code.

The PHP Serial class offers a readPort() function but I does not return my data.

UPDATE[2]:

ARDUINO:

PHP/HTML:

sisko
siskosisko

3 Answers

I assume you work on linux.

First setup your serial port:

Then you can use good old fashion fread/fwrite

There is only one thing you have to remember. Arduino will restart on every connection. If you don't know that It will confuse you. For instance if you connect (fopen) and instantly send data Arduino will miss it because it's booting (which takes a sec or two). Experiment with sleep to give it some time. If you want to disable restarting use 10uF capacitor from GRD to RST.

Good luck

ps. you can troubleshoot with 'screen'

Post about setting PHP with Arduino http://systemsarchitect.net/connecting-php-with-arduino-via-serial-port-on-linux/ and one more here http://systemsarchitect.net/arduino-and-php-serial-communication-with-a-protocol/.

Lukasz KujawaLukasz Kujawa

/dev/ttyUSB0 running with user root, if your using apache try chown /dev/ttyUSB0 to apache or user is logged in.

and then try again, or try logout from ubuntu and login as root user.

user1068963

You are probably trying to read when is no data on the serial port. You need to implement JavaScript code to call PHP code that can read at regular intervals.

When you have got data, you should process it.

readPort() has worked fine for me. If the baud rate, parity, etc. is adjusted properly, then you should not have any problem reading the serial port.

Serial Port Communication Software

Here is a sample of using the library for Arduino. It worked for me some time ago:

opc0deopc0de

protected by CommunityNov 15 '13 at 8:19

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged phpserial-portarduino or ask your own question.

I am looking for a way to communicate with RS232 serial COM port on windows. I have found 2 solutions on the net, one which is not totally free (introduces deliberate delays on the function) and another with limited capability on Windows. The latter can only write to a COM port on Windows, not read.

I can't look at the code of the first solution since it is compiled into a .dll (makes sense, otherwise people can just edit the delay and not purchase it...) and the second one seems only to use fopen() to open the port and later fwrite() to it for writing, just like one would do to a stream. But apparently freading it returns nothing.

I know it's possible as the first solution did it, although it does require Apache to use php-cgi module instead of php5module.

Any ideas?

syazsyaz

7 Answers

Every solution above is either inefficient or too much work.

You can just use the PHP-DIO library (dio_fcntl, dio_open, dio_read, dio_write, dio_seek, ...). It's also in the PHP manual's entry for DIO:

This PECL package isn't available by default. To get it for Windows if you have PHP 5.2.x greater than 5.2.6, you can download it as part of a ZIP:

Both of these links were found in http://www.deveblog.com/index.php/download-pecl-extensions-for-windows/

Here is the build from Linux, just get it and do the phpize/configure/make/make install thing.

I don't know whether it should be used in an Apache session, but go for it.

Dustin OpreaDustin Oprea

The easiest way to tackle this would be to write a program in another language (such as C++) and then execute it from your php script with system(). Doing Comm I/O in C++ is trivial.

This assumes you have enough access to the server to configure it to allow the executable to be run by php, etc.

SoapBoxSoapBox

Another possible way would be to use the Win32 API through something like w32api_register_function() or ffi and then use serial communications calls to get it to work under Windows.

lpfavreaulpfavreau

I had the same problem and already considered writing my own php extension when I came across this solution which is popular with Arduino developers - 'serproxy' (found it at many places, ie. http://www.lspace.nildram.co.uk/freeware.html ) sets up a tcp stack to/from the serial ports and allowed me to use the php socket functions to communicate with it.

Communication
MichaelMichael

You need to set up the com port using a DOS-like command.

For example, the following line executes the command through php:

To display the results you can use:

Create the resource id:

Write to port:

Read from port:

Maybe someone can help me with the fgets problem. It stacks there for exactly one minute if TO=on, or stacks there forever if TO=off. It seems to be a 'MODE COM' option so maybe a DOS expert can help.

Perhaps instead of fgets, one should use fgetc, since fgets capture through to the newline, while fgetc captures a single character. If a new line isn't encountered, it may block until there is one or until the buffer is flushed. The one minute delay may be windows flushing its buffer on an interval.

Giorgos Pap

Another option is to use an object via ActiveX on windows. There are several, mostly commercial serial objects for COM on windows. You can also expose a .Net based object and register it for COM use as well. Of course, this does presume you have control on the server to register a COM control, as you would need a serial interface.

Another issue is resource contention if this is for use via the Web. If this is for a serial printer, for instance, then a print queue manager would be your best option over direct communication.

Tracker1Tracker1

If you want to deal with sms using com port then here is the most famous php serial communication class by Rémy Sanchez with google sample code. Here is a thread which includes that topic.

Community
adiadi

Not the answer you're looking for? Browse other questions tagged phpserial-portcommunication or ask your own question.