-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
459 lines (398 loc) · 16.7 KB
/
Program.cs
File metadata and controls
459 lines (398 loc) · 16.7 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
using System;
using System.Collections.Generic;
using System.Threading;
using TigerStopAPI;
namespace TigerStopSDKExample
{
class Program
{
static TigerStopAPI.TigerStop_IO io;
static void Main(string[] args)
{
Console.WriteLine("Ready to connect....");
Thread.Sleep(2000);
Start:
Console.Write("(1) Enter Comport and Baudrate\n(2) Search for Available Connections\n(3) Exit\nSELECT OPTION : ");
string input = Console.ReadLine();
try
{
switch (input)
{
case "1":
string comport;
int baud;
Console.Write("Enter Comport : ");
comport = Console.ReadLine().ToUpper();
Console.Write("Enter Baudrate : ");
baud = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Connecting to " + comport + "....");
io = new TigerStopAPI.TigerStop_IO(comport, baud);
if (io.IsOpen)
{
Console.WriteLine("Successfully connected.");
goto MainLoop;
}
else
{
Console.WriteLine("Connection failed.");
goto Start;
}
case "2":
Console.WriteLine("Searching....");
List<KeyValuePair<string, int>> con = new List<KeyValuePair<string, int>>();
con = TigerStopAPI.TigerStop_IO.Connections();
if (con.Count > 0)
{
foreach (KeyValuePair<string, int> c in con)
{
Console.WriteLine("Comport : " + c.Key + " | Baudrate : " + c.Value);
}
}
else
{
Console.WriteLine("No connections were found.");
}
goto Start;
case "3":
goto Exit;
default:
Console.WriteLine("Invalid Option.");
goto Start;
}
}
catch
{
Console.WriteLine("Error Occurred.");
goto Start;
}
MainLoop:
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("==================================================");
Console.WriteLine(" -READY- ");
Console.WriteLine("==================================================");
while (true)
{
if (InputHandler())
{
break;
}
}
Exit:
Console.WriteLine("Exiting....");
Thread.Sleep(3000);
Environment.Exit(0);
}
public static bool InputHandler()
{
bool exit = true;
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("Enter Command : ");
string[] input = Console.ReadLine().Split(' ');
Console.ForegroundColor = ConsoleColor.Red;
switch (input[0])
{
case "Exit":
case "EXIT":
case "exit":
case "x":
case "X":
exit = true;
break;
case "Move":
case "MOVE":
case "move":
case "m":
case "M":
if (io.MoveTo(input[1]))
{
Console.WriteLine("Move Successful");
}
else
{
Console.WriteLine("Move Unsuccessful");
}
exit = false;
break;
case "Cycle":
case "CYCLE":
case "cycle":
case "c":
case "C":
if (io.CycleTool())
{
Console.WriteLine("Cycle Successful");
}
else
{
Console.WriteLine("Cycle Unsuccessful");
}
exit = false;
break;
case "Help":
case "HELP":
case "help":
case "h":
case "H":
Console.WriteLine("==================================================\n" +
" -HELP- \n" +
"==================================================\n" +
"Move : Moves the machine to the desired position.\n" +
" - Move [position] | move [position] | MOVE [position] | M [position] | m [position] \n" +
"\n" +
"Cycle : Cycles the tool of the machine.\n" +
" - Cycle | cycle | CYCLE | c | C \n" +
"\n" +
"Home : Homes the machine, returning to the home position.\n" +
" - Home | home | HOME | hm | HM \n" +
"\n" +
"Min-max : Finds end sensors to determine working length.\n" +
" - FEL | fel | MIN-MAX | min-max | MINMAX | minmax | mm | MM \n" +
"\n" +
"Sleep : Sets the drive to sleep.\n" +
" - Sleep | sleep | SLEEP | sl | SL \n" +
"\n" +
"Wake Up : Wakes the drive from sleep.\n" +
" - Wake | wake | WAKE | w | W \n" +
"\n" +
"Analog : Returns the analog values tracked by the amp.\n" +
" - Analog | analog | ANALOG | a | A \n" +
" - Analog [1-5] | analog [1-5] | ANALOG [1-5] | a [1-5] | A [1-5] \n" +
"\n" +
"Log : Returns the log of commands and errors tracked be the amp.\n" +
" - Log | log | LOG | l | L \n" +
" - Log [index] | log [index] | LOG [index] | l [index] | L [index] \n" +
"\n" +
"Counters : Returns the counter values tracked by the amp.\n" +
" - Count | count | COUNT | ct | CT \n" +
" - Count [1-25] | count [1-25] | COUNT [1-25] | ct [1-25] | CT [1-25] \n" +
"\n" +
"Position : Returns the current position of the machine.\n" +
" - Pos | pos | POS | p | P \n" +
"\n" +
"Status : Returns the current status of the amp.\n" +
" - Status | status | STATUS | s | S \n" +
"\n" +
"Setting : Returns the value of the desired setting.\n" +
" - Sett [index] | sett [index] | SETT [index] | st [index] ST [index] \n" +
"\n" +
"Update Setting : Changes a specified setting to a specified value.\n" +
" - Updt [Index] [Value] | updt [Index] [Value] | UPDT [Index] [Value] | u [Index] [Value] | U [Index] [Value] \n" +
"\n" +
"IO Connection : Turns the specified IO connection on or off.\n" +
" - Io [IO#] [on/off] | io [IO#] [on/off] | IO [IO#] [on/off] | i [IO#] [on/off] | I [IO#] [on/off] \n" +
"\n" +
"Exit : Exit the program.\n" +
" - Exit | exit | EXIT | x | X \n");
exit = false;
break;
case "Analog":
case "ANALOG":
case "analog":
case "a":
case "A":
if (input.Length > 1)
{
Console.WriteLine(io.GetAnalog(input[1]));
}
else
{
foreach (string s in io.GetAnalog())
{
Console.WriteLine(s);
}
}
exit = false;
break;
case "Log":
case "LOG":
case "log":
case "l":
case "L":
if (input.Length > 1)
{
foreach (string s in io.GetLog(input[1]))
{
Console.WriteLine(s);
}
}
else
{
foreach (string s in io.GetLog())
{
Console.WriteLine(s);
}
}
exit = false;
break;
case "Count":
case "COUNT":
case "count":
case "ct":
case "CT":
if (input.Length > 1)
{
Console.WriteLine(io.GetCounter(input[1]));
}
else
{
foreach (string s in io.GetCounter())
{
Console.WriteLine(s);
}
}
exit = false;
break;
case "Pos":
case "POS":
case "pos":
case "p":
case "P":
Console.WriteLine(io.GetPosition());
exit = false;
break;
case "Status":
case "STATUS":
case "status":
case "s":
case "S":
Console.WriteLine(io.GetStatus());
exit = false;
break;
case "Sett":
case "SETT":
case "sett":
case "st":
case "ST":
// A quick check of the first character in the second argument will determine if a setting name was sent or a setting index.
// If a setting index, a digit, was found then GetSetting() can be called immediately.
if (char.IsDigit(input[1], 0))
{
Console.WriteLine(io.GetSetting(Convert.ToInt32(input[1])));
}
// Else, the full setting name, not a digit, was found and the setting name needs to be concatenated.
else if (!char.IsDigit(input[1], 0))
{
// 'newInput' is the same length as 'input' minus the command.
string[] newInput = new string[input.Length - 1];
Array.Copy(input, 1, newInput, 0, (input.Length - 1));
string setting = string.Join(" ", newInput);
Console.WriteLine(io.GetSetting(setting));
}
else
{
goto default;
}
exit = false;
break;
case "Home":
case "HOME":
case "home":
case "hm":
case "HM":
io.HomeDevice();
Console.WriteLine("Home Complete");
exit = false;
break;
case "FEL":
case "fel":
case "Fel":
case "Minmax":
case "Min-Max":
case "Min-max":
case "minmax":
case "min-max":
case "MINMAX":
case "MIN-MAX":
case "mm":
case "MM":
io.FindEndLimits();
Console.WriteLine("Min-max complete");
exit = false;
break;
case "Sleep":
case "SLEEP":
case "sleep":
case "sl":
case "SL":
io.DriveSleep();
exit = false;
break;
case "Wake":
case "WAKE":
case "wake":
case "w":
case "W":
io.DriveWake();
exit = false;
break;
case "Updt":
case "UPDT":
case "updt":
case "u":
case "U":
// A quick check of the first character in the second argument will determine if a setting name was sent or a setting index.
// If a setting index, a digit, was found then UpdateSetting() can be called immediately.
if (char.IsDigit(input[1], 0))
{
if (io.UpdateSetting(Convert.ToInt32(input[1]), Convert.ToDouble(input[2])))
{
Console.WriteLine("Update Successful.");
}
else
{
Console.WriteLine("Update Unsuccessful.");
}
exit = false;
}
// Else, the full setting name, not a digit, was found and the setting name needs to be concatenated.
else
{
// 'newInput' is the same length as 'input' minus the command and the new setting value.
string[] newInput = new string[input.Length - 2];
Array.Copy(input, 1, newInput, 0, (input.Length - 2));
string setting = string.Join(" ", newInput);
if (io.UpdateSetting(setting, input[input.Length - 1]))
{
Console.WriteLine("Update Successful.");
}
else
{
Console.WriteLine("Update Unsuccessful.");
}
exit = false;
}
break;
case "io":
case "IO":
case "Io":
case "i":
case "I":
if (input[2].ToLower() == "on")
{
if (!io.IO_Connection(Convert.ToInt32(input[1]), true))
{
goto default;
}
}
else if (input[2].ToLower() == "off")
{
if (!io.IO_Connection(Convert.ToInt32(input[1]), false))
{
goto default;
}
}
else
{
goto default;
}
exit = false;
break;
default:
Console.WriteLine("Invalid Command.\nType 'help' or 'h' to view list of available commands.\n");
exit = false;
break;
}
return exit;
}
}
}