Solved

Serial Port Access via PHP

Posted on 2009-06-30
2
956 Views
Last Modified: 2013-11-10
# Goal
- Access Serial Port on a Linux (Ubuntu 9.4) machine with Php.
- The serial device is an usb serial converter chip "ft232r".
- The Receiver must always be online, because the timepoint of incoming data is unnown.
- The transmitted data has raw format.

# Not Working
- The "php_serial" class works pretty good with the build in serial port, but with the usb serial converter chip there are some errors. Other software doesn't have any problem with the chip. Moreover with directly php acess the "online goal" can't be archieved.

# Ideas - receive
- Serial_sniffer. Didn't get out how to use yet.
- Script below. Problem: Waits for lines, not for every single byte.

# Ideas - transmit
- $ echo "mem" > /dev/ttyS0. Does this works with raw files?
- $ sz fifo >/dev/ttyUSB0 </dev/ttyUSB0 &. Can't file an installation file for ubuntu.
#!/usr/bin/expect
 
proc Reader { pipe } {
global done
 
if {[eof $pipe]} {
catch {close $pipe}
set done 1
return
}
gets $pipe line
set tagxmitdate [clock seconds]
#puts $line $tagxmitdate
puts "$tagxmitdate $line"
}
 
set pipe [open "|cat /dev/ttyS0" r]
fileevent $pipe readable [list Reader $pipe]
vwait done

Open in new window

0
Comment
Question by:asking-fox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
thinkingman2 earned 500 total points
ID: 24751102
Honestly this is somewhat out of my expertise with PHP, as I only use C for that type of thing, but here's a PHP class for working with serial ports that may be better than what you're using. Also, the author seems to be pretty knowledgeable about that type of thing, perhaps Remy Sanchez may have some directions for you:

http://www.phpclasses.org/browse/package/3679.html
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 24758776
Are you saying it works with ttyS0 but not ttyUSB0? At work we have found that some USB serial converters are better than others
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question