linux-gpib php5 support coming back to life ;-) - Page 1
Forum section: electronics / testgear

author: davorin
author_rank: Unknown
timestamp: June 21, 2016, 09:58:28 pm
content: Evelin' (o;bingo600 asked me, you know..the guy who knows everything about GPIB, asked me to start a new thread regarding the php5 support in the linux-glib software...As you might know...the PHP code is rather old and only supports PHP version 4 only....a quick look into it and a few line removal showed that at least writing/reading to/from the GPIB bus can be made to work easily...This thread is about the progress about my work to get the PHP5 support back into shape...extending the possibilities of this great package...not only it will open to great web application controlling GPIB equipment...but also it could replace the old RPC code with a nice HTTP API which can be talked by almost any device nowadays...could be in the end even have the same protocol as the Prologix ethernet adapter....I'm currently using a Beiming S82357 and a F82357 (both are the exactly the same hardware..only the firmware differs ;o), and a recently acquired NI PCI card with an unknown PCI ID so far to the linux-glib stack...For further development, not only PHP5 based...but also reverse engineering do develop an own FPGA PCI(e) GPIB controller, I'm looking for sponsors of GPIB hardware...which is already supported....or currently not..cya l8r (o;

author: awallin
author_rank: Frequent Contributor
timestamp: June 22, 2016, 05:15:01 am
content: Quote from: davorin on June 21, 2016, 09:58:28 pm+1 on this, the NI USB-dongles are a bit expensive and in my experience the cheaper yellow Prologix boxes are tricky/unreliable to work with.Given how cheap e.g. arduino-platforms or RPi is, do you think it makes sense to roll your own FPGA for a GPIB-controller? If it's doable with arduino/RPi/beagle-whatever then I would choose that because of price and availability. I would prefer an ethernet device over USB and especially PCI(e).

author: bingo600
author_rank: Super Contributor
timestamp: June 22, 2016, 06:34:45 am
content: Quote from: davorin on June 21, 2016, 09:58:28 pmMaybe have a look @ The Raggedstone series fromwww.enterpoint.co.ukhttps://www.enterpoint.co.uk/products/spartan-3-development-boards/raggedstone-1/https://www.enterpoint.co.uk/products/spartan-6-development-boards/raggedstone-2/https://www.enterpoint.co.uk/products/cyclone-iv-development-boards/raggedstone3/They might donate one/Bingo

author: davorin
author_rank: Unknown
timestamp: June 22, 2016, 02:33:23 pm
content: Well..not sure about that....in the good old days I even got a full Quartus license from Altera directly...or had a direct contact at Lattice Finland (o;Ordered now another bloody cheap Thinclient PC which has both PCI and PCIe interface...so I can use my Lattice ECP3 Versa board which you get frmo time to time for US$ 99....Not sure if the promo has ended where they haven given it away for free...Guess a PCI prototyping board could be of great help...with short wires to a Altera FPGA board....Back to PHP5 (o;Currently tested and working fine:Code:ibfindibdevibpadibwrtibrdibrsp

author: davorin
author_rank: Unknown
timestamp: June 22, 2016, 04:48:20 pm
content: A simple webpage with AJAX drawing voltage level of my HP 3456A in realtime:The AJAX just calls every second this snippet:Code:<?php$string="";$u=ibfind("voltmeter");ibrd($u,$string,1000);echonumber_format((float)$string,5) ."\n";?>

author: davorin
author_rank: Unknown
timestamp: June 22, 2016, 06:07:52 pm
content: Attached the modified glib.c file, which goes into "language/php" folder...

author: bingo600
author_rank: Super Contributor
timestamp: June 22, 2016, 07:57:20 pm
content: Quote from: davorin on June 22, 2016, 06:07:52 pmCould you make a diff file please ?/Bingo

author: davorin
author_rank: Unknown
timestamp: June 23, 2016, 08:12:56 am
content: As you wish...made with "diff -u gpib.c.orig gpib.c > gpib-php.patch"Code:--- gpib.c.orig2016-06-23 10:06:53.789146336 +0200+++ gpib.c2016-06-22 15:27:33.329798187 +0200@@ -11,6 +11,9 @@the Minerva "Emerge" project, in February 2003(C) Michel Billaud, 2003+php5 modifications by+Richard Klingler, richard@klingler.net+**************************************************************************** ** This program is free software; you can redistribute it and/or modify *@@ -29,6 +32,7 @@the linux-gpib-3.1.92 files. http://linux-gpib.sourceforge.netMODIFICATIONS+ * 2016/06/22 : modifications to make it work with php5* 2003/02/25 : in ibrd, string terminated after ibcnt chars* 2003/03/14 : more comments@@ -37,11 +41,11 @@- integrate more constants (for ibconf)NOTES :- * installation under Debian/Woody requires the php4-dev package+ * installation under Debian/Woody requires the php5-dev package* for convenience, install the gpib.so where dynamic extensions liveand add the line- extension=gpib.so- to the /etc/php/{apache,cgi}/php.ini files+ extension=gpib_php.so+ to the /etc/php5/{apache2,cli}/conf.d/20-gpib.ini filesBIBLIOGRAPHY:@@ -49,13 +53,7 @@Till Gerken, Campus Press, pp. 327-...file://localhost/opt/doc.php.nexen.html/zend.structure.exporting-functions.html */-#ifdef USE_LINUX_GPIB#include "gpib/ib.h"-#endif--#ifdef USE_NI_GPIB-#include <ugpib.h>-#endif#include "php.h"#include "ext/standard/info.h"@@ -175,10 +173,6 @@== FAILURE) { \return; \} \-if (!PZVAL_IS_REF(z)) { \-zend_error(E_WARNING, "Not a reference"); \-RETURN_NULL(); \-} \r=functionName(n,&result); \ZVAL_LONG(z,result); \RETURN_LONG(r); \@@ -195,10 +189,6 @@== FAILURE) { \return; \} \-if (!PZVAL_IS_REF(z)) { \-zend_error(E_WARNING, "Not a reference"); \-RETURN_NULL(); \-} \r=functionName(n,&result); \ZVAL_LONG(z,result); \RETURN_LONG(r); \@@ -215,10 +205,6 @@== FAILURE) { \return; \} \-if (!PZVAL_IS_REF(z)) { \-zend_error(E_WARNING, "Not a reference"); \-RETURN_NULL(); \-} \r=functionName(n,nn,&result); \ZVAL_LONG(z,result); \RETURN_LONG(r); \@@ -256,9 +242,7 @@ZEND_FUNCTION(ibwait);ZEND_FUNCTION(ibwrtf);-#ifdef USE_LINUX_GPIBZEND_FUNCTION(gpib_error_string);-#endifZEND_FUNCTION(ibsta);ZEND_FUNCTION(ibcnt);@@ -306,11 +290,9 @@ZEND_FE(ibwait,NULL)ZEND_FE(ibwrtf,NULL)-#ifdef USE_LINUX_GPIBZEND_FE(gpib_error_string, NULL)-#endif- ZEND_FE(ibsta,NULL)+ZEND_FE(ibsta,NULL)ZEND_FE(ibcnt,NULL)ZEND_FE(iberr,NULL)@@ -349,16 +331,11 @@php_info_print_table_start();php_info_print_table_row(2,"GPIB Support","Enabled");-#ifdef USE_LINUX_GPIBphp_info_print_table_row(2,"Supported library","Linux GPIB ""(http://linux-gpib/sourceforge.net)");-#endif-#ifdef USE_NI_GPIB- php_info_print_table_row(2,"Supported library",-"National Instruments");-#endif+ php_info_print_table_row(2,"PHP5 modifications by","Richard Klingler, richard@klingler.net");php_info_print_table_end();}@@ -486,7 +463,6 @@*/-#ifdef USE_LINUX_GPIBZEND_FUNCTION(gpib_error_string){long n;@@ -497,7 +473,6 @@}RETURN_STRING((char*)gpib_error_string(n), 1);}-#endifZEND_FUNCTION(ibwrt){@@ -542,10 +517,6 @@== FAILURE) {return;}-if (!PZVAL_IS_REF(z)) {-zend_error(E_WARNING, "Not a reference");-RETURN_NULL();-}p = (char *) malloc(len + 1);memset(p,0,len+1);r=ibrd(n,p,len);

author: davorin
author_rank: Unknown
timestamp: June 27, 2016, 10:41:48 am
content: Seems the PHP module is not binary save when doing "ibrd()"...Need to change in gpib.c line 524 from:Code:ZVAL_STRING(z,p,1);to:Code:ZVAL_STRINGL(z,p, ibcnt,1);Now this piece of code works now reading a bitmap image from my LeCroy 9354AL:Code:<?php$string= array();$tiff="";$u=ibfind("9354");ibwrt($u,"HCSU DEV,BMP");ibwrt($u,"SCDP");$bytes=0;while($r=ibrd($u,$string,1000)){$count=ibcnt();echo"Read bytes: ".$count."\n";file_put_contents("/var/www/html/output.bmp",$string,FILE_APPEND);$bytes+=$count;if($count<1000){echo"Total bytes: ".$bytes."\n";exit;}}echo"Total bytes: ".$bytes."\n";?>Producing:

author: davorin
author_rank: Unknown
timestamp: June 27, 2016, 11:12:32 am
content: And this snippet even renders it on your web browser: (o;Code:<?php$string="";$image="";$u=ibfind("9354");ibwrt($u,"HCSU DEV,BMP");ibwrt($u,"SCDP");while($r=ibrd($u,$string,1000)){$count=ibcnt();$image.=$string;if($count<1000)break;;}$imagick= newImagick();$imagick->readImageBlob($image);header("Content-Type: image/png");echo$imagick;?>

author: davorin
author_rank: Unknown
timestamp: June 27, 2016, 12:32:27 pm
content: This is soooo much better (o;Code:<?php$string="";$image="";$u=ibfind("9354");ibwrt($u,"HCSU DEV,BMP");ibwrt($u,"SCDP");while($r=ibrd($u,$string,1000)){$count=ibcnt();$image.=$string;if($count<1000)break;}$imagick= newImagick();$imagick->readImageBlob($image);$imagick->setImageDepth(24);$imagick->setImageFormat("png");$clut= newImagick();$clut->newPseudoImage(2,1,"gradient:orange-black");$imagick->clutImage($clut);header("Content-Type: image/png");echo$imagick;?>

author: bingo600
author_rank: Super Contributor
timestamp: June 28, 2016, 02:25:48 pm
content: Nice job Davorin/Bingo

author: davorin
author_rank: Unknown
timestamp: March 11, 2018, 10:31:21 am
content: Next hurdle after a looong time (o;Moved to a new box running Debian 9 and of course it has now php 7.x (o;ibfind crashesibwrt wants always to tal kto device descriptor 0and ibrd returns nothing though it completes successfully (sta = 0x2100), but the returned string can be printed out in the ibrd function....Code:ZEND_FUNCTION(ibrd){/* at the moment only the traditional form is supported$r = ibrd($ud,&$string,$count)(read at most $count bytes into $string)but$r = ibrd($ud,&$string)(read unlimited number of bytes) will be. Soon. Really.*/long n;zval *z;long len;char *p;long r;if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"lzl", &n, &z, &len)== FAILURE) {return;}p = (unsigned char *) malloc(len + 1);if(p == NULL) {ibsta |= ERR;iberr = EABO; // should be ENOMEMRETURN_LONG(ibsta);}memset(p,0,len+1);r=ibrd(n,p,len);p='\0';ZVAL_STRING(z,p);printf("Read %d bytes from device %d\n", ibcnt, n);printf("Returned %s\n", p);free(p);RETURN_LONG(r);}

author: davorin
author_rank: Unknown
timestamp: March 15, 2018, 04:02:44 pm
content: Works again under php-7 and Debian 9 (o;Now some testing and patch preparing....