Solved

Serial Port Access via PHP

Posted on 2009-06-30
2
951 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

809 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