/* C-Language "Hello World" example for the Crandun Technologies CTI-AR4000 software library. Copyright (c) 2001, Crandun Technologies Inc. */ #include "CTI_AR4000.h" /* required header */ #include #define MAXSAMPLES 20 int main() { char c; long i; long rc; float rangeData[MAXSAMPLES]; long numSkipped; long sensorHandle; printf("Crandun Technologies CTI-AR4000 Library 'Hello World' example.\n"); sensorHandle = -1; sensorHandle = getNewCTIAR4000(); if (sensorHandle < 0) { printf("ERROR: getNewCTIAR4000 returned error code %ld\n", sensorHandle); printf("Please enter any character to exit: "); \ scanf("%c", &c); \ return -1; } rc = setCommOpen(sensorHandle, "COM1:", 9600); if (rc != CTI_SUCCESS) { printf("ERROR: setCommOpen returned error: %ld\n", rc); printf("Please enter any character to exit: "); \ scanf("%c", &c); \ return -1; } rc = getSamples(sensorHandle, rangeData, MAXSAMPLES, 10); if (rc < 0) { printf("ERROR: getSamples returned error: %ld", rc); setCommClosed(sensorHandle); printf("Please enter any character to exit: "); \ scanf("%c", &c); \ return -1; } printf("Read %ld range samples from the sensor.\n", rc); for (i = 0; i < rc; i++) printf("Range %d is %8.3f inches\n", i, rangeData[i]); numSkipped = getNumBytesSkipped(sensorHandle); printf("%ld bytes of data were skipped.\n", numSkipped); setCommClosed(sensorHandle); printf("Please enter any character to exit: "); \ scanf("%c", &c); \ return 0; }