Solved

Serial Port Access via PHP

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

717 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