/
emcsh.cc
3729 lines (3154 loc) · 99.5 KB
/
emcsh.cc
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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/********************************************************************
* Description: emcsh.cc
* Extended-Tcl-based EMC automatic test interface
*
* Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* Reorganized by Eric H. Johnson
* License: GPL Version 2
* System: Linux
*
* Copyright (c) 2004 All rights reserved.
*
* Last change:
********************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <math.h>
#include <tcl.h>
#include <tk.h>
#include "emc/linuxcnc.h"
#include "rcs.hh"
#include "posemath.h" // PM_POSE, TO_RAD
#include "emc.hh" // EMC NML
#include "emc_nml.hh" // EMC NML
#include "canon.hh" // CANON_UNITS, CANON_UNITS_INCHES,MM,CM
#include "emcglb.h" // EMC_NMLFILE, TRAJ_MAX_VELOCITY, etc.
#include "emccfg.h" // DEFAULT_TRAJ_MAX_VELOCITY
#include "inifile.hh" // INIFILE
#include "rcs_print.hh"
#include "timer.hh"
#include <rtapi_string.h>
#include "shcom.hh"
#define setresult(t,s) Tcl_SetObjResult((t), Tcl_NewStringObj((s),-1))
/*
Using tcl package Linuxcnc:
Using emcsh:
% package require Linuxcnc
% emc_init -ini <INI file> # to start with an INI file
or
% emc_init # to start with the default inifilename (emc.ini)
With filename, it opens NML buffers to the EMC, runs the script, closes
the buffers, and quits.
With -ini <INI file>, uses specified INI file instead of default emc.ini.
Commands in the LinuxCNC package are all prefixed with "emc_", which makes them
somewhat inconvenient for typing but avoids name conflicts, e.g., open.
Some commands take 0 or more arguments. 0 arguments means they return
the associated value; the argument would be to set the value.
Commands are sent to the EMC, and control resumes immediately. You can
call a timed wait until the command got there, or a timed wait until the
command completed, or not wait at all.
EMC commands:
emc_plat
Returns the platform for which this was compiled, e.g., linux_2_0_36
emc_ini <var> <section>
Returns the string value of <var> in section <section>, in EMC_INIFILE
emc_debug {<new value>}
With no arg, returns the integer value of EMC_DEBUG, in the EMC. Note that
it may not be true that the local EMC_DEBUG variable here (in emcsh and
the GUIs that use it) is the same as the EMC_DEBUG value in the EMC. This
can happen if the EMC is started from one INI file, and the GUI is started
with another that has a different value for DEBUG.
With an arg, sends a command to the EMC to set the new debug level,
and sets the EMC_DEBUG global here to the same value. This will make
the two values the same, since they really ought to be the same.
emc_set_wait none | received | done
Set the wait for commands to return to be right away (none), after the
command was sent and received (received), or after the command was
done (done).
emc_wait received | done
Force a wait for the previous command to be received, or done. This lets
you wait in the event that "emc_set_wait none" is in effect.
emc_set_timeout <timeout>
Set the timeout for commands to return to <timeout>, in seconds. Timeout
is a real number. If it's <= 0.0, it means wait forever. Default is 0.0,
wait forever.
emc_update (none) | none | auto
With no arg, forces an update of the EMC status. With "none", doesn't
cause an automatic update of status with other emc_ words. With "auto",
makes emc_ words automatically update status before they return values.
emc_error
Returns the current EMC error string, or "ok" if no error.
emc_operator_display
Returns the current EMC operator display string, or "ok" if none.
emc_operator_text
Returns the current EMC operator text string, or "ok" if none.
emc_time
Returns the time, in seconds, from the start of the epoch. This starting
time depends on the platform.
emc_estop (none) | on | off
With no arg, returns the estop setting as "on" or "off". Otherwise,
sends an estop on or off command.
emc_machine (none) | on | off
With no arg, returns the machine setting as "on" or "off". Otherwise,
sends a machine on or off command.
emc_mode (none) | manual | auto | mdi
With no arg, returns the mode setting as "manual", "auto", or "mdi".
Otherwise, sends a mode manual, auto, or mdi command.
emc_mist (none) | on | off
With no arg, returns the mist setting as "on" or "off". Otherwise,
sends a mist on or off command.
emc_flood (none) | on | off
With no arg, returns the flood setting as "on" or "off". Otherwise,
sends a flood on or off command.
emc_spindle (spindle_number) (none) | forward | reverse | increase | decrease | constant | off
With no spindle_number defaults to spindle 0. This is a little different
from the default behaviour elsewhere where specifyin no spindle affects all spindles.
With no arg, returns the value of the spindle state as "forward",
"reverse", "increase", "decrease", or "off". With arg, sends the spindle
command. Note that "increase" and "decrease" will cause a speed change in
the corresponding direction until a "constant" command is sent.
emc_brake (none) | on | off
With no arg, returns the brake setting. Otherwise sets the brake.
emc_tool
Returns the id of the currently loaded tool
emc_tool_offset X | Y | ...
Returns the currently applied tool length offset
emc_load_tool_table <file>
Loads the tool table specified by <file>
emc_home 0 | 1 | 2 | ...
Homes the indicated joint.
emc_unhome 0 | 1 | 2 | ...
Unhomes the indicated joint.
emc_jog_stop 0 | 1 | 2 | ...
Stop the joint jog
emc_jog 0 | 1 | 2 | ... <speed>
Jog the indicated joint at <speed>; sign of speed is direction
emc_jog_incr 0 | 1 | 2 | ... <speed> <incr>
Jog the indicated joint by increment <incr> at the <speed>; sign of
speed is direction
emc_feed_override {<percent>}
With no args, returns the current feed override, as a percent. With
argument, set the feed override to be the percent value
emc_rapid_override {<percent>}
With no args, returns the current rapid override, as a percent. With
argument, set the rapid override to be the percent value
emc_spindle_override {<percent>}
With no args, returns the current spindle override, as a percent. With
argument, set the spindle override to be the percent value
emc_abs_cmd_pos X | Y | ...
Returns double obj containing the commanded pos in abs coords,
at given index, 0 = X, etc.
emc_abs_act_pos X | Y | ...
Returns double objs containing the actual pos in abs coords
emc_rel_cmd_pos X | Y | ...
Returns double obj containing the commanded pos in rel coords,
including tool length offset
emc_rel_act_pos X | Y | ...
Returns double objs containing the actual pos in rel coords,
including tool length offset
emc_joint_pos
Returns double objs containing the actual pos in absolute coords of individual
joint/slider positions, excludes tool length offset
emc_pos_offset X | Y | Z | A | B | C | U | V | W
Returns the position offset associated with the world coordinate provided
emc_joint_limit 0 | 1 | ...
Returns "ok", "minsoft", "minhard", "maxsoft", "maxhard"
emc_joint_fault 0 | 1 | ...
Returns "ok" or "fault"
emc_joint_homed 0 | 1 | ...
Returns "homed", "not"
emc_mdi <string>
Sends the <string> as an MDI command
emc_task_plan_init
Initializes the program interpreter
emc_open <filename>
Opens the named file
emc_run {<start line>}
Without start line, runs the opened program from the beginning. With
start line, runs from that line. A start line of -1 runs in verify mode.
emc_pause
Pause program execution
emc_resume
Resume program execution
emc_step
Step the program one line
emc_program
Returns the name of the currently opened program, or "none"
emc_program_line
Returns the currently executing line of the program
emc_program_status
Returns "idle", "running", or "paused"
emc_program_codes
Returns the string for the currently active program codes
emc_override_limit none | 0 | 1
returns state of override, sets it or deactivates it (used to jog off hardware limit switches)
emc_optional_stop none | 0 | 1
returns state of optional setop, sets it or deactivates it (used to stop/continue on M1)
emc_program_codes
Returns the string for the currently active program codes
emc_joint_type <joint>
Returns "linear", "angular", or "custom" for the type of the specified joint
emc_joint_units <joint>
Returns "inch", "mm", "cm", or "deg", "rad", "grad", or "custom",
for the corresponding native units of the specified joint. The type
of the joint (linear or angular) is used to resolve which type of units
are returned. The units are obtained heuristically, based on the
EMC_JOINT_STAT::units numerical value of user units per mm or deg.
For linear joints, something close to 0.03937 is deemed "inch",
1.000 is "mm", 0.1 is "cm", otherwise it's "custom".
For angular joints, something close to 1.000 is deemed "deg",
PI/180 is "rad", 100/90 is "grad", otherwise it's "custom".
emc_program_units
emc_program_linear_units
Returns "inch", "mm", "cm", or "none", for the corresponding linear
units that are active in the program interpreter.
emc_program_angular_units
Returns "deg", "rad", "grad", or "none" for the corresponding angular
units that are active in the program interpreter.
emc_user_linear_units
Returns "inch", "mm", "cm", or "custom", for the
corresponding native user linear units of the EMC trajectory
level. This is obtained heuristically, based on the
EMC_TRAJ_STAT::linearUnits numerical value of user units per mm.
Something close to 0.03937 is deemed "inch", 1.000 is "mm", 0.1 is
"cm", otherwise it's "custom".
emc_user_angular_units
Returns "deg", "rad", "grad", or "custom" for the corresponding native
user angular units of the EMC trajectory level. Like with linear units,
this is obtained heuristically.
emc_display_linear_units
emc_display_angular_units
Returns "inch", "mm", "cm", or "deg", "rad", "grad", or "custom",
for the linear or angular units that are active in the display.
This is effectively the value of linearUnitConversion or
angularUnitConversion, resp.
emc_linear_unit_conversion {inch | mm | cm | auto}
With no args, returns the unit conversion active. With arg, sets the
units to be displayed. If it's "auto", the units to be displayed match
the program units.
emc_angular_unit_conversion {deg | rad | grad | auto}
With no args, returns the unit conversion active. With arg, sets the
units to be displayed. If it's "auto", the units to be displayed match
the program units.
emc_probe_clear
Clear the probe tripped flag.
emc_probe_tripped
Has the probe been tripped since the last clear.
emc_probe_value
Value of current probe signal. (read-only)
emc_probe
Move toward a certain location. If the probe is tripped on the way stop
motion, record the position and raise the probe tripped flag.
emc_teleop_enable
Should motion run in teleop mode? (No args
gets it, one arg sets it.)
emc_kinematics_type
returns the type of kinematics functions used identity=1, serial=2,
parallel=3, custom=4
*/
#define CHECKEMC \
if (!checkStatus() ) {\
setresult(interp,"emc not connected");\
return TCL_ERROR;\
}
static void thisQuit(ClientData clientData)
{
EMC_NULL emc_null_msg;
if (0 != emcStatusBuffer) {
// wait until current message has been received
emcCommandWaitReceived();
}
// clean up NML buffers
if (emcErrorBuffer != 0) {
delete emcErrorBuffer;
emcErrorBuffer = 0;
}
if (emcStatusBuffer != 0) {
delete emcStatusBuffer;
emcStatusBuffer = 0;
emcStatus = 0;
}
if (emcCommandBuffer != 0) {
delete emcCommandBuffer;
emcCommandBuffer = 0;
}
return;
}
/* EMC command functions */
static int emc_plat(ClientData clientdata,
Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[])
{
if (objc == 1) {
setresult(interp,"Linux");
return TCL_OK;
}
setresult(interp,"emc_plat: need no args");
return TCL_ERROR;
}
static int emc_ini(ClientData clientdata,
Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[])
{
IniFile inifile;
std::optional<const char *> inistring;
const char *varstr, *secstr, *defaultstr;
defaultstr = 0;
if (objc != 3 && objc != 4) {
setresult(interp,"emc_ini: need 'var' and 'section'");
return TCL_ERROR;
}
// open it
if (inifile.Open(emc_inifile) == false) {
return TCL_OK;
}
varstr = Tcl_GetStringFromObj(objv[1], 0);
secstr = Tcl_GetStringFromObj(objv[2], 0);
if (objc == 4) {
defaultstr = Tcl_GetStringFromObj(objv[3], 0);
}
if (!(inistring = inifile.Find(varstr, secstr))) {
if (defaultstr != 0) {
setresult(interp,(char *) defaultstr);
}
return TCL_OK;
}
setresult(interp, *inistring);
// close it
inifile.Close();
return TCL_OK;
}
static int emc_Debug(ClientData clientdata,
Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[])
{
Tcl_Obj *debug_obj;
int debug;
CHECKEMC
if (emcUpdateType == EMC_UPDATE_AUTO) {
updateStatus();
}
if (objc == 1) {
// no arg-- return current value
debug_obj = Tcl_NewIntObj(emcStatus->debug);
Tcl_SetObjResult(interp, debug_obj);
return TCL_OK;
}
if (objc == 2) {
if (0 != Tcl_GetIntFromObj(0, objv[1], &debug)) {
setresult(interp,"emc_debug: need debug level as integer");
return TCL_ERROR;
}
sendDebug(debug);
emc_debug = debug;
return TCL_OK;
}
// wrong number of args
setresult(interp,"emc_debug: need zero or one arg");
return TCL_ERROR;
}
static int emc_set_wait(ClientData clientdata,
Tcl_Interp * interp, int objc,
Tcl_Obj * CONST objv[])
{
char *objstr;
CHECKEMC
if (objc == 1) {
switch (emcWaitType) {
case EMC_WAIT_RECEIVED:
setresult(interp,"received");
break;
case EMC_WAIT_DONE:
setresult(interp,"done");
break;
default:
setresult(interp,"(invalid)");
break;
}
return TCL_OK;
}
if (objc == 2) {
objstr = Tcl_GetStringFromObj(objv[1], 0);
if (!strcmp(objstr, "received")) {
emcWaitType = EMC_WAIT_RECEIVED;
return TCL_OK;
}
if (!strcmp(objstr, "done")) {
emcWaitType = EMC_WAIT_DONE;
return TCL_OK;
}
}
setresult(interp, "emc_set_wait: need 'received', 'done', or no args");
return TCL_ERROR;
}
static int emc_wait(ClientData clientdata,
Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[])
{
char *objstr;
CHECKEMC
if (objc == 2) {
objstr = Tcl_GetStringFromObj(objv[1], 0);
if (!strcmp(objstr, "received")) {
if (0 != emcCommandWaitReceived()) {
setresult(interp,"timeout");
}
return TCL_OK;
}
if (!strcmp(objstr, "done")) {
if (0 != emcCommandWaitDone()) {
setresult(interp,"timeout");
}
return TCL_OK;
}
}
setresult(interp,"emc_wait: need 'received' or 'done'");
return TCL_ERROR;
}
static int emc_set_timeout(ClientData clientdata,
Tcl_Interp * interp, int objc,
Tcl_Obj * CONST objv[])
{
double timeout;
Tcl_Obj *timeout_obj;
CHECKEMC
if (objc == 1) {
timeout_obj = Tcl_NewDoubleObj(emcTimeout);
Tcl_SetObjResult(interp, timeout_obj);
return TCL_OK;
}
if (objc == 2) {
if (TCL_OK == Tcl_GetDoubleFromObj(0, objv[1], &timeout)) {
emcTimeout = timeout;
return TCL_OK;
}
}
setresult(interp,"emc_set_timeout: need time as real number");
return TCL_ERROR;
}
static int emc_update(ClientData clientdata,
Tcl_Interp * interp, int objc,
Tcl_Obj * CONST objv[])
{
char *objstr;
CHECKEMC
if (objc == 1) {
// no arg-- return status
updateStatus();
return TCL_OK;
}
if (objc == 2) {
objstr = Tcl_GetStringFromObj(objv[1], 0);
if (!strcmp(objstr, "none")) {
emcUpdateType = EMC_UPDATE_NONE;
return TCL_OK;
}
if (!strcmp(objstr, "auto")) {
emcUpdateType = EMC_UPDATE_AUTO;
return TCL_OK;
}
}
return TCL_OK;
}
static int emc_time(ClientData clientdata,
Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[])
{
CHECKEMC
if (objc == 1) {
Tcl_SetObjResult(interp, Tcl_NewDoubleObj(etime()));
return TCL_OK;
}
setresult(interp,"emc_time: needs no arguments");
return TCL_ERROR;
}
static int emc_error(ClientData clientdata,
Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[])
{
CHECKEMC
if (objc == 1) {
// get any new error, it's saved in global error_string[]
if (0 != updateError()) {
setresult(interp,"emc_error: bad status from EMC");
return TCL_ERROR;
}
// put error on result list
if (error_string[0] == 0) {
setresult(interp,"ok");
} else {
setresult(interp,error_string);
error_string[0] = 0;
}
return TCL_OK;
}
setresult(interp,"emc_error: need no args");
return TCL_ERROR;
}
static int emc_operator_text(ClientData clientdata,
Tcl_Interp * interp, int objc,
Tcl_Obj * CONST objv[])
{
CHECKEMC
if (objc == 1) {
// get any new string, it's saved in global operator_text_string[]
if (0 != updateError()) {
setresult(interp,"emc_operator_text: bad status from EMC");
return TCL_ERROR;
}
// put error on result list
if (operator_text_string[0] == 0) {
setresult(interp,"ok");
operator_text_string[0] = 0;
} else {
setresult(interp,operator_text_string);
}
return TCL_OK;
}
setresult(interp,"emc_operator_text: need no args");
return TCL_ERROR;
}
static int emc_operator_display(ClientData clientdata,
Tcl_Interp * interp, int objc,
Tcl_Obj * CONST objv[])
{
CHECKEMC
if (objc == 1) {
// get any new string, it's saved in global operator_display_string[]
if (0 != updateError()) {
setresult(interp,"emc_operator_display: bad status from EMC");
return TCL_ERROR;
}
// put error on result list
if (operator_display_string[0] == 0) {
setresult(interp,"ok");
} else {
setresult(interp,operator_display_string);
operator_display_string[0] = 0;
}
return TCL_OK;
}
setresult(interp,"emc_operator_display: need no args");
return TCL_ERROR;
}
static int emc_estop(ClientData clientdata,
Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[])
{
char *objstr;
CHECKEMC
if (objc == 1) {
// no arg-- return status
if (emcUpdateType == EMC_UPDATE_AUTO) {
updateStatus();
}
if (emcStatus->task.state == EMC_TASK_STATE::ESTOP) {
setresult(interp,"on");
} else {
setresult(interp,"off");
}
return TCL_OK;
}
if (objc == 2) {
objstr = Tcl_GetStringFromObj(objv[1], 0);
if (!strcmp(objstr, "on")) {
sendEstop();
return TCL_OK;
}
if (!strcmp(objstr, "off")) {
sendEstopReset();
return TCL_OK;
}
}
setresult(interp, "emc_estop: need 'on', 'off', or no args");
return TCL_ERROR;
}
static int emc_machine(ClientData clientdata,
Tcl_Interp * interp, int objc,
Tcl_Obj * CONST objv[])
{
char *objstr;
CHECKEMC
if (objc == 1) {
// no arg-- return status
if (emcUpdateType == EMC_UPDATE_AUTO) {
updateStatus();
}
if (emcStatus->task.state == EMC_TASK_STATE::ON) {
setresult(interp,"on");
} else {
setresult(interp,"off");
}
return TCL_OK;
}
if (objc == 2) {
objstr = Tcl_GetStringFromObj(objv[1], 0);
if (!strcmp(objstr, "on")) {
sendMachineOn();
return TCL_OK;
}
if (!strcmp(objstr, "off")) {
sendMachineOff();
return TCL_OK;
}
}
setresult(interp, "emc_machine: need 'on', 'off', or no args");
return TCL_ERROR;
}
static int emc_mode(ClientData clientdata,
Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[])
{
char *objstr;
CHECKEMC
if (objc == 1) {
// no arg-- return status
if (emcUpdateType == EMC_UPDATE_AUTO) {
updateStatus();
}
switch (emcStatus->task.mode) {
case EMC_TASK_MODE::MANUAL:
setresult(interp,"manual");
break;
case EMC_TASK_MODE::AUTO:
setresult(interp,"auto");
break;
case EMC_TASK_MODE::MDI:
setresult(interp,"mdi");
break;
default:
setresult(interp,"?");
break;
}
return TCL_OK;
}
if (objc == 2) {
objstr = Tcl_GetStringFromObj(objv[1], 0);
if (!strcmp(objstr, "manual")) {
sendManual();
return TCL_OK;
}
if (!strcmp(objstr, "auto")) {
sendAuto();
return TCL_OK;
}
if (!strcmp(objstr, "mdi")) {
sendMdi();
return TCL_OK;
}
}
setresult(interp,"emc_mode: need 'manual', 'auto', 'mdi', or no args");
return TCL_ERROR;
}
static int emc_mist(ClientData clientdata,
Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[])
{
char *objstr;
CHECKEMC
if (objc == 1) {
// no arg-- return status
if (emcUpdateType == EMC_UPDATE_AUTO) {
updateStatus();
}
if (emcStatus->io.coolant.mist == 1) {
setresult(interp,"on");
} else {
setresult(interp,"off");
}
return TCL_OK;
}
if (objc == 2) {
objstr = Tcl_GetStringFromObj(objv[1], 0);
if (!strcmp(objstr, "on")) {
sendMistOn();
return TCL_OK;
}
if (!strcmp(objstr, "off")) {
sendMistOff();
return TCL_OK;
}
}
setresult(interp,"emc_mist: need 'on', 'off', or no args");
return TCL_ERROR;
}
static int emc_flood(ClientData clientdata,
Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[])
{
char *objstr;
CHECKEMC
if (objc == 1) {
// no arg-- return status
if (emcUpdateType == EMC_UPDATE_AUTO) {
updateStatus();
}
if (emcStatus->io.coolant.flood == 1) {
setresult(interp,"on");
} else {
setresult(interp,"off");
}
return TCL_OK;
}
if (objc == 2) {
objstr = Tcl_GetStringFromObj(objv[1], 0);
if (!strcmp(objstr, "on")) {
sendFloodOn();
return TCL_OK;
}
if (!strcmp(objstr, "off")) {
sendFloodOff();
return TCL_OK;
}
}
setresult(interp,"emc_flood: need 'on', 'off', or no args"); return TCL_ERROR;
}
static int emc_spindle(ClientData clientdata,
Tcl_Interp * interp, int objc,
Tcl_Obj * CONST objv[])
{
char *objstr = NULL;
int spindle = 0;
CHECKEMC
if (objc >= 2) {
if (Tcl_GetIntFromObj(interp, objv[1], &spindle) != TCL_OK){ // not a likely spindle index first, then
spindle = 0;
objstr = Tcl_GetStringFromObj(objv[1], 0);
} else {
if (spindle < 0 || spindle > EMCMOT_MAX_SPINDLES){ // should really be num_spindles, but not sure we know that here
setresult(interp,"invalid spindle index number");
return TCL_ERROR;
}
objstr = Tcl_GetStringFromObj(objv[2], 0);
}
}
if (objstr) {
if (!strcmp(objstr, "forward")) {
sendSpindleForward(spindle);
return TCL_OK;
}
if (!strcmp(objstr, "reverse")) {
sendSpindleReverse(spindle);
return TCL_OK;
}
if (!strcmp(objstr, "increase")) {
sendSpindleIncrease(spindle);
return TCL_OK;
}
if (!strcmp(objstr, "decrease")) {
sendSpindleDecrease(spindle);
return TCL_OK;
}
if (!strcmp(objstr, "constant")) {
sendSpindleConstant(spindle);
return TCL_OK;
}
if (!strcmp(objstr, "off")) {
sendSpindleOff(spindle);
return TCL_OK;
}
}
else
{
// no arg-- return status
if (emcUpdateType == EMC_UPDATE_AUTO) {
updateStatus();
}
if (emcStatus->motion.spindle[spindle].increasing > 0) {
setresult(interp,"increase");
} else if (emcStatus->motion.spindle[spindle].increasing < 0) {
setresult(interp,"decrease");
} else if (emcStatus->motion.spindle[spindle].direction > 0) {
setresult(interp,"forward");
} else if (emcStatus->motion.spindle[spindle].direction < 0) {
setresult(interp,"reverse");
} else {
setresult(interp,"off");
}
return TCL_OK;
}
setresult(interp,"emc_spindle: need 'on', 'off', a spindle index or no args");
return TCL_ERROR;
}
static int emc_brake(ClientData clientdata,
Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[])
{
char *objstr = NULL;
int spindle = 0;
CHECKEMC
if (objc >= 2) {
if (Tcl_GetIntFromObj(interp, objv[1], &spindle) != TCL_OK){ // not a likely spindle index first, then
spindle = 0;
objstr = Tcl_GetStringFromObj(objv[1], 0);
} else {
if (spindle < 0 || spindle > EMCMOT_MAX_SPINDLES){ // FIXME: should really be num_spindles, but not sure we know that here
setresult(interp,"invalid spindle index number");
return TCL_ERROR;
}
objstr = Tcl_GetStringFromObj(objv[2], 0);
}
}
if (objstr) {
if (!strcmp(objstr, "on")) {
sendBrakeEngage(spindle);
return TCL_OK;
}
if (!strcmp(objstr, "off")) {
sendBrakeRelease(spindle);
return TCL_OK;
}
}
else
{
// no arg-- return status
if (emcUpdateType == EMC_UPDATE_AUTO) {
updateStatus();
}
if (emcStatus->motion.spindle[spindle].brake == 1) {
setresult(interp,"on");
} else {
setresult(interp,"off");
}
return TCL_OK;
}
setresult(interp,"emc_brake: need 'on', 'off', spindle index or no args");
return TCL_ERROR;
}
static int emc_tool(ClientData clientdata,
Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[])
{
Tcl_Obj *toolobj;
CHECKEMC
if (objc != 1) {
setresult(interp,"emc_tool: need no args");
return TCL_ERROR;
}
if (emcUpdateType == EMC_UPDATE_AUTO) {
updateStatus();
}
toolobj = Tcl_NewIntObj(emcStatus->io.tool.toolInSpindle);
Tcl_SetObjResult(interp, toolobj);
return TCL_OK;
}
static int emc_tool_offset(ClientData clientdata,
Tcl_Interp * interp, int objc,
Tcl_Obj * CONST objv[])
{
char string[1];
Tcl_Obj *tlobj;
string[0] = 'Z'; //default if not specified
CHECKEMC
if (objc > 2) {
setresult(interp,"emc_tool_offset: need 0 or 1 args");
return TCL_ERROR;