Author Topic: linux-gpib php5 support coming back to life ;-)  (Read 1560 times)

0 Members and 1 Guest are viewing this topic.

Offline davorin

  • Supporter
  • ****
  • Posts: 828
  • Country: ch
linux-gpib php5 support coming back to life ;-)
« on: June 21, 2016, 09:58:28 pm »
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;

« Last Edit: June 21, 2016, 10:05:59 pm by davorin »
 

Offline awallin

  • Frequent Contributor
  • **
  • Posts: 680
Re: linux-gpib php5 support coming back to life ;-)
« Reply #1 on: June 22, 2016, 05:15:01 am »
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..

+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).
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1499
  • Country: dk
 

Offline davorin

  • Supporter
  • ****
  • Posts: 828
  • Country: ch
Re: linux-gpib php5 support coming back to life ;-)
« Reply #3 on: June 22, 2016, 02:33:23 pm »
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: [Select]
ibfind
ibdev
ibpad
ibwrt
ibrd
ibrsp
« Last Edit: June 22, 2016, 02:41:42 pm by davorin »
 

Offline davorin

  • Supporter
  • ****
  • Posts: 828
  • Country: ch
Re: linux-gpib php5 support coming back to life ;-)
« Reply #4 on: June 22, 2016, 04:48:20 pm »
A simple webpage with AJAX drawing voltage level of my HP 3456A in realtime:

The AJAX just calls every second this snippet:

Code: [Select]
<?php
$string "";

$u ibfind("voltmeter");
ibrd($u,$string,1000);
echo number_format((float)$string5) . "\n";
?>


 

Offline davorin

  • Supporter
  • ****
  • Posts: 828
  • Country: ch
Re: linux-gpib php5 support coming back to life ;-)
« Reply #5 on: June 22, 2016, 06:07:52 pm »
Attached the modified glib.c file, which goes into "language/php" folder...

 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1499
  • Country: dk
Re: linux-gpib php5 support coming back to life ;-)
« Reply #6 on: June 22, 2016, 07:57:20 pm »
Attached the modified glib.c file, which goes into "language/php" folder...

Could you make a diff file please ?

/Bingo
 

Offline davorin

  • Supporter
  • ****
  • Posts: 828
  • Country: ch
Re: linux-gpib php5 support coming back to life ;-)
« Reply #7 on: June 23, 2016, 08:12:56 am »
As you wish...made with "diff -u gpib.c.orig gpib.c > gpib-php.patch"

Code: [Select]
--- gpib.c.orig 2016-06-23 10:06:53.789146336 +0200
+++ gpib.c 2016-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.net
 
 MODIFICATIONS
+ * 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 live
  and 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 files
     
 BIBLIOGRAPHY:
 
@@ -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_GPIB
 ZEND_FUNCTION(gpib_error_string);
-#endif
 
 ZEND_FUNCTION(ibsta);
 ZEND_FUNCTION(ibcnt);
@@ -306,11 +290,9 @@
  ZEND_FE(ibwait, NULL)
  ZEND_FE(ibwrtf, NULL)
 
-#ifdef USE_LINUX_GPIB
  ZEND_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_GPIB
    php_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_GPIB
 ZEND_FUNCTION(gpib_error_string)
 {
   long n;
@@ -497,7 +473,6 @@
  }
  RETURN_STRING((char*)gpib_error_string(n), 1);
 }
-#endif
 
 ZEND_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);
 

Offline davorin

  • Supporter
  • ****
  • Posts: 828
  • Country: ch
Re: linux-gpib php5 support coming back to life ;-)
« Reply #8 on: June 27, 2016, 10:41:48 am »
Seems the PHP module is not binary save when doing "ibrd()"...

Need to change in gpib.c line 524 from:

Code: [Select]
        ZVAL_STRING(z,p,1);

to:

Code: [Select]
        ZVAL_STRINGL(z,p, ibcnt,1);

Now this piece of code works now reading a bitmap image from my LeCroy 9354AL:

Code: [Select]
<?php
$string = array();
$tiff "";

$u ibfind("9354");
ibwrt($u"HCSU DEV,BMP");
ibwrt($u"SCDP");

$bytes 0;

while($r ibrd($u$string1000))
{
$count ibcnt();
echo "Read bytes: " $count "\n";
file_put_contents("/var/www/html/output.bmp"$stringFILE_APPEND);
$bytes += $count;
if($count 1000)
{
echo "Total bytes: " $bytes "\n";
exit;
}
}
echo "Total bytes: " $bytes "\n";
?>


Producing:

« Last Edit: June 27, 2016, 10:44:32 am by davorin »
 

Offline davorin

  • Supporter
  • ****
  • Posts: 828
  • Country: ch
Re: linux-gpib php5 support coming back to life ;-)
« Reply #9 on: June 27, 2016, 11:12:32 am »
And this snippet even renders it on your web browser: (o;

Code: [Select]
<?php
$string "";
$image "";

$u ibfind("9354");
ibwrt($u"HCSU DEV,BMP");
ibwrt($u"SCDP");

while($r ibrd($u$string1000))
{
$count ibcnt();
$image .= $string;
if($count 1000)
break;;
}

$imagick = new Imagick();
$imagick->readImageBlob($image);
header("Content-Type: image/png");
echo $imagick;
?>


 

Offline davorin

  • Supporter
  • ****
  • Posts: 828
  • Country: ch
Re: linux-gpib php5 support coming back to life ;-)
« Reply #10 on: June 27, 2016, 12:32:27 pm »
This is soooo much better (o;

Code: [Select]
<?php
$string "";
$image "";

$u ibfind("9354");
ibwrt($u"HCSU DEV,BMP");
ibwrt($u"SCDP");

while($r ibrd($u$string1000))
{
$count ibcnt();
$image .= $string;
if($count 1000)
break;
}

$imagick = new Imagick();
$imagick->readImageBlob($image);
        
$imagick->setImageDepth(24);
$imagick->setImageFormat("png");
$clut = new Imagick();
$clut->newPseudoImage(21"gradient:orange-black");
$imagick->clutImage($clut);
header("Content-Type: image/png");
echo $imagick;
?>


« Last Edit: June 27, 2016, 02:11:27 pm by davorin »
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1499
  • Country: dk
Re: linux-gpib php5 support coming back to life ;-)
« Reply #11 on: June 28, 2016, 02:25:48 pm »
Nice job Davorin  :-+

/Bingo
 

Offline davorin

  • Supporter
  • ****
  • Posts: 828
  • Country: ch
Re: linux-gpib php5 support coming back to life ;-)
« Reply #12 on: March 11, 2018, 10:31:21 am »
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 crashes
ibwrt wants always to tal kto device descriptor 0
and ibrd returns nothing though it completes successfully (sta = 0x2100), but the returned string can be printed out in the ibrd function....

Code: [Select]
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 ENOMEM
RETURN_LONG(ibsta);
}
    memset(p,0,len+1);

r=ibrd(n,p,len);
    p[ibcnt]='\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);
}

 

Offline davorin

  • Supporter
  • ****
  • Posts: 828
  • Country: ch
Re: linux-gpib php5 support coming back to life ;-)
« Reply #13 on: March 15, 2018, 04:02:44 pm »
Works again under php-7 and Debian 9 (o;

Now some testing and patch preparing....
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf