GEN DAQ API  4.0
Controlling GEN Series tethered Mainframes
examples/timebase.c
/*
* Copyright (C) 2009 HBM Netherlands B.V.
* Schutweg 15a
* 5145 NP Waalwijk
* The Netherlands
* http://www.hbm.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "GEN_DAQ_API.h"
static void confirm_close(void);
static const char *continuousModeToString(GHSContinuousRecordingMode);
static const char *sweepModeToString(GHSSweepRecordingMode);
static void terminate(const char *format, ...);
int main(void)
{
char* ipaddress = "192.168.1.1";
unsigned short portno = 8006;
GHSConnectionHandle connection = 0;
GHSReturnValue returnCode;
uint32_t serverAPIVersion;
GHSSlotID slotID = 'A';
int64_t sweepLength;
int sweepCount;
double triggerPosition, timeSpan, leadOutTime;
printf("Connecting to %s:%u\n", ipaddress, portno);
/* Connect to the mainframe "localhost" is also possible. */
returnCode = GHSConnect(ipaddress, portno, &connection, &serverAPIVersion);
if (returnCode == GHSReturnValue_APIMismatch)
{
terminate("Failed: client has API version %u, while mainframe has API version %u.\n",
GHSGetClientAPIVersion(), serverAPIVersion);
}
else if (returnCode != GHSReturnValue_OK)
{
terminate("Failed: return code is %d.\n", returnCode);
}
printf("Connected\n");
/* Get sweep mode. */
returnCode = GHSGetSweepRecordingMode(connection, slotID, &recordingMode);
if (returnCode != GHSReturnValue_OK)
{
terminate("Failed on GHSGetSweepRecordingMode: return code is %d.\n", returnCode);
}
/* Set sweep mode. */
returnCode = GHSSetSweepRecordingMode(connection, slotID, recordingMode);
if (returnCode != GHSReturnValue_OK)
{
terminate("Failed on GHSSetSweepRecordingMode: return code is %d.\n", returnCode);
}
/* Get sweep length. */
returnCode = GHSGetSweepLength(connection, slotID, &sweepLength);
if (returnCode != GHSReturnValue_OK)
{
terminate("Failed on GHSGetSweepLength: return code is %d.\n", returnCode);
}
/* Set sweep length. */
returnCode = GHSSetSweepLength(connection, slotID, sweepLength);
if (returnCode != GHSReturnValue_OK)
{
terminate("Failed on GHSSetSweepLength: return code is %d.\n", returnCode);
}
/* Get number of sweeps. */
returnCode = GHSGetNumberOfSweeps(connection, slotID, &sweepCount);
if (returnCode != GHSReturnValue_OK)
{
terminate("Failed on GHSGetNumberOfSweeps: return code is %d.\n", returnCode);
}
/* Set number of sweeps. */
returnCode = GHSSetNumberOfSweeps(connection, slotID, sweepCount);
if (returnCode != GHSReturnValue_OK)
{
terminate("Failed on GHSSetNumberOfSweeps: return code is %d.\n", returnCode);
}
/* Get trigger position. */
returnCode = GHSGetTriggerPosition(connection, slotID, &triggerPosition);
if (returnCode != GHSReturnValue_OK)
{
terminate("Failed on GHSGetTriggerPosition: return code is %d.\n", returnCode);
}
/* Set trigger position. */
returnCode = GHSSetTriggerPosition(connection, slotID, triggerPosition);
if (returnCode != GHSReturnValue_OK)
{
terminate("Failed on GHSSetTriggerPosition: return code is %d.\n", returnCode);
}
/* Show sweep settings. */
printf("\nSweep Settings:\n");
printf("Mode: %s\n", sweepModeToString(recordingMode));
printf("Length: %ld\n", (long)sweepLength);
printf("Number of sweeps: %d\n", sweepCount);
printf("Trigger position (%%): %.2f\n", triggerPosition);
/* Get continuous mode. */
returnCode = GHSGetContinuousRecordingMode(connection, slotID, &continuousMode);
if (returnCode != GHSReturnValue_OK)
{
terminate("Failed on GHSGetContinuousRecordingMode: return code is %d.\n", returnCode);
}
/* Set continuous mode. */
returnCode = GHSSetContinuousRecordingMode(connection, slotID, continuousMode);
if (returnCode != GHSReturnValue_OK)
{
terminate("Failed on GHSSetContinuousRecordingMode: return code is %d.\n", returnCode);
}
/* Get time span. */
returnCode = GHSGetContinuousTimeSpan(connection, slotID, &timeSpan);
if (returnCode != GHSReturnValue_OK)
{
terminate("Failed on GHSGetContinuousTimeSpan: return code is %d.\n", returnCode);
}
/* Set time span. */
returnCode = GHSSetContinuousTimeSpan(connection, slotID, timeSpan);
if (returnCode != GHSReturnValue_OK)
{
terminate("Failed on GHSSetContinuousTimeSpan: return code is %d.\n", returnCode);
}
/* Get lead out time. */
returnCode = GHSGetContinuousLeadOutTime(connection, slotID, &leadOutTime);
if (returnCode != GHSReturnValue_OK)
{
terminate("Failed on GHSGetContinuousLeadOutTime: return code is %d.\n", returnCode);
}
/* Set lead out time. */
returnCode = GHSSetContinuousLeadOutTime(connection, slotID, leadOutTime);
if (returnCode != GHSReturnValue_OK)
{
terminate("Failed on GHSSetContinuousLeadOutTime: return code is %d.\n", returnCode);
}
/* Show continuous settings. */
printf("\nContinuous Settings:\n");
printf("Mode: %s\n", continuousModeToString(continuousMode));
printf("Time span (in seconds): %.2f\n", timeSpan);
printf("Lead out time (in seconds): %.2f\n", leadOutTime);
/* Disconnect from the mainframe (this enables Perception or another GHS API client to connect). */
returnCode = GHSDisconnect(connection);
if (returnCode != GHSReturnValue_OK)
{
terminate("Failed on GHSDisconnect: return code is %d.\n", returnCode);
}
printf("Disconnected\n");
confirm_close();
return EXIT_SUCCESS;
}
void confirm_close(void)
{
printf("Press ENTER to close this example program.\n");
(void)getchar();
}
const char *continuousModeToString(GHSContinuousRecordingMode mode)
{
switch(mode)
{
case GHSContinuousRecordingMode_Reserved: return "Reserved";
case GHSContinuousRecordingMode_Standard: return "Standard";
case GHSContinuousRecordingMode_Circular: return "Circular";
case GHSContinuousRecordingMode_Limited: return "Limited";
case GHSContinuousRecordingMode_StopOnTrigger: return "StopOnTrigger";
default: return "INVALID";
}
}
const char *sweepModeToString(GHSSweepRecordingMode mode)
{
switch(mode)
{
case GHSSweepMode_Reserved: return "Reserved";
case GHSSweepMode_Normal: return "Normal";
case GHSSweepMode_PreTrigger: return "PreTrigger";
default: return "INVALID";
}
}
void terminate(const char *format, ...)
{
va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);
confirm_close();
exit(EXIT_FAILURE);
}