Search code examples
clabviewieeegpib

Convert IEEE read/write from C to LabVIEW


I'm attempting to communicate with a Solartron 7060 Voltmeter through IEEE in LabVIEW. I have to convert some old C code that was originally used to communicate and cannot find a way to get out the main data from the Solartron.

Here is the C code:

#include "ieeeio.h"
#include <stdio.h>

double DATDVM(int dvmtime,int lasttime)
{
  float value;
  double Volt,volt;
  int j,response=0;

    if (lasttime!=dvmtime)
    {
      if (dvmtime<1)
      {
    if (ieeewt("clear 16\n")==-1) IEEEERR();
    if (ieeewt("abort\n")==-1) IEEEERR();
    if (ieeewt("output 16;D2F1M0R3\n")==-1) IEEEERR();
      }
      else
      {
    if (ieeewt("clear 16\n")==-1) IEEEERR();
    if (ieeewt("abort\n")==-1)  IEEEERR();
    if (ieeewt("output 16;D3F1M0R3\n")==-1)  IEEEERR();
      }
    }
    if (dvmtime<1)
    {
      if (ieeewt("abort\n")==-1)  IEEEERR();
      if (ieeewt("output 16;G\n")==-1)  IEEEERR();
      while (response != 24)
      {
    delay(50);
    if (ieeewt("spoll 16\n")==-1)  IEEEERR();
    if (ieeescnf("%d",&response)==-1) IEEEERR();
      }
      response=0;
      if (ieeewt("enter 16\n")==-1) IEEEERR();
      if (ieeescnf("%*5s%e",&value)==-1) IEEEERR();
      Volt=value;
    }
    else
    {
      volt=0;
      for (j=0; j<dvmtime; j++)
      {
    if (ieeewt("abort\n")==-1) IEEEERR();
    if (ieeewt("output 16;G\n")==-1) IEEEERR();
    while (response != 24)
    {
       delay(50);
       if (ieeewt("spoll 16\n")==-1) IEEEERR();
       if (ieeescnf("%d",&response)==-1) IEEEERR();
    }
    response=0;
    if (ieeewt("enter 16\n")==-1) IEEEERR();
    if (ieeescnf("%*5s%e",&value)==-1) IEEEERR();
    volt+=value;
      }
      Volt=volt/dvmtime;
    }
    return(Volt);
}

This code is sampling a DC voltage (from a faraday detector on an old mass spectrometer detected by an electrometer) at some integration time dvmtime in seconds. So as to tell the 7060 DVM to take a reading volt for a set integration time Dvmtime.

I have tried the following LabVIEW code, part of which I took from the .vi that controls a Solartron 7061 multimeter. In this code I'm sending D3F1MOR3, that comes from the ieeewt functions in the first block of the C code. However, I'm having trouble finding a function that is equivalent to ieeescnf in LabVIEW.

The first time I run the .vi it returns the correct voltage reading, then it returns 0 on the second run, and a large number on the third run. Also, the time it takes to run each varies substantially.

Any help would be appreciated, as I'm not sure exactly what this C code is doing at every stage.

LabVIEW .vi that I have tried so far


Solution

  • ieeescnf() seems to be a read GPIB + scAnf() function, GPIB read should do the job.

    You may want to take a look at the ScanFromString and the FormatIntoString function - LabVIEW format string differs from C:

    https://zone.ni.com/reference/en-XX/help/371361R-01/glang/scan_from_string/

    https://zone.ni.com/reference/en-XX/help/371361R-01/glang/format_into_string/

    Taking a look at the LabVIEW GPIB documentation, you do not seems to be using the correct terminaison mode. '\n' terminaison in ieeewt should correspond to write mode 2 or 5, assuming your C library does not append additional characters :

    http://zone.ni.com/reference/en-XX/help/371361R-01/lvinstio/gpib_write/

    When poking not-yet-correctly-handled devices, it's perfectly normal to have variable responses times. Don't forget to reset your voltmeter between probing it with test commands, as errors may be carried over.