UGSimple GPIB hacks - Page 1
Forum section: electronics / general

author: flittle
author_rank: Contributor
timestamp: April 29, 2018, 03:41:46 am
content: 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:proc = Gwrite(address, (char *)commands.str().c_str());istringstream r(Gread(address));//read from devicedouble 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=0Apologies in advance for my vc++ code.Here is the exe:https://www.dropbox.com/sh/a61s7tsyf3ap3h5/AADj9XF92ool0dqbZh2XoLK1a?dl=0Tell us your UGSimple Hack!

author: flittle
author_rank: Contributor
timestamp: April 29, 2018, 03:45:27 am
content: Here is the entire cpp file:Code:// 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 argvchar *argv[], // Array of command-line argument stringschar *envp[]) // Array of environment variable strings{// usage uglogger address "cmds" delay countclog << "uglogger - v0.1" << endl << "by flittle" << endl;if (argc < 2){cerr << "\nUsage: uglogger address   [\"commands\"]\n" << "\n Example:\n uglogger 11\n";return -1;}istringstream addr(argv);if (!(addr >> address)) {cerr << "Invalid address " << argv << endl;return -1;}if (argc >= 3){istringstream dly(argv);if (!(dly >> readDelay)) {cerr << "Invalid delay in milliseconds." << argv << " using 10000" << endl;readDelay = 10000;}}if (argc >= 4){istringstream cnt(argv);if (!(cnt >> readCount)) {cerr << "Invalid count (number expected, using -1 for continuous) " << argv << endl;readCount = -1;}}if (argc >= 5){commands.str(argv);}int proc = 100;char* result = new char;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 deviceif (result == 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 devicedouble 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;}

author: cellularmitosis
author_rank: Unknown
timestamp: April 29, 2018, 06:57:04 am
content: Very cool!I was reminded that someone wrote a python interface to the UGSimple:https://github.com/haata/ugsimple-usb-gpibI 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

author: guenthert
author_rank: Frequent Contributor
timestamp: April 29, 2018, 09:14:04 am
content: Quote from: flittle on April 29, 2018, 03:41:46 amCan'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.Quote from: flittle on April 29, 2018, 03:41:46 amThe 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.

author: flittle
author_rank: Contributor
timestamp: April 29, 2018, 03:20:07 pm
content: Quote from: guenthert on April 29, 2018, 09:14:04 amWhen 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.Quote from: cellularmitosis on April 29, 2018, 06:57:04 amCould you try my code on Windows?Syntax is: uglogger address   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

author: rhb
author_rank: Super Contributor
timestamp: April 29, 2018, 06:44:05 pm
content: 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.

author: maxwell3e10
author_rank: Frequent Contributor
timestamp: April 29, 2018, 07:40:18 pm
content: 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 posthttps://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.

author: eurofox
author_rank: Unknown
timestamp: April 29, 2018, 09:06:21 pm
content: 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.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

author: Kosmic
author_rank: Super Contributor
timestamp: April 30, 2018, 12:22:54 am
content: Quote from: rhb on April 29, 2018, 06:44:05 pmYou 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.

author: cellularmitosis
author_rank: Unknown
timestamp: April 30, 2018, 04:02:27 am
content: Quote from: flittle on April 29, 2018, 03:20:07 pmYeah, 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?

author: flittle
author_rank: Contributor
timestamp: May 01, 2018, 03:33:40 pm
content: Quote from: cellularmitosis on April 30, 2018, 04:02:27 amYou can try not adding the last parameter (or any parameters besides the address which is required) or adding ""so:uglogger 11uglogger 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.

author: flittle
author_rank: Contributor
timestamp: May 01, 2018, 03:39:38 pm
content: Quote from: Kosmic on April 30, 2018, 12:22:54 amWhen 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.

author: flittle
author_rank: Contributor
timestamp: May 01, 2018, 03:42:49 pm
content: QuoteUGSimple 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.

author: Muxr
author_rank: Super Contributor
timestamp: August 16, 2018, 04:59:12 am
content: Quote from: cellularmitosis on April 29, 2018, 06:57:04 amI 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/fixes1Basically 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 theread()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 methodask().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 likeask(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 doask(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 theask()method which is kind of the reason I added it to the UGSimple to make cross porting scripts between these popular GPIB interfaces easier.

author: cellularmitosis
author_rank: Unknown
timestamp: August 20, 2018, 04:55:10 am
content: Excellent work Muxr!!!