| |
// To use the QLIB Commands in your source, do the following:
//
// (1) Install the PCI driver
// (2) Add file "qlib.c" to your makefile.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include "../qlib/qlib.h"
#include <sys/select.h>
int kbhit(void)
{
struct timeval tv;
fd_set read_fd;
/* Do not wait at all, not even a microsecond */
tv.tv_sec=0;
tv.tv_usec=0;
/* Must be done first to initialize read_fd */
FD_ZERO(&read_fd);
/* Makes select() ask if input is ready:
* 0 is the file descriptor for stdin */
FD_SET(0,&read_fd);
/* The first parameter is the number of the
* largest file descriptor to check + 1. */
if(select(1, &read_fd, NULL, NULL, &tv) == -1)
return 0; /* An error occured */
/* read_fd now holds a bit map of files that are
* readable. We test the entry for the standard
* input (file 0). */
if(FD_ISSET(0,&read_fd))
/* Character pending on stdin */
return 1;
/* no characters were pending */
return 0;
}
int main(int argc, char **argv)
{
ULONG handle;
char ch;
int j;
//
// This sample works for USBOPTOREL32 and USBOPTOIO32 Modules
//
//
// Open the USB Module
//
handle = QAPIExtOpenCard(PCITTL32,0);
//
// If there are no modules terminate application
//
if ( handle == 0 )
{
printf("No PCITTL32 found or device permissions wrong!\n");
return FALSE;
}
// Ok, we found a QUANCOM Module
// ---------------------------------------------------------------------------
// PART 1: Setting the outputs
//
// The following constants can be used to program the outputs:
// ---------------------------------------------------------------------------
#define OUT1 0x1
#define OUT2 0x2
#define OUT3 0x4
#define OUT4 0x8
#define OUT5 0x10
#define OUT6 0x20
#define OUT7 0x40
#define OUT8 0x80
#define OUT9 0x100
#define OUT10 0x200
#define OUT11 0x400
#define OUT12 0x800
#define OUT13 0x1000
#define OUT14 0x2000
#define OUT15 0x4000
#define OUT16 0x8000
#define OUT17 0x10000
#define OUT18 0x20000
#define OUT19 0x40000
#define OUT20 0x80000
#define OUT21 0x100000
#define OUT22 0x200000
#define OUT23 0x400000
#define OUT24 0x800000
#define OUT25 0x1000000
#define OUT26 0x2000000
#define OUT27 0x4000000
#define OUT28 0x8000000
#define OUT29 0x10000000
#define OUT30 0x20000000
#define OUT31 0x40000000
#define OUT32 0x80000000
ULONG lines = 0;
//
// switching all DX to ouput
//
QAPIExtSpecial(handle, JOB_WRITE_DDR, 0x0fL, 0);
//
// Reset all lines to "Low"
//
printf("Reset all lines to 'Low' ( Press return to continue ):\n");
QAPIExtWriteDO32(handle, 0, lines, 0);
ch = getchar();
//
// Set the outputs OUT4,OUT10 and OUT15 to "High" ( 16-Bit )
//
printf("Set OUT4,OUT10,OUT15 and OUT30 to 'High' ( Press return to continue ):\n");
lines = OUT4 + OUT10 + OUT15 + OUT30;
QAPIExtWriteDO32(handle, 0, lines, 0);
ch = getchar();
//
// Set the output OUT1, OUT4,OUT10 and OUT15 to "High" ( 16-Bit )
//
printf("Set OUT1, OUT4,OUT10 and OUT15 to 'High' ( Press return to continue ):\n");
lines = OUT1 + OUT4 + OUT10 + OUT15;
QAPIExtWriteDO32(handle, 0, lines, 0);
ch = getchar();
//
// Reset line OUT10 to "Low"
//
printf("Reset line OUT10 to 'Low' ( Press return to continue ):\n");
QAPIExtWriteDO1(handle, 10 - 1, FALSE, 0);
ch = getchar();
//
// Set line OUT5 to "High"
//
printf("Set line OUT5 to 'High' ( Press return to continue ):\n");
QAPIExtWriteDO1(handle, 5 - 1, TRUE, 0);
ch = getchar();
//
// Reset all lines to "Low"
//
printf("Reset all to 'Low' ( Press return to continue ):\n");
lines = 0;
QAPIExtWriteDO32(handle, 0, lines, 0);
ch = getchar();
// ---------------------------------------------------------------------------
// PART 2: Reading the inputs
//
// This part reads the state of the input lines.
//
// The following constants can be used to program the inputs:
// ---------------------------------------------------------------------------
//
// switching all DX to input
//
QAPIExtSpecial(handle, JOB_WRITE_DDR, 0x00L, 0);
int i;
while (!kbhit())
{
// read the current state from the inputs
lines = QAPIExtReadDI32(handle, 0, 0);
printf("\n--------------------------------------------------------------------------------\n");
printf("Current input states\n");
printf("IN1 IN2 IN3 IN4 IN5 IN6 IN7 IN8 IN9 IN10 IN11 IN12 IN13 IN14 IN15 IN16\n");
for (i=0;i<16;i++)
{
if ( lines & 1<<i)
{
printf(" 1 ");
}
else
{
printf(" 0 ");
}
}
printf("IN17 IN18 IN19 IN20 IN21 IN22 IN23 IN24 IN25 IN26 IN27 IN28 IN29 IN30 IN31 IN32\n");
for (i=16;i<32;i++)
{
if ( lines & 1<<i)
{
printf(" 1 ");
}
else
{
printf(" 0 ");
}
}
printf("\n--------------------------------------------------------------------------------\n");
printf("Press return to stop reading the inputs every 5 seconds ...\n");
for (j=0;(j<5) && !kbhit();j++)
{
sleep(1);
}
}
ch = getchar();
QAPIExtCloseCard(handle);
return 0;
}
|
|