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 variations....

Any ideas, suggestions, .... Thanks!


Reply via email to