1 | #include <stdio.h>
|
2 | #include <stdlib.h>
|
3 | #include <string.h>
|
4 |
|
5 | #include "usb.h"
|
6 |
|
7 | #define USB_ADC 7
|
8 | #define USB_Trans 8
|
9 |
|
10 |
|
11 | int main(int argc, char **argv) {
|
12 | usb_dev_handle *handle = NULL;
|
13 | int nBytes = 0;
|
14 | char buffer[256];
|
15 |
|
16 | if(argc < 2) {
|
17 | printf("Hello User, My Funktion are:\n");
|
18 | printf("command lowercase\n");
|
19 | printf("usbtext trans for read PINB 3\n");
|
20 | printf("usbtext adc for AD-Converter PB0\n");
|
21 | exit(1);
|
22 | }
|
23 |
|
24 | handle = usbOpenDevice(0x16C0, "codeandlife.com", 0x05DC, "USBexample");
|
25 |
|
26 | if(handle == NULL) {
|
27 | fprintf(stderr, "Could not find USB device!\n");
|
28 | exit(1);
|
29 | }
|
30 | }
|
31 | else if(strcmp(argv[1], "trans") == 0) {
|
32 | nBytes = usb_control_msg(handle,
|
33 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
|
34 | USB_Trans, 0, 0, (char *)buffer, sizeof(buffer), 5000);
|
35 | printf("Got %d bytes: %s\n", nBytes, buffer);
|
36 | }
|
37 | else if(strcmp(argv[1], "adc") == 0)
|
38 | while(1){
|
39 | //Schlechte Idee Kommst da nicht mehr raus
|
40 | {nBytes = usb_control_msg(handle,
|
41 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
|
42 | USB_ADC, 0, 0, (char *)buffer, sizeof(buffer), 5000);
|
43 |
|
44 | printf("Spannung= %s\r",buffer);
|
45 | }}
|
46 |
|
47 | else if(strcmp(argv[1], "") != 0) {
|
48 | nBytes = usb_control_msg(handle,
|
49 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
|
50 | USB_Error, 0, 0, (char *)buffer, sizeof(buffer), 5000);
|
51 | printf("wrong Command\n");
|
52 | }
|
53 |
|
54 | if(nBytes < 0)
|
55 | fprintf(stderr, "USB error: %s\n", usb_strerror());
|
56 |
|
57 | usb_close(handle);
|
58 |
|
59 | return 0;
|
60 | }
|