2
* Testprogram to communicate with the camera.
4
* test.exe <PropertyName> <Value> #communicate on default port 0
5
* test.exe <Port> <PropertyName> <Value> #communicate on port Port
7
* test.exe #List all properties of port 0
8
* test.exe Window.X #Get value of Property Window.X on port 0
9
* test.exe Window.X 100 #Set value of Property Window.X to 100 on port 0
11
* test.exe 1 #List all properties of port 1
12
* test.exe 1 Window.X #Get value of Property Window.X on port 1
13
* test.exe 1 Window.X 100 #Set value of Property Window.X to 100 on port 1
15
* test.exe 3 #List all properties of port 3
16
* test.exe 3 Window.Y #Get value of Property Window.Y on port 3
17
* test.exe 3 Window.Y 150 #Set value of Property Window.Y to 150 on port 3
19
* if the first argument is not a number, the communication is opened over default port 0
21
* if the first argument is a number, the communication is opend over given port number
31
void list_children(int port, TOKEN t);
32
void print_type(int port, TOKEN t);
33
////////////////////////////////////////////////////////////////////////////
34
int handleError(error)
38
s = pfGetErrorString(error);
40
printf("Error: %s\n", s);
42
printf("Warning: %s\n", s);
47
void list_children(int port, TOKEN t)
50
child = pfProperty_Select(port, t, t);
52
printf("Has Child: '%s'\n", pfProperty_GetName(port, child));
53
child = pfProperty_Select(port, t, child); // iterate to next
57
static unsigned char *g_types[] = {
58
(unsigned char*)"Invalid value",
59
(unsigned char*)"ROOT NODE",
60
(unsigned char*)"Integer",
61
(unsigned char*)"Float",
62
(unsigned char*)"Boolean",
63
(unsigned char*)"Mode",
64
(unsigned char*)"Register",
65
(unsigned char*)"String",
66
(unsigned char*)"Buffer",
67
(unsigned char*)"{Struct}",
68
(unsigned char*)"{Array}",
69
(unsigned char*)"[Command]",
70
(unsigned char*)"[Event]"
73
void print_type(int port, TOKEN t)
75
printf("Type : %s\n", g_types[pfProperty_GetType(port, t)]);
78
static char s_line[] = "----------------------------------------------\n";
80
int main(int argc, char **argv)
84
char name[50], manu[50];
87
int port, offset, arg;
88
int numOfPorts, mBytes, nBytes, version, type;
94
//Init PFLib, get number of available port
95
pfPortInit(&numOfPorts);
96
printf("Number of Ports: %d\n", numOfPorts);
99
for(i=0; i<numOfPorts; i++){
100
pfPortInfo(i, manu, &mBytes, name, &nBytes, &version, &type);
101
printf("Port %d: Manufacturer: %s, %s", i, manu, name);
102
printf(", mBytes %d, nBytes %d, ver. %d, type %d\n", mBytes, nBytes, version, type);
106
//Check if not default port, means "test.exe 5 " -> port 5
108
arg = strtoul(argv[1], &tmp, 10);
112
if(port >= numOfPorts){
118
//show info about port to open
119
pfPortInfo(port, manu, &mBytes, name, &nBytes, &version, &type);
120
printf("Opening camera on port: Port %d: %s, %s...\n", port, manu, name);
123
error = pfDeviceOpen(port);
132
printf("Device opened \n");
134
//Check if higher baud rate is supported
135
error = pfIsBaudRateSupported(port, 115200);
137
error = pfSetBaudRate(port, 115200);
145
error = pfIsBaudRateSupported(port, 57600);
147
error = pfSetBaudRate(port, 57600);
155
printf("%s", s_line);
157
if(argc >= (2+offset)){//get or set value
158
//parse propertyname to token
159
t = pfProperty_ParseName(port, argv[1+offset]);
160
if(t == INVALID_TOKEN) {
161
printf("Property not found or bad index\n");
169
if(argc == 2+offset){//get property
170
list_children(port, t);
172
error = pfDevice_GetProperty_String(port, t, data, 64);
181
printf("Value: %s\n", data);
183
else if(argc == 3+offset){//Set property
184
error = pfDevice_SetProperty_String(port, t, argv[2+offset]);
194
fprintf(stderr, "Wrong number of arguments\n");
197
else{//list properties
198
root = pfDevice_GetRoot(port);
199
list_children(port, root);