Comments (7)
Hello
You need to compile it first. It is a php extension.
Compile it described in the README.md file.
You probably need to add the library in your php.ini file:
Add the following text to the php.ini file:
extension=php_i2c
You can find the php.ini files by typing php --ini into the command line.
Hope that helps.
from php-i2c-extension.
from php-i2c-extension.
I found a problem, but no solution yet. When I run ./configure --enable-i2c-php, the script displays a warning that "--enable-i2c-php' is an unknown option. In the script, it appears to be looking for "enable-php-i2c". There is no errors or warning when I use --enable-php-i2c, but the require statement sill fails, and the extension_loaded function reports false.
When I include the require statement:
define('BASE_DIR', dirname(FILE));
require_once(BASE_DIR.'/config.php');
require BASE_DIR.'/tasoft/php-i2c-extension';
use TASoft\Bus\I2C;
The following errors are displayed when attempting to render the page:
Note that if I don't use the BASE_DIR definition, the first error message is "file not found"
from php-i2c-extension.
I've made some progress. After successfully compiling and configuring with the correct option, it appears that the extension is indeed loaded, even though the require /tasoft/php-i2c-extension line fails. For example, with (and only with) "use TASoft\Bus\I2C" in my php file, the following code executes without error:
function iris(int $p) {
$i2c = new I2C(0x60, 1);
$i2c->writeRegister(192);
$i2c->write16(1,$p);
}
It doesn't do what I need it to do, but that's another issue. The point is that these functions are not available unless the extension is loaded, so it appears that it is.
Also, the test to see if the extension is loaded is positive, but only when run in the debugger. I was able to run the debugger as a non-privileged user, and the extension still loads. However, when running with the standard Apache server, it is not loaded.
from php-i2c-extension.
Hello jay3702
Again, the tasoft/php-i2c-extension is an EXTENSION for PHP, which can not be included in a script using require or include.
You need to figure out, which php.ini files your php binary loads and add the following line at end of this php.ini file:
extension=php_i2c
Only after this moment, the extension gets loaded automatically by bootstrapping the php binary.
Type: php --ini in a command line tool to find the loaded php.ini files.
Example:
pi@raspberrypi:~/SPS $ php --ini
Configuration File (php.ini) Path: /etc/php/7.3/cli
Loaded Configuration File: /etc/php/7.3/cli/php.ini
Scan for additional .ini files in: /etc/php/7.3/cli/conf.d
Additional .ini files parsed: /etc/php/7.3/cli/conf.d/10-mysqlnd.ini,
/etc/php/7.3/cli/conf.d/10-opcache.ini,
/etc/php/7.3/cli/conf.d/10-pdo.ini,
/etc/php/7.3/cli/conf.d/15-xml.ini,
/etc/php/7.3/cli/conf.d/20-calendar.ini,
/etc/php/7.3/cli/conf.d/20-ctype.ini,
/etc/php/7.3/cli/conf.d/20-dom.ini,
/etc/php/7.3/cli/conf.d/20-exif.ini,
/etc/php/7.3/cli/conf.d/20-fileinfo.ini,
/etc/php/7.3/cli/conf.d/20-ftp.ini,
/etc/php/7.3/cli/conf.d/20-gettext.ini,
/etc/php/7.3/cli/conf.d/20-iconv.ini,
/etc/php/7.3/cli/conf.d/20-json.ini,
/etc/php/7.3/cli/conf.d/20-mysqli.ini,
/etc/php/7.3/cli/conf.d/20-pdo_mysql.ini,
/etc/php/7.3/cli/conf.d/20-pdo_sqlite.ini,
/etc/php/7.3/cli/conf.d/20-phar.ini,
/etc/php/7.3/cli/conf.d/20-posix.ini,
/etc/php/7.3/cli/conf.d/20-readline.ini,
/etc/php/7.3/cli/conf.d/20-shmop.ini,
/etc/php/7.3/cli/conf.d/20-simplexml.ini,
/etc/php/7.3/cli/conf.d/20-sockets.ini,
/etc/php/7.3/cli/conf.d/20-sqlite3.ini,
/etc/php/7.3/cli/conf.d/20-sysvmsg.ini,
/etc/php/7.3/cli/conf.d/20-sysvsem.ini,
/etc/php/7.3/cli/conf.d/20-sysvshm.ini,
/etc/php/7.3/cli/conf.d/20-tokenizer.ini,
/etc/php/7.3/cli/conf.d/20-wddx.ini,
/etc/php/7.3/cli/conf.d/20-xmlreader.ini,
/etc/php/7.3/cli/conf.d/20-xmlwriter.ini,
/etc/php/7.3/cli/conf.d/20-xsl.ini
pi@raspberrypi:~/SPS $
from php-i2c-extension.
I got it to work, thanks!
Turns out that Apache was not loading a php.ini file at all. What was throwing me off was that when I run php from the command line to generate a phpinfo() report, it shows that it had /etc/php/7.3/cli/php.ini loaded. It apparently uses that file when running the web page with the VS Code internal web server. To figure out what was happening, I created a stripped down version of the page I was developing, containing only a call to phpinfo and tests for the i2c extension and the ini file path:
<body
<div ><?php phpinfo(); ?> </div>
<div><?php
$p = extension_loaded('php_i2c');
var_dump( $p );?></div>
<div><?php
$s = php_ini_loaded_file();
var_dump($s);?>
</div>
</body>
This showed that the expected ini path was /etc/php/7.3/apache2, and there was no ini file there! So, I moved the one I had modified from the cli folder to apache2, et voila!
I'm still not sure why running php from the command line shows different results, but lesson learned! This probably explains the trouble I was having with xdebug, too.
FYI - I'm using your extension to communicate with a MCP4725 DAC development board to control the iris of a CCTV video camera lens that I'm using with the Raspberry Pi high quality camera.
Thanks again!
from php-i2c-extension.
You welcome!
from php-i2c-extension.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-i2c-extension.