Solved

Serial Port Access via PHP

Posted on 2009-06-30
2
947 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now