Serial_Talk.cpp 1.49 KB
Newer Older
Achim Morschhauser's avatar
Achim Morschhauser committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

#include <string.h>
#include <inttypes.h>
#include <stdio.h>

#include <driver_serial.hpp>


int main(){

	std::string cmd;

	int baud;

	char term[1];
	term[0]=13;

	char buf[500];

	std::cout << "BAUD: ";
	std::cin  >> baud;

Achim Morschhauser's avatar
Update    
Achim Morschhauser committed
24
	driver_serial serial = driver_serial("/dev/ttyUSB0",term,1,baud);
Achim Morschhauser's avatar
Achim Morschhauser committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38

	while (1){

		std::cout << "CMD: ";
		std::cin  >> cmd;

		//if (cmd.compare("QUIT")){
		//  break;
		//}

		cmd=cmd+(char) 13;

		serial.send((const char*) cmd.c_str());

Achim Morschhauser's avatar
Achim Morschhauser committed
39
		serial.receive(buf,sizeof(buf),5);
Achim Morschhauser's avatar
Achim Morschhauser committed
40
41
42

		std::cout << buf << std::endl;

43
		/*
Achim Morschhauser's avatar
Achim Morschhauser committed
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
69
		// Extract data from channels 1-3
		uint32_t num = (uint32_t) 0x800000L;
		uint32_t n32;
		double n;
		double M = 42.5 / 4 / (double) 0x800000;

		// Channel 1
		n32  = ( (uint32_t) ( (buf[2 ]&127) + ((buf[0]&32)<<2)) )<<16
				+ ( (uint32_t) ( (buf[3 ]&127) + ((buf[0]&16)<<3)) )<<8
				+ ( (uint32_t) ( (buf[4 ]&127) + ((buf[0]&8 )<<4)) );
		n = (double) ((int32_t) ((n32 ^ num) - num)) * M;
		printf("XYZ: %u %f\n",n32,n);

		// Channel 2
		n32  = ( (uint32_t) ( (buf[5 ]&127) + ((buf[0]&4 )<<5)) )<<16
				+ ( (uint32_t) ( (buf[6 ]&127) + ((buf[0]&2 )<<6)) )<<8
				+ ( (uint32_t) ( (buf[7 ]&127) + ((buf[0]&1 )<<7)) );
		n = (double) ((int32_t) ((n32 ^ num) - num)) * M;
		printf("XYZ: %u %f\n",n32,n);

		// Channel 3
		n32  = ((buf[8 ]&127) + ((buf[1]&32)<<2))<<16
				+ ((buf[9 ]&127) + ((buf[1]&16)<<3))<<8
				+ ((buf[10]&127) + ((buf[1]&8 )<<4));
		n = (double) ((int32_t) ((n32 ^ num) - num)) * M;
		printf("XYZ: %u %f\n",n32,n);
70
		*/
Achim Morschhauser's avatar
Achim Morschhauser committed
71
72
73
74
75

	}


}