Repository navigation
Expand file tree
/
Copy pathgetvolt.c
More file actions
68 lines (61 loc) · 2.25 KB
/
Copy pathgetvolt.c
File metadata and controls
68 lines (61 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//****************************************************************************
//
// Copyright 2010-18 by WinSystems Inc.
//
// Permission is hereby granted to the purchaser of WinSystems GPIO cards
// and CPU products incorporating a GPIO device, to distribute any binary
// file or files compiled using this source code directly or in any work
// derived by the user from this file. In no case may the source code,
// original or derived from this file, be distributed to any third party
// except by explicit permission of WinSystems. This file is distributed
// on an "As-is" basis and no warranty as to performance or fitness of pur-
// poses is expressed or implied. In no case shall WinSystems be liable for
// any direct or indirect loss or damage, real or consequential resulting
// from the usage of this source code. It is the user's sole responsibility
// to determine fitness for any considered purpose.
//
//****************************************************************************
//
// Name : getvolt.c
//
// Project : PCMMIO Sample Application Program
//
// Author : Paul DeMetrotion
//
//****************************************************************************
//
// Date Revision Description
// -------- -------- ---------------------------------------------
// 11/11/10 1.0 Original Release
// 10/09/12 3.0 Cleaned up
// 11/14/18 4.0 Changes due to driver enhancements
//
//****************************************************************************
#include <stdio.h>
#include <stdlib.h>
#include "mio_io.h" // Our IOCTL definitions and all function prototypes
int main(int argc, char *argv[])
{
int dev = 0;
int ch = 0;
float result;
if (argc != 3)
{
printf("\nUsage: getvolt <devnum> <channel>\n");
printf(" getvolt 0 2\n");
exit(1);
}
dev = atoi(argv[1]);
ch = atoi(argv[2]);
// We'll let the driver validate the channel number
result = adc_auto_get_channel_voltage(dev, ch);
// Check for an error
if (mio_error_code)
{
// If an error occured. Display the error and exit
printf("%s\n", mio_error_string);
exit(1);
}
// Print the results
printf(" Device %d : Channel %d = %9.4f\n", dev, ch, result);
}