I2C, sending a binary byte with fwrite

[email protected] (Tobias Krieger)
Newsgroups php.general
Message-ID <[email protected]>
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 = 1111 1111 (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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.