Link to home
Start Free TrialLog in
Avatar of asking-fox
asking-fox

asked on

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.
#!/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

ASKER CERTIFIED SOLUTION
Avatar of thinkingman2
thinkingman2
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Duncan Roe
Are you saying it works with ttyS0 but not ttyUSB0? At work we have found that some USB serial converters are better than others