Linux Beispiele für USB_GPIB_1

Um USB_GPIB_1 unter Linux ansprechen zu können, ist einerseits ein Kernel Modul und andererseits die QLIB vonnöten. Das Kernel Modul stellt nur die absolut notwendige Kommunikationschicht zur Verfügung, die QLIB hingegen macht die eigentliche Arbeit.

Installation

Nachdem man sich das Linux Archiv (in unserem Beispiel quancom_usb-1.2.0.tar.gz) runtergeladen hat, muss man es auspacken

>>tar xvzf quancom_usb-1.2.0.tar.gz

Nachdem man in das entstandene Verzeichnis gewechselt ist geht es weiter mit dem Kernel Modul. Danach muss man die QLIB bauen.

Befehle

Folgende Befehle sind unter Linux verfügbar:

Die Verwendung illustriert folgendes Programm. Ein etwas ausführlicheres Demoprogramm findet sich im Treiberarchiv.

 

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "qlib.h"

int main(int argc, char* argv[])
{
	
	ULONG result;
	ULONG listener;
	ULONG talker;
	ULONG i;

	char buffer[1024];	

	// The following sequence tries to find the
	// Bus Type ( PCI, ISA or USB ) of the 
	// installed GPIB Controller
	
	ULONG handle = QAPIExtOpenCard(USBGPIB,0);
	// The handle is != NULL if there is a GPIB Controller installed
	
	if ( handle == 0 )
		{				
			printf("No QUANCOM GPIB Controller found!\n");
			return FALSE;
		}

	// Ok, we found a QUANCOM GPIB Controller Card

	// ---------------------------------------------------------------------------
	// PART 0: Resetting the controller and the internal flags
	//
	// The following command clears the internal driver flags and resets
	// the GPIB chip. The function resets the controller to its internal
	// default state and issues an IFC ( interface clear command ). Additionally
	// the function test for the presence of the GPIB Controller.
	// ---------------------------------------------------------------------------

	result = QAPIExtSpecial(handle, JOB_RESET, 1, 0);

	if (result)
		{
			printf("RESET Controller\n");
		}			
	else
		{

			// This function only fails when: 
			//
			// PCI - Never
			// ISA - Wrong I/O Address or GPIB Card not installed
			// USB - Unplugged USB Module
			//

			printf("RESET Failed ( Card or Module not present ? )\n");
		}			
		

	// Now we can send a string to the listner with address 1
	// Change the address to the appropriate address for your
	// device ( normally set by DIP-Switches on the back side )

	// ---------------------------------------------------------------------------
	// PART 1a: Writing a string to the DMM ( The DMM is a the listener )
	//
	// Listener: A device capable of receiving data over the interface 
	// when addressed to Listen by the active controller. Examples of such 
	// devices are printers, programmable power supplies, or any other 
	// programmable instrument. There can be up to 14 Listeners on the GPIB Bus
	// at one time. 
	// ---------------------------------------------------------------------------

	// Select the listener address, which is set by a DIP-Switch on the 
	// back side of your instrument. 

	listener = 1; 

	// Send "z" to the listner 1, which resets the DMM to the initial settings.


	result = QAPIExtSpecial(handle, JOB_REN, FALSE, 0);
		
	if (result)
		{
			printf("Disabling REN line\n");
		}			


	result = QAPIExtSpecial(handle, JOB_REN, TRUE, 0);
		
	if (result)
		{
			printf("Enabling REN line\n");
		}			


	result = QAPIExtSpecial(handle, JOB_TIMEOUT, 10000, 0);
		
	if (result)
		{
			printf("Timeout=10000\n");
		}			



	char s1[] = "*IDN?"; 
//	char s1[] = "CURSor:HBArs?"; 

	if ( QAPIExtWriteString(handle, listener, (char*)&s1, strlen(s1),0))
		{
			printf("Writing to device %u was successful\n", listener);
		}
	else
		{
			printf("Writing to device %u failed\n", listener);
		}

	
	// ---------------------------------------------------------------------------
	// PART 1b: Reading a DMM ( The DMM is a talker )
	//
	// Talker: A device capable of transmitting data over the interface when 
	// addressed to talk by the active controller. Examples of such devices 
	// are voltmeters, data-acquisition systems, or any other programmable 
	// instrument. There can be only one addressed talker on the GPIB Bus at one 
	// time. 
	// ---------------------------------------------------------------------------
	
    // clear buffer

    memset((void *) &buffer, 0, sizeof(buffer));
    
	// Select the talker address, which is set by a DIP-Switch on the 
	// back side of your instrument. 

	talker = 1; 

	// Read value from DMM with talker address 3

	result = QAPIExtReadString(handle, talker, (char*)&buffer, sizeof(buffer), 0);
		
	if (result)
		{
			printf("Reading from device %u was: %s\n",talker, buffer);
		}			
	else
		{
			printf("Reading from device %u failed\n", talker);
		}	

	// ---------------------------------------------------------------------------
	// PART 6: Tests with a oscilloscope as device 1
	// ---------------------------------------------------------------------------

	// ---------------------------------------------------------------------------
	// PART 6a: switch cursor off
	// ---------------------------------------------------------------------------	

    char s4[] = "CURSor:FUNCtion OFF";
	listener = 1; 

	if ( QAPIExtWriteString(handle, listener, (char*)&s4, strlen(s4),0))
		{
            printf("Cursor switched off, press return\n");
            getchar();
		}
	else
		{
			printf("6a: Writing to device %u failed\n", listener);
		}


	// ---------------------------------------------------------------------------
	// PART 6b: switch cursor pair back on
	// ---------------------------------------------------------------------------	

    char s5[] = "CURSor:FUNC PAIR";

	if ( QAPIExtWriteString(handle, listener, (char*)&s5, strlen(s5),0))
		{
            printf("Cursor pair switched on, press return\n");
            getchar();
		}
	else
		{
			printf("6b: Writing to device %u failed\n", listener);
		}

	// ---------------------------------------------------------------------------
	// PART 6c: get cursor position
	// ---------------------------------------------------------------------------	

    char s6[] = "CURSor:HBArs?";

	if (!QAPIExtWriteString(handle, listener, (char*)&s6, strlen(s6),0)) {
			printf("6c: Writing to device %u failed\n", listener);
    } else {

        // clear buffer

        memset((void *) &buffer, 0, sizeof(buffer));

        // Select the talker address, which is set by a DIP-Switch on the 
        // back side of your instrument. 

        talker = 1; 

        // Read value from DMM with talker address 3

        result = QAPIExtReadString(handle, talker, (char*)&buffer, sizeof(buffer), 0);

        if (result) {
            printf("Reading from device %u was: %s\n",talker, buffer);
        } else {
            printf("6c: Reading from device %u failed\n", talker);
        }		
    }



	// ---------------------------------------------------------------------------
	// PART 7: Close the Card
	// ---------------------------------------------------------------------------	


    printf("\nPress return key to exit.\n");
    getchar();

	QAPIExtCloseCard(handle); 


	return 0;
}