Serial Port Access via PHP

# 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.
proc Reader { pipe } {
global done
if {[eof $pipe]} {
catch {close $pipe}
set done 1
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

Who is Participating?
thinkingman2Connect With a Mentor Commented:
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:
Duncan RoeSoftware DeveloperCommented:
Are you saying it works with ttyS0 but not ttyUSB0? At work we have found that some USB serial converters are better than others
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.