Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a2da1791f4e6
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e65588e76cd7
Choose a head ref
  • 6 commits
  • 16 files changed
  • 1 contributor

Commits on Jun 1, 2019

  1. Copy the full SHA
    9487366 View commit details
  2. Copy the full SHA
    bb31766 View commit details
  3. Copy the full SHA
    e1e7f75 View commit details
  4. Added SCPIDevice class for *IDN? handling and transport management fo…

    …r non-oscilloscope instruments
    azonenberg committed Jun 1, 2019
    Copy the full SHA
    a2f079a View commit details
  5. Removed unused variable

    azonenberg committed Jun 1, 2019
    Copy the full SHA
    6b9fb26 View commit details
  6. Copy the full SHA
    e65588e View commit details
2 changes: 2 additions & 0 deletions scopehal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ set(SCOPEHAL_SOURCES

SCPITransport.cpp
SCPISocketTransport.cpp
SCPIDevice.cpp

Instrument.cpp
FunctionGenerator.cpp
@@ -25,6 +26,7 @@ set(SCOPEHAL_SOURCES
SiglentSCPIOscilloscope.cpp
RedTinLogicAnalyzer.cpp
RigolOscilloscope.cpp
RohdeSchwarzOscilloscope.cpp
RohdeSchwarzHMC8012Multimeter.cpp
RohdeSchwarzHMC804xPowerSupply.cpp
Multimeter.cpp
99 changes: 20 additions & 79 deletions scopehal/RohdeSchwarzHMC8012Multimeter.cpp
Original file line number Diff line number Diff line change
@@ -35,42 +35,9 @@ using namespace std;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction

RohdeSchwarzHMC8012Multimeter::RohdeSchwarzHMC8012Multimeter(string hostname, unsigned short port)
: m_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
, m_hostname(hostname)
, m_port(port)
RohdeSchwarzHMC8012Multimeter::RohdeSchwarzHMC8012Multimeter(SCPITransport* transport)
: SCPIDevice(transport)
{
LogDebug("Connecting to R&S HMC8012 DMM at %s:%d\n", hostname.c_str(), port);

if(!m_socket.Connect(hostname, port))
{
LogError("Couldn't connect to socket");
return;
}
if(!m_socket.DisableNagle())
{
LogError("Couldn't disable Nagle\n");
return;
}

//Ask for the ID
SendCommand("*IDN?");
string reply = ReadReply();
char vendor[128] = "";
char model[128] = "";
char serial[128] = "";
char swversion[128] = "";
if(4 != sscanf(reply.c_str(), "%127[^,],%127[^,],%127[^,],%127s",
vendor, model, serial, swversion))
{
LogError("Bad IDN response %s\n", reply.c_str());
return;
}
m_vendor = vendor;
m_model = model;
m_serial = serial;
m_fwVersion = swversion;

m_mode = GetMeterMode();
}

@@ -79,32 +46,6 @@ RohdeSchwarzHMC8012Multimeter::~RohdeSchwarzHMC8012Multimeter()

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Command helpers

bool RohdeSchwarzHMC8012Multimeter::SendCommand(string cmd)
{
cmd += "\n";
return m_socket.SendLooped((unsigned char*)cmd.c_str(), cmd.length());
}

string RohdeSchwarzHMC8012Multimeter::ReadReply()
{
string ret;
unsigned char tmp;

while(1)
{
if(!m_socket.RecvLooped(&tmp, 1))
return "";

if(tmp == '\n')
return ret;
else
ret += tmp;
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Device info

@@ -141,7 +82,7 @@ bool RohdeSchwarzHMC8012Multimeter::GetMeterAutoRange()
switch(m_mode)
{
case DC_CURRENT:
SendCommand("SENSE:CURR:DC:RANGE:AUTO?");
m_transport->SendCommand("SENSE:CURR:DC:RANGE:AUTO?");
break;

//TODO
@@ -150,7 +91,7 @@ bool RohdeSchwarzHMC8012Multimeter::GetMeterAutoRange()
return false;
}

string str = ReadReply();
string str = m_transport->ReadReply();
return (str == "1");
}

@@ -160,9 +101,9 @@ void RohdeSchwarzHMC8012Multimeter::SetMeterAutoRange(bool enable)
{
case DC_CURRENT:
if(enable)
SendCommand("SENSE:CURR:DC:RANGE:AUTO 1");
m_transport->SendCommand("SENSE:CURR:DC:RANGE:AUTO 1");
else
SendCommand("SENSE:CURR:DC:RANGE:AUTO 0");
m_transport->SendCommand("SENSE:CURR:DC:RANGE:AUTO 0");
break;

default:
@@ -183,8 +124,8 @@ void RohdeSchwarzHMC8012Multimeter::StopMeter()
double RohdeSchwarzHMC8012Multimeter::GetVoltage()
{
//assume we're in the right mode for now
SendCommand("READ?");
string str = ReadReply();
m_transport->SendCommand("READ?");
string str = m_transport->ReadReply();
double d;
sscanf(str.c_str(), "%lf", &d);
return d;
@@ -193,8 +134,8 @@ double RohdeSchwarzHMC8012Multimeter::GetVoltage()
double RohdeSchwarzHMC8012Multimeter::GetPeakToPeak()
{
//assume we're in the right mode for now
SendCommand("READ?");
string str = ReadReply();
m_transport->SendCommand("READ?");
string str = m_transport->ReadReply();
double d;
sscanf(str.c_str(), "%lf", &d);
return d;
@@ -203,8 +144,8 @@ double RohdeSchwarzHMC8012Multimeter::GetPeakToPeak()
double RohdeSchwarzHMC8012Multimeter::GetFrequency()
{
//assume we're in the right mode for now
SendCommand("READ?");
string str = ReadReply();
m_transport->SendCommand("READ?");
string str = m_transport->ReadReply();
double d;
sscanf(str.c_str(), "%lf", &d);
return d;
@@ -213,8 +154,8 @@ double RohdeSchwarzHMC8012Multimeter::GetFrequency()
double RohdeSchwarzHMC8012Multimeter::GetCurrent()
{
//assume we're in the right mode for now
SendCommand("READ?");
string str = ReadReply();
m_transport->SendCommand("READ?");
string str = m_transport->ReadReply();
double d;
sscanf(str.c_str(), "%lf", &d);
return d;
@@ -242,8 +183,8 @@ void RohdeSchwarzHMC8012Multimeter::SetCurrentMeterChannel(int /*chan*/)

Multimeter::MeasurementTypes RohdeSchwarzHMC8012Multimeter::GetMeterMode()
{
SendCommand("CONF?");
string str = ReadReply();
m_transport->SendCommand("CONF?");
string str = m_transport->ReadReply();

char mode[32];
sscanf(str.c_str(), "\"%31[^,]", mode);
@@ -264,15 +205,15 @@ void RohdeSchwarzHMC8012Multimeter::SetMeterMode(Multimeter::MeasurementTypes ty
switch(type)
{
case DC_VOLTAGE:
SendCommand("MEAS:VOLT:DC?");
m_transport->SendCommand("MEAS:VOLT:DC?");
break;

case DC_CURRENT:
SendCommand("MEAS:CURR:DC?");
m_transport->SendCommand("MEAS:CURR:DC?");
break;

case AC_CURRENT:
SendCommand("MEAS:CURR:AC?");
m_transport->SendCommand("MEAS:CURR:AC?");
break;

//whatever it is, not supported
@@ -283,5 +224,5 @@ void RohdeSchwarzHMC8012Multimeter::SetMeterMode(Multimeter::MeasurementTypes ty
m_mode = type;

//Wait for, and discard, the reply to make sure the change took effect
ReadReply();
m_transport->ReadReply();
}
21 changes: 3 additions & 18 deletions scopehal/RohdeSchwarzHMC8012Multimeter.h
Original file line number Diff line number Diff line change
@@ -30,17 +30,15 @@
#ifndef RohdeSchwarzHMC8012Multimeter_h
#define RohdeSchwarzHMC8012Multimeter_h


#include "../xptools/Socket.h"

/**
@brief A Rohde & Schwarz HMC8012 multimeter
*/
class RohdeSchwarzHMC8012Multimeter
: public virtual Multimeter
, public SCPIDevice
{
public:
RohdeSchwarzHMC8012Multimeter(std::string hostname, unsigned short port);
RohdeSchwarzHMC8012Multimeter(SCPITransport* transport);
virtual ~RohdeSchwarzHMC8012Multimeter();

//Device information
@@ -49,7 +47,7 @@ class RohdeSchwarzHMC8012Multimeter
virtual std::string GetSerial();

virtual unsigned int GetInstrumentTypes();

virtual unsigned int GetMeasurementTypes();

//Channel info
@@ -75,19 +73,6 @@ class RohdeSchwarzHMC8012Multimeter
virtual double GetCurrent();

protected:
Socket m_socket;

std::string m_hostname;
unsigned short m_port;

std::string m_vendor;
std::string m_model;
std::string m_serial;
std::string m_fwVersion;

bool SendCommand(std::string cmd);
std::string ReadReply();

MeasurementTypes m_mode;
};

Loading