/* * hp8753_test.c - simple test program for the HP8753 Network Analyzer * using the Linux gpib library * * Copyright 2008 Joop Stakenborg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ #include #include #include #include #define BOARD_INDEX 0 #define PRIMARY_ADDRESS 16 #define SECONDARY_ADDRESS 0 #define TIMEOUT T3s #define SEND_EOI 0 #define EOSMODE 1 /* * convert the global iberr (error) bits into a readable form */ void errstr (const int err) { if (iberr == EBUS) fprintf (stderr, "An attempt to write command bytes to the bus has timed out\n"); else if (iberr == EARG) fprintf (stderr, "One or more arguments to the function call were invalid\n"); else if (iberr == EABO) fprintf (stderr, "A read or write of data bytes has been aborted, possibly due to a timeout or reception of a device clear command\n"); else fprintf (stderr, "iberr = %d\n", iberr); } /* * convert the global ibsta (status) bits into a readable form */ void verbose_error (const int errcode) { fprintf (stderr, "Function returned %d\n", ibsta); if (errcode & ERR) { fprintf (stderr, "Function call failed\n"); errstr (iberr); } if (errcode & TIMO) { fprintf (stderr, "Last io operation timed out\n"); } if (errcode & END) { fprintf (stderr, "END\n"); } if (errcode & SRQI) { fprintf (stderr, "SRQI\n"); } if (errcode & RQS) { fprintf (stderr, "RQS\n"); } if (errcode & SPOLL) { fprintf (stderr, "SPOLL\n"); } if (errcode & EVENT) { fprintf (stderr, "EVEN\n"); } if (errcode & CMPL) { fprintf (stderr, "I/O operation is complete\n"); } if (errcode & LOK) { fprintf (stderr, "LOK\n"); } if (errcode & REM) { fprintf (stderr, "REM\n"); } if (errcode & CIC) { fprintf (stderr, "CIC\n"); } if (errcode & ATN) { fprintf (stderr, "ATN\n"); } if (errcode & TACS) { fprintf (stderr, "TACS\n"); } if (errcode & LACS) { fprintf (stderr, "LACS\n"); } if (errcode & DTAS) { fprintf (stderr, "DTAS\n"); } if (errcode & DCAS) { fprintf (stderr, "DCAS\n"); } } /* * this example program opens the network analyzer as a device, * then clears it, sets a marker at 1 GHZ and reads it's values * settings used in /etc/gpib.conf: * * eos = 0x0a * set-reos = yes * */ int main (int argc, char **argv) { int device, result; double ampl; char buffer[256], *p; /* gpib is the name of the board in /etc/gpib.conf */ device = ibfind("gpib"); printf ("Clearing the interface... "); result = ibsic (device); if (result & ERR) { printf ("Failed!\n"); fprintf (stderr, "Exiting, errorcode: %d\n", iberr); exit (1); } printf ("Success!\n"); printf ("Opening handle to network analyzer... "); device = ibdev (BOARD_INDEX, PRIMARY_ADDRESS, SECONDARY_ADDRESS, TIMEOUT, SEND_EOI, EOSMODE); if (device == -1) { printf ("Failed!\n"); printf ("Do you have device permissions?\n"); exit (1); } printf ("Success!\n"); printf ("Device preset... "); result = ibwrt (device, "PRES;", 5); if (result & ERR) { printf ("Failed!\n"); verbose_error (result); exit (1); } printf ("Success!\n"); /* set marker at 1 GHz and read it's values */ printf ("Set marker to 1 GHz... "); result = ibwrt (device, "MARK1 1 GHZ;", 12); if (result & ERR) { printf ("Failed!\n"); verbose_error (result); exit (1); } printf ("Success!\n"); printf ("Set read marker... "); result = ibwrt (device, "OUTPMARK;", 9); if (result & ERR) { printf ("Failed!\n"); verbose_error (result); exit (1); } printf ("Success!\n"); printf ("Reading marker values... "); result = ibrd (device, buffer, 256); if (result & ERR) { printf ("Failed!\n"); verbose_error (result); exit (1); } printf ("Success!\n"); p = strchr (buffer, '\n'); *p = '\0'; printf ("values: %s\n", buffer); /* convert to float */ p = strchr (buffer, ','); ampl = strtod (buffer, &p); printf ("amplitude: %f\n", ampl); printf ("Closing device... "); result = ibonl(device, 1); if (result & ERR) { printf ("Failed!\n"); verbose_error (result); exit (1); } printf ("Success!\n"); exit (0); }