[PHP] I2C, sending a binary byte with fwrite

2009-06-15 Thread Tobias Krieger
Hi,

I'm working on a interface between the I2C Bus (Hardware) and PHP - to use
the PHP as webinterface to control an I2C Device.

The bus is mounted as: /dev/i2c8_aux - and works

opening the bus with

$fd=fopen (/dev/i2c8_aux, w (r+) (r+b) (wb))is successfull

setting the address of the slave device (0xB0 (=0x58) and the register
(between 0-15) works

fseek($fd, 0x5801) (accessing register 01)

Now - the things that doesn't work: writting into the register

I'd like to write a value between 0-255 (0x00 and 0xff) e.g into register 1
(the one from above) - (0 = turn left, 128=stop, 255=turn right) I can only
write one (1) byte into the register, and fwrite uses strings.

$data = 128
$rslt = ($fd, $data, 1)

would write 3bytes.

So, what I need is a way to convert any value between 0 and 255 into a
string with one byte, e.g

0xff =   (with strlen($data) == 1)

I tried it with:

chr(255) - not successfull
pack("H" and "h", 0xff) - not successfull
decbin(255) - without success

and many more.

Any advice, suggestion, experience? Thanks!

Tobias


[PHP] I2C and PHP

2009-06-15 Thread Tobias Krieger
Hi,

I'm working on a interface between the I2C Bus (Hardware) and PHP - to use
the PHP as webinterface to control an I2C Device.

The bus is mounted as: /dev/i2c8_aux - and works

opening the bus with

$fd=fopen (/dev/i2c8_aux, w (r+) (r+b) (wb))is successfull

setting the address of the slave device (0xB0 (=0x58) and the register
(between 0-15) works

fseek($fd, 0x5801) (accessing register 01)

Now - the things that doesn't work: writting into the register

I'd like to write a value between 0-255 (0x00 and 0xff) e.g into register 1
(the one from above) - (0 = turn left, 128=stop, 255=turn right) I can only
write one (1) byte into the register, and fwrite uses strings.

$data = 128
$rslt = ($fd, $data, 1)

would write 3bytes.

So, what I need is a way to convert any value between 0 and 255 into a
string with one byte, e.g

0xff =   (with strlen($data) == 1)

I tried it with:

chr(255) - not successfull
pack("H" and "h", 0xff) - not successfull
decbin(255) - without success

And many more variations

Any ideas, suggestions,  Thanks!

tobias


[PHP] Passing Values between C App and PHP

2009-06-21 Thread Tobias Krieger

Hi,

I've recently written an eMail regarding I2C and PHP - since I haven't  
found a nice solution yet, I'm considering writting the I2C part  
(opening device, writing, reading,...) in C (that's simple) and to  
recieve (and returning) the values through PHP and Javascript.


E.g. Website (PHP/Javascript) -> set a new motorspeed -> PHP passes  
the new speed to C Application -> C AP opens and writes the new speed  
onto the I2C Bus -> Motor executes -> returns ack ->


Is this somehow, and not complicated possible?

Thanks,

Tobias


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing Values between C App and PHP

2009-06-21 Thread Tobias Krieger


Am 21.06.2009 um 23:31 schrieb Nathan Nobbe:

On Sun, Jun 21, 2009 at 3:25 PM, Tobias Krieger > wrote:

Hi,

I've recently written an eMail regarding I2C and PHP - since I  
haven't found a nice solution yet, I'm considering writting the I2C  
part (opening device, writing, reading,...) in C (that's simple) and  
to recieve (and returning) the values through PHP and Javascript.


E.g. Website (PHP/Javascript) -> set a new motorspeed -> PHP passes  
the new speed to C Application -> C AP opens and writes the new  
speed onto the I2C Bus -> Motor executes -> returns ack ->


Is this somehow, and not complicated possible?

if the C program is written such that it can start and stop on every  
request rather than as a daemon, its as simple as shell_exec().


write your C app to take args over the cli and then pass them in  
through the call:




something of that nature.

-nathan

This would be a nice and fast solution, but unfortunatelly, it's like  
that the C programm needs to surveilance the hardware all the time  
(controlling values,...) hence, it would run more as a "daemon".


thx,

tobias