---
title: "Arduino-based Agilent/Keysight USB-to-IR Adapter to LAN Adapter"
url: "https://maker.wiznet.io/praveen_k/projects/Arduinobased-AgilentKeysight-USBtoIR-Adapter-to-LAN-Adapter/"
markdown_url: "https://maker.wiznet.io/praveen_k/projects/Arduinobased-AgilentKeysight-USBtoIR-Adapter-to-LAN-Adapter/md"
type: "UCC: User Created Content"
author: "praveen_k"
author_url: "https://maker.wiznet.io/praveen_k/"
original_author: "praveen_k"
original_url: "https://goughlui.com/2021/10/30/project-arduino-based-agilent-keysight-usb-to-ir-adapter-to-lan-adapter/"
published: "2022-03-28"
language: "en"
hardware: ["WIZnet W5100 ethernet shield", "usb host shield"]
likes: 0
views: 179
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Arduino-based Agilent/Keysight USB-to-IR Adapter to LAN Adapter

> Arduino-based Agilent/Keysight USB-to-IR Adapter to LAN Adapter

Original author: praveen_k (source: https://goughlui.com/2021/10/30/project-arduino-based-agilent-keysight-usb-to-ir-adapter-to-lan-adapter/)

## Components

- **WIZnet W5100 ethernet shield** x 1 ([docs](https://www.wiznet.hk/en/open-source-hardware/102-w5100s-ethernetshield.html?search_query=W5100+ethernet+shield&results=84))
- **usb host shield** x 1

## Article

It was many moons ago when I treated myself to a proper name-brand DMM with some decent accuracy, an?[Agilent/Keysight U1241B](https://goughlui.com/2015/01/28/review-agilent-u1241b-4-digit-handheld-dmm-accessories/)?complete with a U1173 USB to IR interface cable and a few other accessories. In the intervening years, I also ended up with a Keysight U1242B, a close cousin which has a few more features, so similar that some have unlocked the U1241B to U1242B by some EEPROM modifications. These handheld DMMs have served me well, with one of the drawcards being the?[Keysight Handheld Meter Logger software](https://www.keysight.com/au/en/lib/software-detail/computer-software/keysight-handheld-meter-logger-software-for-pc-2470924.html)?which allows logging on PC via USB or both PC and?[mobile](https://www.keysight.com/au/en/lib/software-detail/computer-software/keysight-meter-logger-for-ios-and-android-2943792.html)?via Bluetooth. Unfortunately, the software has become quite dated and have some frustrating limitations and quirks, one of which includes loss of recording data on the PC if the Bluetooth connection fails (e.g. due to low battery) and an attempt is made to stop the log. Support on mobile seems to have dwindled slightly as well, with warnings about incompatibilities when running on more modern devices. As a test and measurement user, I have grown dramatically both in skill and in needs and running multiple-instrument tests is no longer a dream ? it’s my everyday reality. Sometimes, I find myself needing an extra measurement device here or there, but not having the budget nor inclination to purchase a benchtop DMM just to get that capability, I set off to make the Keysight handheld DMMs I have a little more useful.

## **One of Many Means of Connection?**

It is no great secret that the Keysight handheld DMMs?**actually use a?*bastardised*?version of SCPI commands**. These are not officially documented, but?[Sigrok has a good summary](https://sigrok.org/wiki/Agilent_U12xxx_series)?of most of the commands. While there’s very little to configure, often all you want is to grab readings from the DMM and that’s not all that difficult with the?*FETC?*?or?*READ?*?commands (both are equivalent). [![](https://goughlui.com/wp-content/uploads/2021/10/2021102717429845-1024x453.jpg)](https://goughlui.com/wp-content/uploads/2021/10/2021102717429845.jpg) Getting a connection to a PC is pretty easy (in theory) using the USB to IR lead, however the grey U1173A version comes with a trap which I wasn’t aware of when I purchased the lead ? it uses a old PL-2303X chip. [I noticed in 2017](https://goughlui.com/2017/11/12/problem-agilent-technologies-u1173a-compatibility-with-windows-10/)?that the adapter wouldn’t work under Windows 10 due to Prolific’s driver changes even though an older version of the driver did work. Sick of rolling back drivers only to have them auto-update and unreliable quirks when attempting to lock the drivers, I resorted to using a newer U1173B lead which works fine. [![](https://goughlui.com/wp-content/uploads/2021/10/prolific-support.png)](https://goughlui.com/wp-content/uploads/2021/10/prolific-support.png) Prolific’s?[download page](http://www.prolific.com.tw/US/ShowProduct.aspx?p_id=225&pcid=41)?lists the unending “roll-off” of driver support for older chips ? quite a few present-day chips are slated to get the axe come Windows 11 which is?**sure**?to surprise many people ? perhaps this means the U1173B is going to stop working too for no good reason. If USB doesn’t work for you, then surely Bluetooth is another option. This is definitely an option if you have the U1177A or U1117A adapters, noting that the more expensive U1117A is the only one that supports working with iOS devices and has the Class 1 radio offering better range. But I dislike this solution ? the wireless connectivity adds a potential reliability issue, whether by interference with the wireless link, general flakiness in the host adapter or drivers or by running out of battery mid-experiment. But regardless of the choice of connection, the Keysight DMMs throw another spanner in the works. Unlike the SCPI-compliant counterparts, this meter?**will**?send unsolicited status messages when you turn the dial to indicate dial position and on pressing certain buttons. All of these reports begin with an asterisk (*). For traditional SCPI device communication, it is performed?**lockstep**?? every query is expected to be matched with one reply, and every direct command is not expected to be replied to. Adding these unsolicited status messages into the stream will cause the software to fall out of step if it is not specially coded to handle them.

## **What Do?*I?*Want?**

Anyone with a serious test bench probably already knows that Ethernet connectivity is probably the best answer for all general uses nowadays. Inexpensive, scalable, electrically isolated, capable of connecting devices over long distances and sharing instruments with other hosts on the network, Ethernet is often the best choice despite limitations in performance due to latency. It would make sense to put it on my LAN this way, although Wi-Fi may come a close second (assuming it is reliable?*enough*). To do this, I?**could**?have pursued an approach like my previous?[USB-TMC LAN bridge](https://goughlui.com/2021/02/20/project-a-usb-tmc-to-ethernet-lan-bridge-with-a-difference/), but that seemed like trying to crush an ant using a sledgehammer. The Raspberry Pi is powerful, but it is picky ? microSD cards can corrupt if not powered down properly (making it read-only helps), start-up takes a while and it consumes quite a bit of power. Instead, what if I could build something that would use a microcontroller instead. After all, the IR interface runs at a default of 9600bps, so it’s not much speed nor data to handle. Having previously opened the adapter, I realised that it was nothing but an ordinary USB-UART glued to some circuitry to translate the signal into IR and back. I could modify this and attach it directly to an Arduino UART instead, shove in an Ethernet shield to talk onto a network and call it a day. But that would mean cutting up the?**nicely?**built cable which seemed hardly justified given that it would still work just fine under any Linux. This led me down the path of wondering just how to support USB on a micrcontroller. As it turns out, USB host mode is something that is the preserve of but a few microcontrollers and support is rather patchy. But there was a solution that seemed a little more mature and tested ? the?[USB Host Shield](https://chome.nerpa.tech/usb-host-shield-hardware-manual/)?from Circuits-at-Home which is based around a Maxim MAX3421E Full Speed (12Mbit/s) USB-SPI Peripheral/Host Controller. Given the library has support for the PL-2303, I thought this was a good bet. I’m forever indebted to the fact that something as wonderful as this is Open Source!

## **The Contract Goes to the Lowest Bidder**

[![](https://goughlui.com/wp-content/uploads/2021/10/2021102617549839-1024x754.jpg)](https://goughlui.com/wp-content/uploads/2021/10/2021102617549839.jpg) As usual, I didn’t want to spend more than I needed on the project because it is a “nice to have” but is by no means essential. Using an old Arduino Leonardo board I already have (there are always plenty of “classic” Arduino boards floating around the house), I ordered a USB Host Shield and an Ethernet shield, costing a total of about AU$33 shipped from China. [![](https://goughlui.com/wp-content/uploads/2021/10/2021102617559840-1024x975.jpg)](https://goughlui.com/wp-content/uploads/2021/10/2021102617559840.jpg) The USB Host Shield doesn’t look too complicated ? it’s exactly as you would expect based on the hardware manual online, but there were a few minor setbacks initially. The headers aren’t exactly well-aligned and there is some flux residue on the back of the ICSP header. [![](https://goughlui.com/wp-content/uploads/2021/10/2021102617569841-1024x992.jpg)](https://goughlui.com/wp-content/uploads/2021/10/2021102617569841.jpg) There was some solder flux residue on the pins of the USB-A port as well. As with many of these items, they are packed inside a proper static shielding bag but have their feet pierced into seemingly “ordinary” non-ESD-safe foam. This isn’t ideal, but it also provides little to no protection for the pins against bending in transit. The result is a shield that needs some?*finessing*?of the pins to get it in. [![](https://goughlui.com/wp-content/uploads/2021/10/2021102617569842-1024x729.jpg)](https://goughlui.com/wp-content/uploads/2021/10/2021102617569842.jpg) This version of the Ethernet Shield definitely takes its visuals from the official product, but looks a bit rough in some way. Of note is that it, like many others, seems to be using the?[fail-unsafe AMS1117](https://goughlui.com/2021/03/27/note-linear-regulator-woes-when-is-an-ams1117-not-an-ams1117/)?clone for voltage regulation. [![](https://goughlui.com/wp-content/uploads/2021/10/2021102617569843-1024x770.jpg)](https://goughlui.com/wp-content/uploads/2021/10/2021102617569843.jpg) The pins on this shield were mangled even worse and the flux residue is also visible. As long as it works, I’ll be happy, but aside from having the Arduino URL on the top, the bottom also dares to print the “DESIGN[sic] IN ITALY” line which I suppose is not wrong, but is a bit pretentious given that it’s a pretty rough clone.

## **When You Have a Dremel?*(Clone)*, Everything?*Needs*?Dremeling!**

While the shield concept is nice, the problem is that not everything “stacks up nicely” for a number of reasons. [![](https://goughlui.com/wp-content/uploads/2021/10/2021102717429846-1024x740.jpg)](https://goughlui.com/wp-content/uploads/2021/10/2021102717429846.jpg) One key issue is the fact the Ethernet shield has a tall Ethernet connector meaning anything that stacks on top is not going to sit nicely without either some “extensions” or in my case,?**creative use of the Dremel (clone) to notch out part of the PCB**, annihilating a trace in the process, requiring a patch wire. The second issue is the use of ICSP ports to access the SPI controller. This is great for compatibility, but almost?**never**?are they fitted with stackable headers. This means that you can only have one SPI-based shield attached unless you are a little creative. In my case, I got a four way ribbon wire just to patch the signals that were needed ? MISO, MOSI, SCLK and RST. The shields can’t be detached from one another, but at least they should work. But wait …?**not so fast**. The SS pin is also a problem as Pin 10 is taken by the Ethernet. As a result, we can cut open the pads near the SS line and patch that to another pin ? as I had my Dremel (clone) in hand, I decided to just grind away the pads entirely.?*Can’t be too power hungry!* [![](https://goughlui.com/wp-content/uploads/2021/10/2021102717429847-1024x600.jpg)](https://goughlui.com/wp-content/uploads/2021/10/2021102717429847.jpg) The result is a fairly nice-stack … [![](https://goughlui.com/wp-content/uploads/2021/10/2021102717429848-1024x736.jpg)](https://goughlui.com/wp-content/uploads/2021/10/2021102717429848.jpg) … which should hopefully do the job I want it to do as long as I get my code right. [![](https://goughlui.com/wp-content/uploads/2021/10/2021102717439851-1024x567.jpg)](https://goughlui.com/wp-content/uploads/2021/10/2021102717439851.jpg) For good measure, I decided to also desolder the “excessive” LEDs adorning the Ethernet shield. No need for 100M/Link LEDs on the PCB when the RJ45 port has functioning ones on it. Likewise, no need for additional RX/TX and ON LEDs just wasting power away.

## ***All in a Night’s Work*?? Coding and Testing**

Step one was getting the hardware to work. As I had redirected the SS line to Pin 8, I had to make the change in the UsbCore.h file to match. [![](https://goughlui.com/wp-content/uploads/2021/10/kirlan-usbcoreh.png)](https://goughlui.com/wp-content/uploads/2021/10/kirlan-usbcoreh.png) With that done, it was time to test out the example sketches. I tried the?*USB_desc*?sketch but no dice with an “OSC did not start.” message. Trying the?*board_qc*?sketch it was not possible to read the die revision, so it seems the shield isn’t working. [![](https://goughlui.com/wp-content/uploads/2021/10/usbshield-nojoy1-300x221.png)](https://goughlui.com/wp-content/uploads/2021/10/usbshield-nojoy1.png)?[![](https://goughlui.com/wp-content/uploads/2021/10/usbshield-nojoy2-300x217.png)](https://goughlui.com/wp-content/uploads/2021/10/usbshield-nojoy2.png) Having dremeled the first one, I took out a second and tried it without redirecting the SS pin and set the original settings in UsbCore.h but there was no change. It took me about half an hour to work out why ? [![](https://goughlui.com/wp-content/uploads/2021/10/2021102718339854-1024x964.jpg)](https://goughlui.com/wp-content/uploads/2021/10/2021102718339854.jpg) The board is designed with the possibility to provide independent 3.3V and 5V supplies. The USB Vbus can also be selected to be from 5V or 3.3V rail. Unfortunately, those selection pads were?**not**?soldered together from the factory as they might have been in the original unit, meaning both 5V and 3.3V supplies were not getting to the chips. No wonder it wasn’t working! Adding three solder blobs (as in the above image) fixed it all up. [![](https://goughlui.com/wp-content/uploads/2021/10/usbshield-fix1.png)](https://goughlui.com/wp-content/uploads/2021/10/usbshield-fix1.png) Now, the?*board_qc*?test has passed, although I did not connect the GPIO pins for that test. [![](https://goughlui.com/wp-content/uploads/2021/10/kirlan-usbdesc-471x1024.png)](https://goughlui.com/wp-content/uploads/2021/10/kirlan-usbdesc.png) Attaching the USB to IR adapter lead, the?*USB_desc*?sketch can read out the USB information. That is good to see. I decided to modify the provided?*pl2303_gprs_terminal*?sketch to do some preliminary testing. [![](https://goughlui.com/wp-content/uploads/2021/10/usbshield-compat.png)](https://goughlui.com/wp-content/uploads/2021/10/usbshield-compat.png)It seems that after the connection is established, the serial terminal spews out a blob of HEX characters. Perhaps that’s related to the USB descriptor, but I was finding that communications over the USB to IR lead was not consistent. This led me to discover a setting in?*cdcprolific.h?*called PL2303_COMPAT. [![](https://goughlui.com/wp-content/uploads/2021/10/kirlan-cdcprolifich.png)](https://goughlui.com/wp-content/uploads/2021/10/kirlan-cdcprolifich.png) Uncommenting the line from the header file brings the following lines into play from?*cdcprolific.cpp*?? [![](https://goughlui.com/wp-content/uploads/2021/10/usbshield-compat2.png)](https://goughlui.com/wp-content/uploads/2021/10/usbshield-compat2.png) It seems there is a bunch of commands, but what they actually do is a mystery. It didn’t seem to make anything worse, so I adopted it. I then decided to grab the code that ran my?[modified car fridge](https://goughlui.com/2021/05/02/project-modified-car-fridge-pro-mk-ii-sabotaged-by-cheapness/)?and change it up so it will talk over the USB Host Shield. A number of changes needed to be made ? reading from the USB to IR adapter does not always yield complete responses, so reading is done until encountering a newline and then the response is sent out in a single packet to make it more network friendly. Unsolicited messages beginning with “*” are also filtered out and discarded to make it more?*pyvisa*/SCPI compatible. To simplify the configuration, I decided to stick with DHCP-only as I was having strange behaviour in Static IP mode with the latest Ethernet Shield Library. In the end, I called the sketch?[*gough-kirlanv01*](https://goughlui.com/wp-content/uploads/2021/10/gough-kirlanv01.zip)?and the code is listed in the Appendix. When built, it uses 26,672 bytes (93%) Flash and 959 bytes (37%) RAM of an Arduino Leonardo, so there is not much left, but perhaps had I chose an Arduino Mega, it would have been possible to make it a standalone data logger to microSD card too. [![](https://goughlui.com/wp-content/uploads/2021/10/kirlan-putty.png)](https://goughlui.com/wp-content/uploads/2021/10/kirlan-putty.png) It only took me a night after work to get it working (well, it did keep me up to 1am the next morning). Well worth the effort, I thought! Now that it’s up and running, I did some quick tests. Power consumption was about 209mA at 5V for the full stack with it connected to an Ethernet network and the USB-to-IR adapter which is pretty acceptable. Running a modified SCPI benchmark shows that the response time to an?**IDN?*?request is about 185ms. Considering?*“*IDN?n”*?has six characters, and the response “Keysight Technologies,U1242B,MY58030018,V3.01n” has 46 characters, that is a total of 52 characters. At a baud rate of 9600bps, in 8-N-1, 960 characters per second can be transmitted. As a result, transmitting the characters across the IR link would take about 54ms alone (around 29% of the measured time).

## **Keeping the Lights On ? A?*Dangerous*?Mod**

Getting the meter onto the network may make it more useful, but one key downside compared to benchtop units (aside from its sophistication and accuracy) is the fact that the unit is battery powered. Batteries can be problematic as they can run out at the most inopportune times and cost money to replace or time to recharge. I decided it might be nice to modify the DMM to allow it to run on mains power in some way. While this may seem a simple idea,?**it is actually quite dangerous**?as the safety isolation of many handheld DMMs is?**because**?they run on a battery which is isolated and sealed away in a chamber. It’s also why so many user manuals remind users to disconnect the probes before replacing the fuse or battery ? it’s likely that there is only?**limited**?impedance between the battery and the inputs and perhaps even a common ground!

> **!!! DO NOT**?ATTEMPT THIS MODIFICATION UNLESS YOU UNDERSTAND AND ACCEPT THE SAFETY RISK THAT IT POSES, AND HAVE CONSIDERED ALL CONSEQUENCES THAT COULD ARISE !!! **!!! I WILL NOT BE HELD RESPONSIBLE FOR ANY DAMAGES THAT MAY ARISE !!!**

Regardless, I reasoned that an isolated power supply or a larger external battery may prove to be sufficiently safe for my needs (but perhaps not to the same CAT ratings). I got to work with a piece of veroboard and my clone Dremel to shape a piece of material that would be roughly battery-shaped to go into the battery bay as there is not much space inside the meter for a power socket. [![](https://goughlui.com/wp-content/uploads/2021/10/2021102817459856-1024x597.jpg)](https://goughlui.com/wp-content/uploads/2021/10/2021102817459856.jpg) To make some battery contact pads, I decided to grab some spade crimps, put it into a mini-vice and hammer them into a right angle tab. This was soldered down to the board. [![](https://goughlui.com/wp-content/uploads/2021/10/2021102817459857-1024x616.jpg)](https://goughlui.com/wp-content/uploads/2021/10/2021102817459857.jpg) The resulting piece fits into the chamber perfectly and can be yanked out by depressing some of the springs along the one edge while lifting the board up. A reversible mod, so far … but with one catch ? how to get the wires out? [![](https://goughlui.com/wp-content/uploads/2021/10/2021102818019859-1024x509.jpg)](https://goughlui.com/wp-content/uploads/2021/10/2021102818019859.jpg) I decided to drill a hole through the rear battery panel ? while this will compromise any IP-rating the meter may have had, it is also not too big of a hole to patch in the future if that is necessary. As the DMM runs on four AAA cells, I reasoned it should be able to run from about 4.0 to 6.2V input. Fortunately, USB is a nice 5.0V nominally, so I used a spare USB Kelvin PCB and micro-B socket with some heatshrink to make a detachable power input. Not the most elegant solution but it works! A quick test showed that the DMM consumes about 1.9mA while measuring a DC voltage, but this rises to about 8.9mA when measuring AC (probably because of the load of computing a True RMS reading). Rechargeable AAA cells with a 900mAh capacity would last approximately 19 days measuring DC voltage but only 4 days measuring AC voltage. I didn’t check the current draw in other ranges or functions, but because it is so low, many automatic power-banks will turn off their output as the draw is too low. An isolated mains USB charger should work, as long as the insulation does not fail.

## **Is it Reliable?**

To check for stability and to put in a small element of danger, I decided to set up the DMM to monitor my mains AC voltage while being powered from an (isolated)?[USB multi-port charger](https://goughlui.com/2021/04/03/review-teardown-orico-qse-4u-4-port-smart-desktop-qc2-0-usb-charger/). This is possibly the worst-case I can imagine for a set-up like this, at least for common use cases. [![](https://goughlui.com/wp-content/uploads/2021/10/2021102818409860-1024x683.jpg)](https://goughlui.com/wp-content/uploads/2021/10/2021102818409860.jpg) Letting it run for a while, we had our answer ? in a word, no.?***Not quite :(. *** I’ve had worse from some test equipment, but being subjected to being queried at approximately 0.25s intervals, I found that the converter would time-out on a transaction anywhere from 45-minutes to nine hours. This is a faster polling rate than their apps allow and the set-up may be vulnerable to mains noise being induced into it. The Arduino shields are basically “in open air” save for the electrical tape wrapping, so may pick up local EMI. At the moment, I can’t tell why the converter causes a timeout in this seemingly “random” range of time, but closing and re-opening the connection works just fine. Perhaps it’s a glitch on the USB side or Ethernet side? Maybe it’s the meter itself? Or a subtle bug with the code I can’t see at the moment. But it means that either the code that reads the meter needs to be a little bit more accommodating, or more work needs to be done to improve the stability of the solution by perhaps debugging where the communications fall apart. [![](https://goughlui.com/wp-content/uploads/2021/10/kirlan-tbr-1024x665.png)](https://goughlui.com/wp-content/uploads/2021/10/kirlan-tbr.png) I could query it continuously and the response interval seems to be bimodal. About 10 readings per second seems sensible based on the display update rate. **UPDATE:**?Running the adapter using a?*pyvisa*?script on my main desktop machine under the watchful eye of NI I/O Trace and Wireshark shows that the reading times out ? nothing untoward happens on the TCP/IP socket and things still seem to be operational, just that a response to a?*FETC?*?call was not responded to. Perhaps it was corrupted along the way due to a glitch in the USB or IR layers … or the DMM just didn’t respond. It should be possible to write the code more robustly to take care of a timeout and retry a query ? perhaps this is enough to keep things running in the long term without closing the resource and re-opening it.

## **Conclusion**

Having outgrown the relatively unmaintained Keysight Meter Logger and being dissatisfied with the state of Prolific PL-2303 driver support on Windows for their older ICs, I decided to try and turn my DMM into something I could use with?*pyvisa*?on my local network just like my benchtop DMM. Rather than using a “heavyweight” Raspberry Pi-based solution and not modifying the cable itself, I settled on using an Arduino, Ethernet Shield and USB Host Shield to prototype a solution. It was not entirely inexpensive, but it is definitely not unaffordable. In all, it seemed to work, but not with 100% reliability as the unit would stop responding randomly but be available to re-open immediately and work just fine for another few hours (often for six to nine hours). The cause is not known ? it could be hardware-related, interference of some sort, an issue with the code, a transient communication issue on the USB or IR segments or something to do with the multimeter itself. It’s better than nothing, but I was hoping for a bit more reliability. But considering it only cost me one night to get running, it’s not a big loss either way and it’s not entirely useless. I also made a rather dangerous modification to allow the DMM to run from USB power so it can be run continuously without batteries. This is not advisable as it does violate the safety category ratings and it is known that there may be common grounds and limited impedance between the battery terminals and the front test terminals. Using a suitably rated and isolated supply would be mandatory (or avoiding potentially dangerous voltages). While the USB Host Shield doesn’t have USB-TMC-supporting code to my knowledge, building something like this for USB-TMC devices may actually be a good thing. The Raspberry Pi can be fussy while a mostly hardware bare-metal solution like this is more robust. If only this was just a little more reliable and I had more time to wrap my head around USB-TMC and USB488 …

## **Appendix: gough-kirlanv01**

The code listing for the Arduino sketch that powers this particular project is provided below with no warranties. Feel free to use and modify with credit, but at your own risk. Alternatively, you can download the code in a?[ZIP file](https://goughlui.com/wp-content/uploads/2021/10/gough-kirlanv01.zip).

```
// Simple Keysight USB-IR Interface to LAN Adapter V0.1
// Using Arduino + Ethernet Shield + Modified USB Host Shield
// by Gough Lui (goughlui.com) - Oct-Nov 2021
//
// Free to use and modify with credit.
// No warranties expressed or implied. Use at your own risk.
//
// Relies on:
// USB Host Library Rev. 2.0 (https://github.com/felis/USB_Host_Shield_2.0)
// MUST ENABLE COMPATIBILITY MODE IN cdcprolific.h AND MODIFY PINS IN UsbCore.h
// Uses 26,672 bytes (93%) Flash and 959 bytes (37%) RAM of an Arduino Leonardo

#include <usbhub.h>
#include <cdcacm.h>
#include <cdcprolific.h>
#include <SPI.h>
#include <Ethernet.h>

#define MAX_CMD_LEN 65 // Must be <=255 due byte type counter and RAM limits

class PLAsyncOper : public CDCAsyncOper {
public:
 ???uint8_t OnInit(ACM *pacm);
};

uint8_t PLAsyncOper::OnInit(ACM *pacm) {
 ???pacm->SetControlLineState(1);
 ???LINE_CODING	lc;
 ???lc.dwDTERate	= 9600; // Default UART rate for Agilent DMMs
 ???lc.bCharFormat	= 0;
 ???lc.bParityType	= 0;
 ???lc.bDataBits	= 8;
 ???pacm->SetLineCoding(&lc);
 ???return 0;
}

// USB Interface Variables
USB ????Usb;
PLAsyncOper ?AsyncOper;
PL2303 ??????Pl(&Usb, &AsyncOper);

// Ethernet Server Variables
byte mac[6] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x12};
EthernetServer server(5025);
char ibuf[MAX_CMD_LEN] = {''};
char rbuf[MAX_CMD_LEN] = {''};
byte iptr=0;
byte rptr=0;
bool rspdone=0;
bool newbyte=0;

void setup() {
 ?pinMode(13,OUTPUT); // LED On - begin init init
 ?digitalWrite(13,HIGH);
 ?delay(250); // time for EtherTen Wiznet IC to reset
 ?Ethernet.begin(mac);
 ?server.begin();
 ?Usb.Init();
 ?digitalWrite(13,LOW); // LED Off - init complete
}

void loop() {
 ?EthernetClient client = server.available();
 ?char buf[65];
 ?uint16_t rcvd=64;
 ?char c;
 ?Usb.Task();
 ?if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) {
 ?????if (client) {
 ???????if (client.connected() && client.available()) {
 ???????????c = client.read();
 ???????????newbyte = 1;
 ?????????}
 ?????}
 ?????if(newbyte) {
 ???????newbyte = 0;
 ?????????if (c == 'n') {
 ???????????ibuf[iptr]=c;
 ???????????iptr++;
 ???????????ibuf[iptr]='';
 ???????????Pl.SndData(strlen(ibuf), ibuf);
 ???????????iptr=0;
 ?????????} else {
 ???????????if (iptr<MAX_CMD_LEN) { // over-length commands will be truncated!
 ?????????????ibuf[iptr]=c;
 ?????????????iptr++;
 ???????????}
 ?????????}
 ?????}
 ?????Pl.RcvData(&rcvd, buf);
 ?????if (rcvd) {
 ???????for(int j=0;j<rcvd;j++) {
 ?????????if(buf[j]=='n') {
 ???????????rspdone=1;
 ?????????}
 ?????????rbuf[rptr]=buf[j];
 ?????????rptr=rptr+1;
 ???????}
 ???????rbuf[rptr]=''; ??
 ?????}
 ?????if (rspdone) {
 ???????rspdone=0;
 ???????rptr=0;
 ???????if(rbuf[0]!='*') { // Unsolicited report messages are not passed
 ?????????server.print(rbuf);
 ?????????server.flush();
 ???????}
 ?????}
 ?}
 ?Ethernet.maintain(); // Keep DHCP happy
}
```

---

Source: https://maker.wiznet.io/praveen_k/projects/Arduinobased-AgilentKeysight-USBtoIR-Adapter-to-LAN-Adapter/
