Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
Due to network maintenance being performed by our provider, LQ will be down starting at 05:01 AM UTC. The exact duration of the downtime isn't currently known. We apologize for the inconvenience.
|
 |
08-24-2010, 05:08 PM
|
#1
|
|
LQ Newbie
Registered: Aug 2010
Posts: 5
Rep:
|
PHP Serial port
Hello all,
I had a web server running from a Windows 7 computer and recently moved everything to an Ubuntu server. All is set up and running smoothly. I do have one page that actually interfaces with the serial port. The only thing I do with it is to set the DTR pin to "true" which applies +12v to the pin. This activates a relay. It is very basic and simple. After moving everything to Linux, this page will no longer work. I knew this would happen. I know the page had code in it to call out "Com1" which would change to "ttyS0". It also had "set_serDTR(True);" in the code. I can't figure out how to get PHP to control the DTR pin on a Linux serial port. Can anyone point me in the right direction?
Thanks,
Wayne
|
|
|
|
08-24-2010, 06:18 PM
|
#2
|
|
Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 11,805
|
Quote:
Originally Posted by wkellen
Hello all,
I had a web server running from a Windows 7 computer and recently moved everything to an Ubuntu server. All is set up and running smoothly. I do have one page that actually interfaces with the serial port. The only thing I do with it is to set the DTR pin to "true" which applies +12v to the pin. This activates a relay. It is very basic and simple. After moving everything to Linux, this page will no longer work. I knew this would happen. I know the page had code in it to call out "Com1" which would change to "ttyS0". It also had "set_serDTR(True);" in the code. I can't figure out how to get PHP to control the DTR pin on a Linux serial port. Can anyone point me in the right direction?
|
Not without seeing the code, no. However, it's not just ttyS0...it's /dev/ttyS0. Have you tried that?
|
|
|
|
08-24-2010, 06:42 PM
|
#4
|
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,264
|
You will probably have to adjust the permission level on /dev/ttyS0, as your web server probably does not run as root. To actually control the pins, you might find setSerialSignal useful (from PHP, use 'system()' or whatever PHP provides to launch other programs).
--- rod.
|
|
|
|
08-25-2010, 09:55 AM
|
#5
|
|
LQ Newbie
Registered: Aug 2010
Posts: 5
Original Poster
Rep:
|
On Windows 7 I had to add the php_ser++.dll file to my PHP folder. The code I put in my web page was:
<?php
$module = 'win_serial';
if (extension_loaded($module))
{
$str = "Module loaded";
}
else
{
$str = "Module $module is not compiled into PHP";
die("Module $module is not compiled into PHP");
}
ser_open( "COM1", 115200, 8, "None", "1", "None" );
ser_setDTR( True );
?>
I haven't actually tried the page, because I knew I need to make changes, I just didn't know exactly what I needed to do. I will look into your suggestions.
Thanks for all the help.
|
|
|
|
08-25-2010, 03:01 PM
|
#6
|
|
LQ Newbie
Registered: Aug 2010
Posts: 5
Original Poster
Rep:
|
Ok, I think I have a game plan for when I get to work on it again.
First: I need to allow everyone permissions on /dev/ttyS0
Second: I need to compile setSerialSignal.c
Third: I need to add the php code to my web page.
<?php
exec("setSerialSignal /dev/ttyS0 1 0");
?>
I am guessing that 0 0 sets the DTR pin one way and 1 0 sets it the other. (+ and -)
This is too easy. I have to be missing something. Does this look like it will work?
Thanks for pointing me to the setSerialSignal theNbomr.
|
|
|
|
08-25-2010, 03:13 PM
|
#7
|
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,264
|
Just by scanning the embedded strings for usage messages, I think the arguments to setSerialSignal are the states of DTR and RTS, respectively. 1 == ON, 0 = OFF.
As far as I can tell, the rest of your plan looks solid. BTW, I tried building setSerialSignal, and to get a clean build, I had to add
Code:
#include <stdio.h>
#include <stdlib.h>
--- rod.
|
|
|
|
08-25-2010, 08:53 PM
|
#8
|
|
LQ Newbie
Registered: Aug 2010
Posts: 5
Original Poster
Rep:
|
Success!
I followed the plan and all is well. Well, almost.
I shut my server down and moved it to it's permanent location. When I restarted it, it no longer worked. After chasing wires for a while, I remembered the permissions on the serial port. I logged into it and did a "sudo chmod 777 /dev/ttyS0" and it was up and running again. Now, how do I make the serial port permissions permanent?
Thanks to all for your help. Especially you, Rod.
|
|
|
|
08-25-2010, 09:42 PM
|
#9
|
|
Member
Registered: Oct 2009
Location: South America - Paraguay
Distribution: Debian 5 - Slackware 13.1 - Arch - Some others linuxes/*BSDs through KVM and Xen
Posts: 329
Rep:
|
Quote:
Originally Posted by wkellen
Now, how do I make the serial port permissions permanent?
|
edit udev rules, maybe?
|
|
|
|
08-25-2010, 10:10 PM
|
#10
|
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,264
|
Setting the appropriate udev rules would be the definitive solution. A cheesy alternative would be adding a 'chmod ' line to /etc/rc.local
--- rod.
|
|
|
|
09-01-2010, 09:22 AM
|
#11
|
|
LQ Newbie
Registered: Aug 2010
Posts: 5
Original Poster
Rep:
|
Thank you all. I will look into the "udev rules" to solve my permissions problem. Other than that everything works as it is supposed to work.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 05:15 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|