Re: PHP extension writing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 24.09.2016 at 16:29, Torsten Rosenberger wrote:

> i try to write a php extension for raspberry to get i2c data.
> This is my first extension. And maybe not the corect mailing list.
> 
> The Problem, on the CLI I get the correct return value.
> If i run the same code in an webbrowser i got a wrong value.
> 
> PHP_FUNCTION(i2c_read_value)
> {
>     int arg_len;
>     unsigned char reg;
>     unsigned short res;
> 
>     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &reg,
> &arg_len) == FAILURE){

That looks wrong.  `reg` should be declared as `char *`.

>         RETURN_FALSE;
>     }
> 
>     res = i2c_smbus_read_byte_data(dev_fd, reg);

Where is dev_fd defined and initialized?

>     RETURN_LONG(res);
> }
> 
> 
> if i run these code in CLI 
> <?php
> 
> i2c_init(1,0x48,0);
> echo i2c_read_value(0x40);
> i2c_close();
> 
> ?>
> 
> php i2c.php 
> 
> i get 49 these comes from an ADC and the range is 0 - 255. In an C
> programm i get the same value.
> 
> wenn I run the script in an browser i get: 65535
> 
> someone can give me a hint ?

There might be a permission or working directory issue.

-- 
Christoph M. Becker

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




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux