-
Notifications
You must be signed in to change notification settings - Fork 0
/
RS232communicationMain.cpp
74 lines (48 loc) · 1.63 KB
/
RS232communicationMain.cpp
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
69
70
71
72
73
74
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "RS232communication.h"
#include "/home/xytable/src/XYTable/MotorControl.h"
using namespace std;
int main(){
char output[80];
unsigned char Address, Status;
int Value;
int Motor_handle;
bool verbosity=true;
//Motor_handle = OpenRS232_dev("/dev/ttyS4", 9600); // Baudrate=9600 is defined in RS232communication.hpp, this parameter has no effect
Motor_handle = OpenRS232(5, 9600);
cout << Motor_handle << endl;
if (Motor_handle >= 0){
bool connected = true;
SendCmd(Motor_handle, 1, TMCL_GAP, 0, 0, 0); // just try to speak with motor, used GAP to not change the position
sleep(1);
Address = 0; Status = 0; Value = 0;
//if (GetResult(Motor_handle[a], &Address, &Status, &Value)==TMCL_RESULT_OK) break;
GetResult(Motor_handle, &Address, &Status, &Value);
if (verbosity) cout << "errno = " << errno << ":\t" << strerror(errno) << endl;
if (errno != 0 ){
connected = false;
if (verbosity) cout << "com device did not respond" << endl;
}
else{
cout << Motor_handle << " ok" << endl;
}
}
//int comhandle = OpenRS232(4, 9600);
int comhandle = open ("/dev/ttyS4", O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
//write (comhandle, "hallo", 5);
//sleep (2);
//read (comhandle, output, 5);
cout << comhandle << endl;
close(comhandle);
return 0;
}