Author Topic: UGSimple GPIB hacks  (Read 4430 times)

0 Members and 1 Guest are viewing this topic.

Offline flittleTopic starter

  • Contributor
  • Posts: 17
  • Country: us
UGSimple GPIB hacks
« on: April 29, 2018, 03:41:46 am »
UGSimple is the least expensive option.  Let's make it work! cellularmitosis suggested this thead.

HACK 1.
I got the UGSimple.  It was clunky.  I almost gave up and then I noticed that if I clicked 'Find' between clicking 'Read' I could get sequential reads.

So I looked at their vc++ sample and reworked it to log to stdout.

Basically you just put this in a loop with a delay:
Code: [Select]
       proc = Gwrite(address, (char *)commands.str().c_str());
istringstream r(Gread(address));//read from device
double dr = 0.00;
r >> dr;
cout << dr << endl;

Here is the source of my UGSimple hack:

https://www.dropbox.com/s/h38hsjt7ek0427s/uglogger.zip?dl=0
Apologies in advance for my vc++ code.

Here is the exe:
https://www.dropbox.com/sh/a61s7tsyf3ap3h5/AADj9XF92ool0dqbZh2XoLK1a?dl=0

Tell us your UGSimple Hack!
DS1054Z, HP3455A, HP3457A, Agilent 34401A, HP5334B-010-030, HP204D, EX430, Agilent 6612C, (2) Sorensen XTS15-4 /M1 /M9B, WaveTek 131, WaveTek 134,PAR 110, FG-8002,FY3200S, UNI-T61E, TEK2465
 

Offline flittleTopic starter

  • Contributor
  • Posts: 17
  • Country: us
Re: UGSimple GPIB hacks
« Reply #1 on: April 29, 2018, 03:45:27 am »
Here is the entire cpp file:
Code: [Select]
// uglogger.cpp
// By flittle
// Free as in Free
//

#include "stdafx.h"
#include "UGSimple_dll_VC++.h"

int main(int argc, char * argv[], char * envp[]);
bool Loaddll(void);

using namespace std;

HINSTANCE hInst;
int address = 1;
int readDelay = 10000;
int readCount = -1;
istringstream commands;

int main(int argc,      // Number of strings in array argv 
char *argv[],   // Array of command-line argument strings 
char *envp[])  // Array of environment variable strings 
{
// usage uglogger address "cmds" delay count
clog << "uglogger - v0.1" << endl << "by flittle" << endl;
if (argc < 2)
{
cerr << "\nUsage: uglogger address [delay] [count] [\"commands\"]\n" << "\n   Example:\n       uglogger 11\n";
return -1;
}

istringstream addr(argv[1]);

if (!(addr >> address)) {
cerr << "Invalid address " << argv[1] << endl;
return -1;
}

if (argc >= 3)
{
istringstream dly(argv[2]);
if (!(dly >> readDelay)) {
cerr << "Invalid delay in milliseconds." << argv[1] << " using 10000" << endl;
readDelay = 10000;
}
}

if (argc >= 4)
{
istringstream cnt(argv[3]);
if (!(cnt >> readCount)) {
cerr << "Invalid count (number expected, using -1 for continuous) " << argv[3] << endl;
readCount = -1;
}
}
if (argc >= 5)
{
commands.str(argv[4]);

}
int proc = 100;
char* result = new char[500];

if (!Loaddll()) {
cerr << "DLL failed.  Check path above.\n";
return -1;
}
clog << "Testing write & read combination before logging....";

proc = Gwrite(address, (char *)commands.str().c_str());
if (proc != 0)
{
cerr << "WRITE TEST FAILED. Error Found! UG Simple returned a non-zero result." << endl;
return -1;
}
clog << "Write test good." << endl;

result = Gread(address);//read measured data or result from device
if (result[0] == 0xA)
{
cerr << "READ TEST FAILED. Error Found! UG Simple returned a non-zero result." << endl;
return -1;
}
clog << "Read test good." << endl;

int i=-1;
if (readCount>0) i = -1*readCount;
clog << "Begin logging to standard out every " << readDelay << "ms Ctrl-C to stop.\n";
while (i<0)
{
proc = Gwrite(address, (char *)commands.str().c_str());
istringstream r(Gread(address));//read from device
double dr = 0.00;
r >> dr;
cout << dr << endl;
Sleep(readDelay);

if (i != -1) i++;
}
    return 0;
}

bool Loaddll(void)
{
hInst = NULL;
hInst = LoadLibrary(TEXT("C:\\Program Files (x86)\\LQElectronics\\UGSimple\\UGSimpleAPI\\LQUGSimple_c.dll"));
if (hInst == NULL)
{
cerr << "Unable to load dll at C:\\Program Files(x86)\\LQElectronics\\UGSimple\\UGSimpleAPI\\LQUGSimple_c.dll c\n";
return false;
}
Gwrite = (gwrite1)GetProcAddress(hInst, "Gwrite");
Gread = (gread1)GetProcAddress(hInst, "Gread");
return true;
}
DS1054Z, HP3455A, HP3457A, Agilent 34401A, HP5334B-010-030, HP204D, EX430, Agilent 6612C, (2) Sorensen XTS15-4 /M1 /M9B, WaveTek 131, WaveTek 134,PAR 110, FG-8002,FY3200S, UNI-T61E, TEK2465
 
The following users thanked this post: cellularmitosis, kj7e

Offline cellularmitosis

  • Supporter
  • ****
  • Posts: 1111
  • Country: us
Re: UGSimple GPIB hacks
« Reply #2 on: April 29, 2018, 06:57:04 am »
Very cool!

I was reminded that someone wrote a python interface to the UGSimple: https://github.com/haata/ugsimple-usb-gpib

I thought I'd see if I could get it working on windows.

Unfortunately, it seems that getting libusb to work from python on windows is a total nightmare (I'm a developer and I can't figure it out).

I literally just wasted all evening on this: https://github.com/pyusb/pyusb/issues/120#issuecomment-385225830
LTZs: KX FX MX CX PX Frank A9 QX
 

Offline guenthert

  • Frequent Contributor
  • **
  • Posts: 712
  • Country: de
Re: UGSimple GPIB hacks
« Reply #3 on: April 29, 2018, 09:14:04 am »
UGSimple is the least expensive option.
Can't help to think of the bonmot "The most expensive car is a cheap used <insert favorite luxory car brand>".

I actually gave up on it long time ago and was much happier with a proper PCI based GPIB adaptor with sound hardware and software (https://linux-gpib.sourceforge.io/).  Sadly in my recent move, I lost my lab PC with that card.  I'm not sure, whether I wan't another PC with fans and hence am motivated to give the Raspberry Pi / UGSimple combo another try.

  The hardware (a PIC18 directly connected to the GPIB pins) is fundamentally limited in that the MCU just cannot drive enough current, which might be an issue when attempting to control multiple or older instruments.  It's also slow, but that shouldn't be much of a concern when just reading some DMMs or setting some PSUs.
 
  My main grief however is with the software.  The Python library seems to be written by someone who's calling simply is not software development.  It seems to be reversed engineer'ed from the Windows software, which I haven't looked much into yet.

  Simple requests against a recent enough (HP3456A, but not a HP5328A) instrument seem to work, but I have yet to succeed in sending a trigger and subsequently reading the data.



  Let's make it work!
Tell us your UGSimple Hack!
The end goal -- if possible -- should be integration into an existing GPIB library.  I rather not write hardware dependent application software.
Not sure, if this hardware is worth the trouble though.
 :popcorn:
 

Offline flittleTopic starter

  • Contributor
  • Posts: 17
  • Country: us
Re: UGSimple GPIB hacks
« Reply #4 on: April 29, 2018, 03:20:07 pm »

The end goal -- if possible -- should be integration into an existing GPIB library.  I rather not write hardware dependent application software.
Not sure, if this hardware is worth the trouble though.
 :popcorn:
When I paid about the same price for the UGSimple as for my HP3455A it seems to be worth the trouble to me get it to at least log measurements which I think it is now doing well on my Windows 10 notebook.  I don't have more than one GPIB and all of it's limitations work ok for me so far. 

I just wanted people who had bought it or wanted to pay small money for it to have way to use it.

Very cool!

I thought I'd see if I could get it working on windows.

Could you try my code on Windows?
Syntax is:  uglogger address [delay] [count] [commands]
In my case on e HP3455A I used the following command:
uglogger 1 3000 -1 "F1R3A1H1"
the -1 will make it run until Ctrl-C.

here  is the runtime: https://www.dropbox.com/s/3su83rqwhg8d1gq/VC_redist.x86.exe?dl=0
DS1054Z, HP3455A, HP3457A, Agilent 34401A, HP5334B-010-030, HP204D, EX430, Agilent 6612C, (2) Sorensen XTS15-4 /M1 /M9B, WaveTek 131, WaveTek 134,PAR 110, FG-8002,FY3200S, UNI-T61E, TEK2465
 

Offline rhb

  • Super Contributor
  • ***
  • Posts: 3481
  • Country: us
Re: UGSimple GPIB hacks
« Reply #5 on: April 29, 2018, 06:44:05 pm »
I bought a UGPlus which I'm returning tomorrow.  I could never get it to work with Windows 7 on a VirtualBox VM.  Sometimes it saw the device, sometimes it didn't.  I got the impression the issue was the USB device driver.

Now I'm trying to decide whether to write an interface program using an Arduino or buy an Agilent or NI device.
 

Offline maxwell3e10

  • Frequent Contributor
  • **
  • Posts: 869
  • Country: us
Re: UGSimple GPIB hacks
« Reply #6 on: April 29, 2018, 07:40:18 pm »
It doesn't seem worth the trouble fussing with one of the unreliable UG devices when on a good day one can get a GPIB to RS232 converter on ebay for about $50. But there are many solutions that can be implemented for just a few bucks, I have summarized some in this post
https://www.eevblog.com/forum/testgear/diy-gpib-to-usb-summary-and-way-forward/msg1349307/

There is no clear winner, but with a bit of effort it should be possible to converge on the best solution. I plan to setup one of these soon, just not sure which one yet, as I have zero experience in microcontrollers.
 

Offline eurofox

  • Supporter
  • ****
  • Posts: 873
  • Country: be
    • Music
Re: UGSimple GPIB hacks
« Reply #7 on: April 29, 2018, 09:06:21 pm »
I don't understand that your guy's want to spend time and money on those fake interfaces instead of using the real genuine Agilent USB to GPIB interface.

NO! it doesn't cost many $$$, I got a brand new one in original packing like the one below.  :-DD

https://www.benl.ebay.be/itm/New-In-Box-HP-Agilent-82357B-USB-GPIB-Interface-High-Speed-USB-2-0-CD/112921365937?hash=item1a4aa34db1:g:FxEAAOSw52ZayJ4I
eurofox
 

Offline Kosmic

  • Super Contributor
  • ***
  • Posts: 2527
  • Country: ca
Re: UGSimple GPIB hacks
« Reply #8 on: April 30, 2018, 12:22:54 am »
Now I'm trying to decide whether to write an interface program using an Arduino or buy an Agilent or NI device.

You could try building this one: http://www.dalton.ax/gpib/

Working well for me on windows 10. But only tried with 2 gpib devices. Its based around a pic18f2550 so the drivers are well supported across multiple os. Plus its mimicking the prologix protocol, so compatible with a lot of software.

On my side it was the obvious choice since I had all the parts at hands already. I only had to find a gpib connector. Which was surprisingly expensive.

Note that the leds and led driver are optional.
 
The following users thanked this post: zhtoor, flittle

Offline cellularmitosis

  • Supporter
  • ****
  • Posts: 1111
  • Country: us
Re: UGSimple GPIB hacks
« Reply #9 on: April 30, 2018, 04:02:27 am »
Could you try my code on Windows?
Syntax is:  uglogger address [delay] [count] [commands]
In my case on e HP3455A I used the following command:
uglogger 1 3000 -1 "F1R3A1H1"
the -1 will make it run until Ctrl-C.

here  is the runtime: https://www.dropbox.com/s/3su83rqwhg8d1gq/VC_redist.x86.exe?dl=0

Yeah, I also just downloaded the visual studio standalone compiler, so hopefully I can try fooling around with your code too.

Is there a way I can run your exe to just read from a "talk only" device without sending a command to it?
LTZs: KX FX MX CX PX Frank A9 QX
 

Offline flittleTopic starter

  • Contributor
  • Posts: 17
  • Country: us
Re: UGSimple GPIB hacks
« Reply #10 on: May 01, 2018, 03:33:40 pm »
Is there a way I can run your exe to just read from a "talk only" device without sending a command to it?

You can try not adding the last parameter (or any parameters besides the address which is required) or adding ""
so:

uglogger 11
uglogger 11 3000 -1 ""

I messed with Talk Only first and I couldn't get anything happening but I don't remember how deep I went on talk only.


DS1054Z, HP3455A, HP3457A, Agilent 34401A, HP5334B-010-030, HP204D, EX430, Agilent 6612C, (2) Sorensen XTS15-4 /M1 /M9B, WaveTek 131, WaveTek 134,PAR 110, FG-8002,FY3200S, UNI-T61E, TEK2465
 

Offline flittleTopic starter

  • Contributor
  • Posts: 17
  • Country: us
Re: UGSimple GPIB hacks
« Reply #11 on: May 01, 2018, 03:39:38 pm »
You could try building this one: http://www.dalton.ax/gpib/

When I am done with Round 2 of the usa calibration club perhaps I will make that one with the GPIB from my UGSimple but the results are so good so far perhaps I will just buy a new connector.
DS1054Z, HP3455A, HP3457A, Agilent 34401A, HP5334B-010-030, HP204D, EX430, Agilent 6612C, (2) Sorensen XTS15-4 /M1 /M9B, WaveTek 131, WaveTek 134,PAR 110, FG-8002,FY3200S, UNI-T61E, TEK2465
 

Offline flittleTopic starter

  • Contributor
  • Posts: 17
  • Country: us
Re: UGSimple GPIB hacks
« Reply #12 on: May 01, 2018, 03:42:49 pm »
Quote
Too all of the negative comments. :wtf:

UGSimple isn't a fake.  It doesn't pretend to be something else.  UGsimple is just a USB to 488 adapter and it is working great for me in my intended purpose of logging measurements from my HP3455A. It logged 21000 uninterrupted events over the weekend without a single hiccup which is all it needs to do.  My results were so good I plan to add serial port to the logger to also grab environmental data from my envlogger.
DS1054Z, HP3455A, HP3457A, Agilent 34401A, HP5334B-010-030, HP204D, EX430, Agilent 6612C, (2) Sorensen XTS15-4 /M1 /M9B, WaveTek 131, WaveTek 134,PAR 110, FG-8002,FY3200S, UNI-T61E, TEK2465
 
The following users thanked this post: cellularmitosis

Offline Muxr

  • Super Contributor
  • ***
  • Posts: 1369
  • Country: us
Re: UGSimple GPIB hacks
« Reply #13 on: August 16, 2018, 04:59:12 am »
Very cool!

I was reminded that someone wrote a python interface to the UGSimple: https://github.com/haata/ugsimple-usb-gpib

I thought I'd see if I could get it working on windows.

Unfortunately, it seems that getting libusb to work from python on windows is a total nightmare (I'm a developer and I can't figure it out).

I literally just wasted all evening on this: https://github.com/pyusb/pyusb/issues/120#issuecomment-385225830
I think I fixed the python lib for UGSimple interface. I published the PR on the main project (https://github.com/haata/ugsimple-usb-gpib/pull/7). The maintainer looks to be inactive on it (even though he's active on other projects) so not sure when it will get merged.

But here is the link to the branch on my fork if you want to clone it and use it: https://github.com/sirmo/ugsimple-usb-gpib/tree/fixes1

Basically I found two issues with it. Python's usb.core (at least on raspberry pi) is a bit flaky and it can silently time out.

The other issues is that the read() method can desync from the USB buffer. The original code is pretty convoluted at least for me, I am really not sure what the original author was trying to accomplish with it. So instead of gutting all his code I just added a new method ask().

Which handles both writing of the command to the instrument and reading the result. It even has error checking built in, so if flaky USB subsystem rears its ugly head it will check the result and re run the command.

You can do things like ask(instrument_address, "some command?", method="retry", delimiter="\r\n") and it will retry until it gets a result which ends with "\r\n" (which is the case for my 3458a). This is the default behaviour so you don't have to specify method and delimiter if you want this.

Or you can do ask(instrument_address, "some command?", method="quorum") and it will run 10 times by default and pick the result which returned most times. This is not useful for measurements (since those fluctuate) but I've used it for making sure my NVRAM backup from 3458a was correct.

Anyways, why UGSimple? Because it's $30. It works. I can wire half a dozen GPIB interfaces to a raspberry pi with a wifi adapter and have a whole rack of GPIB instruments controlled remotely via a REST interface. It's awesome.

p.s I also included a 3458a NVRAM backup script as an example. The original script was written for Prologix library which also has the ask() method which is kind of the reason I added it to the UGSimple to make cross porting scripts between these popular GPIB interfaces easier.
« Last Edit: August 16, 2018, 05:10:45 am by Muxr »
 
The following users thanked this post: cellularmitosis, flittle

Offline cellularmitosis

  • Supporter
  • ****
  • Posts: 1111
  • Country: us
Re: UGSimple GPIB hacks
« Reply #14 on: August 20, 2018, 04:55:10 am »
Excellent work Muxr!!!  :-+ :-+ :-+
LTZs: KX FX MX CX PX Frank A9 QX
 
The following users thanked this post: Muxr


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf