-
Notifications
You must be signed in to change notification settings - Fork 3
/
vnc_base_v602_tcl.tcl
2138 lines (2044 loc) · 66.8 KB
/
vnc_base_v602_tcl.tcl
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
#9
#SITE_ID __UGPB_ISV_internal_use
if 0 {
}
set PB_version 6.0.2
set __vnc_base_version v[join [split $PB_version .] ""]
if { ![info exists mom_sim_post_builder_version] || \
[string compare "$PB_version" $mom_sim_post_builder_version] > 0 } {
set __msg "ERROR :\n\
\nThe VNC needs to be created with Post Builder v$PB_version or newer\
\nin order to work with \"vnc_base_${__vnc_base_version}_tcl.txt\"!"
catch { SIM_mtd_reset }
MOM_abort $__msg
}
set mom_sim_vnc_base_version $PB_version
if { ![info exists sim_mtd_initialized] } {
set sim_mtd_initialized 0
}
if { $sim_mtd_initialized == 0 } {
source "[MOM_ask_env_var UGII_CAM_POST_DIR]sim_high_level_sv_commands.tcl"
set sim_prev_tool_name "undefined"
set sim_prev_zcs "undefined"
set sim_feedrate_mode "RAPID"
set mom_sim_isv_qc 0 ;# 1=ON, 0=OFF
set mom_sim_isv_qc_file "" ;# "" or "listing_device"
set mom_sim_isv_qc_mode 11001 ;# 1000 = SIM, 0100 = VNC, 0010 = PB_CMD, 0001 = Others, 00001 = mom_sim_pos
if { [info exists env(UGII_ISV_QC)] } {
set mom_sim_isv_qc $env(UGII_ISV_QC)
}
if { [info exists env(UGII_ISV_QC_FILE)] } {
set mom_sim_isv_qc_file $env(UGII_ISV_QC_FILE)
}
if { [info exists env(UGII_ISV_QC_MODE)] } {
set mom_sim_isv_qc_mode $env(UGII_ISV_QC_MODE)
}
if { ![info exists mom_sim_nc_register(MAIN_OFFSET)] } {
set mom_sim_nc_register(MAIN_OFFSET) [list 0.0 0.0 0.0 0.0 0.0]
}
if { ![info exists mom_sim_nc_register(LOCAL_OFFSET)] } {
set mom_sim_nc_register(LOCAL_OFFSET) [list 0.0 0.0 0.0 0.0 0.0]
}
if { ![info exists mom_sim_prev_main_offsets] } {
set mom_sim_prev_main_offsets [list 0.0 0.0 0.0 0.0 0.0]
}
if { ![info exists mom_sim_prev_local_offsets] } {
set mom_sim_prev_local_offsets [list 0.0 0.0 0.0 0.0 0.0]
}
if { ![info exists mom_sim_opskip_block_leader] } {
set mom_sim_opskip_block_leader ""
}
if { ![info exists mom_sim_opskip_mode] } {
set mom_sim_opskip_mode 1
}
if { ![info exists mom_sim_vnc_msg_prefix] } {
set mom_sim_vnc_msg_prefix "VNC_MSG:"
}
if { ![info exists mom_sim_prev_o_buffer] } {
set mom_sim_prev_o_buffer ""
}
if { ![info exists mom_sim_delay_one_block] } {
set mom_sim_delay_one_block 0
}
if { ![info exists mom_sim_motion_begun] } {
set mom_sim_motion_begun 0
}
if { ![info exists mom_sim_control_var_equal] } {
set mom_sim_control_var_equal "="
}
if { ![info exists mom_sim_prog_rewind_stop_code] } {
set mom_sim_prog_rewind_stop_code ""
}
if { ![info exists mom_sim_tmp_tool_jct_index] } {
set mom_sim_tmp_tool_jct_index 0
}
if { ![info exists mom_sim_incr_linear_addrs] } {
set mom_sim_incr_linear_addrs [list]
}
if { ![info exists mom_sim_x_double] } {
set mom_sim_x_double 1
}
if { ![info exists mom_sim_y_double] } {
set mom_sim_y_double 1
}
if { ![info exists mom_sim_i_double] } {
set mom_sim_i_double 1
}
if { ![info exists mom_sim_j_double] } {
set mom_sim_j_double 1
}
if { ![info exists mom_sim_x_factor] } {
set mom_sim_x_factor 1
}
if { ![info exists mom_sim_y_factor] } {
set mom_sim_y_factor 1
}
if { ![info exists mom_sim_z_factor] } {
set mom_sim_z_factor 1
}
if { ![info exists mom_sim_i_factor] } {
set mom_sim_i_factor 1
}
if { ![info exists mom_sim_j_factor] } {
set mom_sim_j_factor 1
}
if { ![info exists mom_sim_k_factor] } {
set mom_sim_k_factor 1
}
if { ![info exists mom_sim_home_pos] } {
set mom_sim_home_pos(0) 0.0
set mom_sim_home_pos(1) 0.0
set mom_sim_home_pos(2) 0.0
}
if { ![info exists mom_sim_vnc_msg_only] || !$mom_sim_vnc_msg_only } {
if { [llength [info commands "MOM_before_output_save"]] } {
rename MOM_before_output_save ""
}
if { [llength [info commands "MOM_before_output"]] } {
rename MOM_before_output MOM_before_output_save
} else {
#=======================================================================
proc MOM_before_output_save {} {}
}
#=======================================================================
proc MOM_before_output { } {
global mom_sim_csys_set
global mom_sim_buffer
global mom_sim_message
MOM_before_output_save
global mom_o_buffer
global mom_sim_o_buffer
global mom_sim_delay_one_block
if $mom_sim_delay_one_block {
global mom_sim_prev_o_buffer
set mom_sim_o_buffer $mom_sim_prev_o_buffer
set mom_sim_prev_o_buffer $mom_o_buffer
} else {
set mom_sim_o_buffer [VNC_escape_special_chars $mom_o_buffer]
}
if { [string length [string trim $mom_sim_o_buffer]] == 0 } {
return
}
lappend mom_sim_buffer $mom_sim_o_buffer
if { ![info exists mom_sim_csys_set] } {
set mom_sim_csys_set 0
}
if $mom_sim_csys_set {
if { ![info exists mom_sim_buffer] } {
set mom_sim_message "> $mom_sim_o_buffer"
PB_CMD_vnc__send_message
PB_SIM_call VNC_sim_nc_block "\"$mom_sim_o_buffer\""
VNC_pause "Does this case ever occur?"
} else {
foreach mom_sim_o_buffer $mom_sim_buffer {
set mom_sim_message "> $mom_sim_o_buffer"
PB_CMD_vnc__send_message
PB_SIM_call VNC_sim_nc_block "\"$mom_sim_o_buffer\""
}
unset mom_sim_buffer
}
} else {
set mom_sim_message "> buffered block:$mom_sim_o_buffer"
PB_CMD_vnc__send_message
PB_SIM_call VNC_sim_nc_block "\"$mom_sim_o_buffer\""
}
}
} ;# mom_sim_vnc_msg_only
#=======================================================================
proc VNC_update_sim_pos { } {
global mom_sim_pos
if { ![catch {set pos [PB_SIM_call SIM_ask_last_position_zcs]} ] } {
set mom_sim_pos(0) [lindex $pos 0]
set mom_sim_pos(1) [lindex $pos 1]
set mom_sim_pos(2) [lindex $pos 2]
}
}
#=======================================================================
proc VNC_parse_nc_word { O_BUFF word flag args } {
upvar $O_BUFF o_buff
set tmp_buff $o_buff
set status [VNC_parse_nc_block tmp_buff $word]
if { $status > 0 } {
if { $flag == 0 || $flag == 3 || $status == $flag } {
if { $flag != 0 } {
set o_buff $tmp_buff
}
if { [llength $args] > 0 } {
set exec_cb [string trim [lindex $args 0]]
} else {
set exec_cb ""
}
if { ![string match "" $exec_cb] } {
if { [llength [info commands "$exec_cb"]] } {
eval "$exec_cb"
} else {
return -1
}
}
return 1
}
}
return 0
}
#=======================================================================
proc PB_VNC_sync { } {
PB_SIM_call PB_CMD_vnc__sync
}
#=======================================================================
proc VNC_output_debug_msg { args } {
PB_VNC_output_debug_msg $args
}
#=======================================================================
proc PB_sim_debug_msg { args } {
PB_VNC_output_debug_msg $args
}
#=======================================================================
proc PB_VNC_output_debug_msg { args } {
global mom_sim_isv_debug
global mom_sim_isv_debug_msg_file
if { ![info exists mom_sim_isv_debug_msg_file] || \
[string match "" [string trim $mom_sim_isv_debug_msg_file]] } {
return
}
set proc_name "[lindex [info level -2] 0] [lindex [info level -1] 0]"
if { [string match "listing_device" $mom_sim_isv_debug_msg_file] } {
if { [llength [info commands "MOM_output_to_listing_device"]] } {
if { [llength $args] } {
set str [format "%-60s %s" "\[$proc_name\]" ">[join $args]<"]
} else {
set str [format "%-60s" "\[$proc_name\]"]
}
MOM_output_to_listing_device $str
}
return
}
if { ![info exists mom_sim_isv_debug] } {
if { [catch {set mom_sim_isv_debug [open "$mom_sim_isv_debug_msg_file" w]} ] } {
return
}
}
if { [llength $args] } {
puts $mom_sim_isv_debug "\[$proc_name\] >[join $args]<"
} else {
puts $mom_sim_isv_debug "\[$proc_name\]"
}
flush $mom_sim_isv_debug
}
#=======================================================================
proc VNC_sim_nc_block { block_buffer } {
global mom_sim_control_out mom_sim_control_in
global mom_sim_word_separator mom_sim_word_separator_len
global mom_sim_end_of_block mom_sim_end_of_block_len
global mom_sim_address
global mom_sim_pos mom_sim_prev_pos
global mom_sim_nc_register
global mom_sim_tool_junction
global mom_sim_message
global mom_sim_csys_set
if { ![info exists block_buffer] } {
return
}
set o_buff $block_buffer
set blk_len [string length $o_buff]
if { $mom_sim_end_of_block_len > 0 } {
set end_idx [expr $blk_len - 1 - $mom_sim_end_of_block_len]
set o_buff [string range $o_buff 0 $end_idx]
}
if { [string match "" [string trim $o_buff]] } {
return
}
global mom_sim_nc_block
set mom_sim_nc_block $o_buff
global mom_sim_opskip_block_leader mom_sim_opskip_mode
set opskip_n [string length $mom_sim_opskip_block_leader]
if { $opskip_n > 0 } {
if { [string match "$mom_sim_opskip_block_leader*" $o_buff] } {
if $mom_sim_opskip_mode {
return
} else {
set o_buff [string range $o_buff $opskip_n end]
if { [string match "" [string trim $o_buff]] } {
return
}
}
}
}
set pat "^$mom_sim_address(N,leader)\[0-9\]*\[\.,\]?\[0-9\]*$mom_sim_word_separator"
set cmd [concat regexp -indices \{$pat\} \$o_buff match]
if { [eval $cmd] == 1 } {
if { [lindex $match 0] == 0 } {
set next_idx [expr [lindex $match 1] + 1]
set o_buff [string range $o_buff $next_idx end]
}
}
if { [string match "" [string trim $o_buff]] } {
return
}
set out_len [string length $mom_sim_control_out]
set in_len [string length $mom_sim_control_in]
set vnc_msg 0
if { $out_len > 0 && $in_len > 0 } {
if { [string first "$mom_sim_control_out" $o_buff] == 0 && \
[string last "$mom_sim_control_in" $o_buff] > 0 } {
set vnc_msg 1
}
} elseif { $out_len > 0 } {
if { [string first "$mom_sim_control_out" $o_buff] == 0 } {
set vnc_msg 1
}
}
if $vnc_msg {
set o_buff [string range $o_buff $out_len end]
set o_buff [string range $o_buff 0 [expr [string length $o_buff] - $in_len - 1]]
set o_buff [string trim $o_buff]
global mom_sim_vnc_msg_prefix
if { [string match "$mom_sim_vnc_msg_prefix*" $o_buff] } {
set len [string length "$mom_sim_vnc_msg_prefix"]
set o_buff [string range $o_buff $len end]
set o_buff [string trim $o_buff]
}
set idx [string first "==" $o_buff]
if { $idx > 0 } {
set key [string range $o_buff 0 [expr $idx - 1]]
set word [string range $o_buff [expr $idx + 2] end]
set word [string trim $word \"]
if { ![string match "" [string trim $word]] } {
PB_SIM_call VNC_set_param_per_msg $key $word
}
}
} else {
global mom_sim_o_buffer
set mom_sim_o_buffer $o_buff
if { $mom_sim_csys_set == 0 } {
return
}
PB_SIM_call PB_CMD_vnc__reset_nc_registers
global mom_sim_control_var_leader
global mom_sim_control_var_equal
if { [string length $mom_sim_control_var_leader] && [string match "*$mom_sim_control_var_leader*" $mom_sim_o_buffer] } {
if { [llength [info commands "PB_CMD_vnc__extract_controller_var"]] } {
set status [PB_SIM_call PB_CMD_vnc__extract_controller_var]
if { [string match "EXIT" $status] } {
return
}
} else {
set pat "^$mom_sim_control_var_leader\[0-9\]*\[\\$mom_sim_control_var_equal\]?\[0-9\]*\[\.,\]?\[0-9\]*"
set cmd [concat regexp -indices \{$pat\} \$mom_sim_o_buffer match]
if { [eval $cmd] == 1 } {
set word_list [split $mom_sim_o_buffer $mom_sim_control_var_equal]
set var [string trim [lindex $word_list 0]]
set val [string trim [lindex $word_list 1]]
set mom_sim_nc_register($var) $val
return
}
}
}
if { [llength [info commands "PB_CMD_vnc__condition_nc_block"]] } {
set o_buff [string trim [PB_SIM_call PB_CMD_vnc__condition_nc_block]]
set mom_sim_o_buffer $o_buff
}
if { [llength [info commands "PB_CMD_vnc__process_nc_block"]] } {
set o_buff [PB_SIM_call PB_CMD_vnc__process_nc_block]
} elseif { [llength [info commands "PB_CMD_vnc____process_nc_block"]] } {
set o_buff [PB_SIM_call PB_CMD_vnc____process_nc_block]
}
if { [string match "" [string trim $o_buff]] } {
return
} else {
set mom_sim_o_buffer $o_buff
}
set o_buff $mom_sim_o_buffer
if 0 {
if { [llength [info commands "PB_CMD_vnc__preprocess_nc_block"]] } {
set o_buff [PB_SIM_call PB_CMD_vnc__preprocess_nc_block]
}
}
if { [string match "" [string trim $o_buff]] } {
return
} else {
set mom_sim_o_buffer $o_buff
}
PB_SIM_call PB_CMD_vnc__G_mode_code
set o_buff [string trim $mom_sim_o_buffer]
set mom_sim_nc_register(RETURN_HOME) 0
set mom_sim_nc_register(RETURN_HOME_P) 0
set mom_sim_nc_register(FROM_HOME) 0
set mom_sim_nc_register(SET_LOCAL) 0
set mom_sim_nc_register(MCS_MOVE) 0
set mom_sim_nc_register(RESET_WCS) 0
PB_SIM_call PB_CMD_vnc__G_misc_code
set o_buff [string trim $mom_sim_o_buffer]
PB_SIM_call PB_CMD_vnc__G_plane_code
set o_buff [string trim $mom_sim_o_buffer]
PB_SIM_call PB_CMD_vnc__G_cutcom_code
set o_buff [string trim $mom_sim_o_buffer]
PB_SIM_call PB_CMD_vnc__G_adjust_code
set o_buff [string trim $mom_sim_o_buffer]
for {set i 0} {$i < 8} {incr i} {
set mom_sim_prev_pos($i) $mom_sim_pos($i)
}
set simulate_block 0
if { [string length $o_buff] } {
set simulate_block [PB_SIM_call VNC_parse_motion_word $o_buff]
}
if $mom_sim_nc_register(SET_LOCAL) {
PB_SIM_call PB_CMD_vnc__set_local_offsets
set simulate_block 0
}
if $mom_sim_nc_register(RESET_WCS) {
PB_SIM_call PB_CMD_vnc__reset_coordinate
set simulate_block 0
}
if { $mom_sim_nc_register(RETURN_HOME) || $mom_sim_nc_register(RETURN_HOME_P) } {
PB_SIM_call PB_CMD_vnc__return_home
set simulate_block 0
}
if $mom_sim_nc_register(FROM_HOME) {
PB_SIM_call PB_CMD_vnc__from_home
set simulate_block 0
}
PB_SIM_call PB_CMD_vnc__M_misc_code
set o_buff [string trim $mom_sim_o_buffer]
PB_SIM_call PB_CMD_vnc__G_motion_code
set o_buff [string trim $mom_sim_o_buffer]
if { [string match "CYCLE_*" $mom_sim_nc_register(MOTION)] && $simulate_block == 0 } {
set simulate_block 111000
}
global mom_sim_arc_output_mode
if { [info exists mom_sim_arc_output_mode] && [string match "FULL_CIRCLE" $mom_sim_arc_output_mode] } {
if { [string match "CIRCULAR_*" $mom_sim_nc_register(MOTION)] && $simulate_block == 0 } {
set simulate_block 111000
}
}
PB_SIM_call PB_CMD_vnc__G_feed_code
set o_buff [string trim $mom_sim_o_buffer]
PB_SIM_call VNC_cook_F_val $simulate_block
PB_SIM_call PB_CMD_vnc__G_spindle_code
set o_buff [string trim $mom_sim_o_buffer]
PB_SIM_call PB_CMD_vnc__M_spindle_code
set o_buff [string trim $mom_sim_o_buffer]
PB_SIM_call PB_CMD_vnc__M_coolant_code
set o_buff [string trim $mom_sim_o_buffer]
global mom_sim_other_nc_codes
global mom_sim_other_nc_codes_ex
global mom_sim_simulate_block
set mom_sim_simulate_block $simulate_block
if { [llength [info commands "PB_CMD_vnc__sim_other_devices"]] } {
set cb_cmd "PB_CMD_vnc__sim_other_devices"
} elseif { [llength [info commands "PB_CMD_vnc____sim_other_devices"]] } {
set cb_cmd "PB_CMD_vnc____sim_other_devices"
} else {
set cb_cmd ""
}
if { [info exists mom_sim_other_nc_codes] } {
foreach code $mom_sim_other_nc_codes {
VNC_parse_nc_word block_buffer $code 1 $cb_cmd
}
}
if { [info exists mom_sim_other_nc_codes_ex] } {
foreach code $mom_sim_other_nc_codes_ex {
VNC_parse_nc_word block_buffer $code 2 $cb_cmd
}
}
if { $mom_sim_simulate_block == 0 } {
set simulate_block 0
}
if { $simulate_block } {
PB_SIM_call PB_CMD_vnc__sim_motion
global mom_sim_motion_begun
set mom_sim_motion_begun 1
} else {
}
if $mom_sim_nc_register(MCS_MOVE) {
if { [string match "ABS" $mom_sim_nc_register(INPUT)] } {
global mom_sim_prev_main_offsets mom_sim_prev_local_offsets
set mom_sim_nc_register(MAIN_OFFSET) $mom_sim_prev_main_offsets
set mom_sim_nc_register(LOCAL_OFFSET) $mom_sim_prev_local_offsets
set mom_sim_nc_register(WORK_OFFSET) [list 0.0 0.0 0.0 0.0 0.0]
global mom_sim_prev_csys_matrix
global mom_sim_csys_matrix
global mom_sim_prev_zcs_base
global mom_sim_zcs_base
if { [info exists mom_sim_prev_csys_matrix] } {
array set mom_sim_csys_matrix [array get mom_sim_prev_csys_matrix]
}
set mom_sim_zcs_base $mom_sim_prev_zcs_base
PB_SIM_call PB_CMD_vnc__set_kinematics
}
VNC_unset_vars mom_sim_prev_csys_matrix
if 0 {
global mom_sim_tool_junction mom_sim_current_tool_junction
global mom_sim_current_junction
if { [info exists mom_sim_current_tool_junction] } {
set mom_sim_tool_junction "$mom_sim_current_tool_junction"
set mom_sim_current_junction "$mom_sim_tool_junction"
}
PB_SIM_call SIM_set_current_ref_junction $mom_sim_current_junction
}
PB_SIM_call VNC_update_sim_pos
set mom_sim_nc_register(MCS_MOVE) 0
}
global mom_sim_prog_rewind_stop_code
if { ![string match "" $mom_sim_prog_rewind_stop_code] } {
VNC_parse_nc_block o_buff $mom_sim_prog_rewind_stop_code VNC_rewind_stop_program
}
} ;# Regular block
}
#=======================================================================
proc PB_VNC_init_sim_vars { } {
global mom_sim_nc_register
global mom_sim_control_var_leader
set mom_sim_control_var_leader ""
PB_SIM_call PB_CMD_vnc__init_sim_vars
global mom_sim_vnc_msg_only
if { [info exists mom_sim_vnc_msg_only] && $mom_sim_vnc_msg_only } {
return
}
global mom_sim_current_junction
if { ![info exists mom_sim_current_junction] } {
PB_SIM_call VNC_set_ref_jct {""}
}
global mom_sim_prev_o_buffer
set mom_sim_prev_o_buffer ""
if { [info exists mom_sim_nc_register(REF_INT_PT_X)] } {
unset mom_sim_nc_register(REF_INT_PT_X)
}
if { [info exists mom_sim_nc_register(REF_INT_PT_Y)] } {
unset mom_sim_nc_register(REF_INT_PT_Y)
}
if { [info exists mom_sim_nc_register(REF_INT_PT_Z)] } {
unset mom_sim_nc_register(REF_INT_PT_Z)
}
if { [info exists mom_sim_nc_register(REF_INT_PT_4)] } {
unset mom_sim_nc_register(REF_INT_PT_4)
}
if { [info exists mom_sim_nc_register(REF_INT_PT_5)] } {
unset mom_sim_nc_register(REF_INT_PT_5)
}
global mom_sim_home_pos
if { ![info exists mom_sim_nc_register(REF_PT)] } {
lappend mom_sim_nc_register(REF_PT) $mom_sim_home_pos(0) \
$mom_sim_home_pos(1) \
$mom_sim_home_pos(2) \
0.0 0.0
}
}
#=======================================================================
proc VNC_reset_controller {} {
PB_SIM_call PB_CMD_vnc__reset_controller
}
#=======================================================================
proc PB_VNC_pass_csys_data {} {
global mom_sim_zcs_base
global mom_csys_matrix
global mom_sim_result
global mom_sim_csys_set
if $mom_sim_csys_set {
return
}
PB_SIM_call PB_CMD_vnc__pass_csys_data
}
#=======================================================================
proc PB_VNC_pass_head_data {} {
if { [llength [info commands "PB_CMD_vnc__pass_head_data"]] } {
PB_SIM_call PB_CMD_vnc__pass_head_data
} else {
PB_SIM_call PB_CMD_vnc__pass_head_param
}
}
#=======================================================================
proc PB_VNC_pass_msys_data {} {
global mom_sim_csys_set
if $mom_sim_csys_set {
return
}
PB_SIM_call PB_CMD_vnc__pass_msys_data
}
#=======================================================================
proc PB_VNC_pass_tool_data {} {
if { [llength [info commands "PB_CMD_vnc__pass_tool_data"]] } {
PB_SIM_call PB_CMD_vnc__pass_tool_data
} else {
PB_SIM_call PB_CMD_vnc__pass_tool_param
}
}
#=======================================================================
proc PB_VNC_pass_spindle_data {} {
PB_SIM_call PB_CMD_vnc__pass_spindle_data
}
#=======================================================================
proc VNC_set_param_per_msg { key word } {
global mom_sim_msg_key mom_sim_msg_word
set mom_sim_msg_key $key
set mom_sim_msg_word $word
PB_SIM_call PB_CMD_vnc__set_param_per_msg
}
#=======================================================================
proc VNC_create_tmp_jct {} {
if { [llength [info commands "PB_CMD_vnc__create_tmp_jct"]] } {
if { ![catch {PB_SIM_call PB_CMD_vnc__create_tmp_jct} ] } {
return
}
}
global mom_sim_tool_junction mom_sim_current_junction
global mom_sim_curr_jct_matrix mom_sim_curr_jct_origin
global mom_sim_tool_loaded
if { ![string match "$mom_sim_tool_junction" "$mom_sim_current_junction"] } {
global mom_sim_result
global mom_sim_tmp_tool_jct_index
PB_SIM_call SIM_ask_is_junction_exist __SIM_TMP_TOOL_JCT__$mom_sim_tmp_tool_jct_index
if { $mom_sim_result == 1 } {
incr mom_sim_tmp_tool_jct_index
}
set tmp_tool_jct "__SIM_TMP_TOOL_JCT__$mom_sim_tmp_tool_jct_index"
PB_SIM_call SIM_create_junction $tmp_tool_jct $mom_sim_tool_loaded \
$mom_sim_curr_jct_origin $mom_sim_curr_jct_matrix
PB_SIM_call SIM_set_current_ref_junction $tmp_tool_jct
set mom_sim_tool_junction $tmp_tool_jct
set mom_sim_current_junction $mom_sim_tool_junction
PB_SIM_call VNC_update_sim_pos
}
}
#=======================================================================
proc VNC_parse_motion_word { o_buff } {
global mom_sim_address mom_sim_pos mom_sim_prev_pos
global mom_sim_nc_register
global mom_sim_message
global mom_sim_x_double mom_sim_i_double
global mom_sim_y_double mom_sim_j_double
global mom_sim_x_factor mom_sim_y_factor mom_sim_z_factor
global mom_sim_i_factor mom_sim_j_factor mom_sim_k_factor
global mom_sim_incr_linear_addrs
set addr_list {X Y Z fourth_axis fifth_axis I J K R K_cycle S F}
global mom_sim_offset_pt
if { $mom_sim_nc_register(SET_LOCAL) || \
$mom_sim_nc_register(RESET_WCS) } {
if { [info exists mom_sim_offset_pt] } {
unset mom_sim_offset_pt
}
}
set handle_incr_register 0
set incr_addr_len [llength $mom_sim_incr_linear_addrs]
if { $incr_addr_len > 0 } {
set handle_incr_register 1
set n1 [llength $addr_list]
set n2 [expr $n1 + 1]
set n3 [expr $n2 + 1]
set n4 [expr $n3 + 1]
set n5 [expr $n4 + 1]
set addr_list [concat $addr_list $mom_sim_incr_linear_addrs]
}
set simulate_block 0
global mom_sim_pos_zcs
set mom_sim_pos_zcs(0) $mom_sim_pos(0)
set mom_sim_pos_zcs(1) $mom_sim_pos(1)
set mom_sim_pos_zcs(2) $mom_sim_pos(2)
set mom_sim_pos_zcs(3) $mom_sim_pos(3)
set mom_sim_pos_zcs(4) $mom_sim_pos(4)
global mom_sim_control_var_leader
set i 0
foreach addr $addr_list {
if { $i < 9 } {
switch $addr {
X {
set sim_bit 100000
}
Y {
set sim_bit 10000
}
Z {
set sim_bit 1000
}
fourth_axis {
set sim_bit 100
}
fifth_axis {
set sim_bit 10
}
default {
set sim_bit 1
}
}
} else {
if { $handle_incr_register } {
if { $i == $n1 } {
set sim_bit 100000
}
if { $i == $n2 } {
set sim_bit 10000
}
if { $i == $n3 } {
set sim_bit 1000
}
if { $i == $n4 } {
set sim_bit 100
}
if { $i == $n5 } {
set sim_bit 10
}
}
}
if { ![info exists mom_sim_address($addr,leader)] } {
set addr_leader [string trim $addr]
if { [string length $addr_leader] == 1 && ![string match "-" $addr_leader] } {
set mom_sim_address($addr,leader) $addr_leader
} else {
set mom_sim_message "Unknown Address \"$addr\" will not be processed!"
PB_CMD_vnc__send_message
incr i
continue
}
}
if { [info exists mom_sim_address($addr,leader)] } {
if { [string match "" $mom_sim_control_var_leader] } {
set pat "$mom_sim_address($addr,leader)\[-\+\]?\[0-9\]*\[\.,\]?\[0-9\]*"
} else {
set pat "$mom_sim_address($addr,leader)\[-\+\]?$mom_sim_control_var_leader?\[0-9\]*\[\.,\]?\[0-9\]*"
}
set cmd [concat regexp -indices \{$pat\} \$o_buff match]
if { [eval $cmd] == 1 } {
if { [info exists mom_sim_address($addr,leader_len)] } {
set len $mom_sim_address($addr,leader_len)
} else {
set len [string length $mom_sim_address($addr,leader)]
}
set idx [expr [lindex $match 0] + $len]
set val [string range $o_buff $idx [lindex $match 1]]
set val [string trim $val]
regsub "," $val "." val
set val_is_negative 0
if { [string match "-*" $val] } {
set val [string trimleft $val -]
set val_is_negative 1
} elseif { [string match "+*" $val] } {
set val [string trimleft $val +]
}
if { ![string match "" $mom_sim_control_var_leader] && \
[string match "$mom_sim_control_var_leader*" $val] } {
set val [string trimright $val .]
set val $mom_sim_nc_register($val)
}
if { [string match "*.*" $val] } {
set val [string trim $val 0]
if { [string match "." $val] } {
set val 0.0
}
} else {
if { ![string match "F" $addr] } {
if { [info exists mom_sim_address($addr,format)] } {
set fmt $mom_sim_address($addr,format)
if { [string length [string trim $val]] == 0 } {
incr i
continue
}
if { [catch { set val [PB_SIM_call VNC_format_val $fmt $val] } ] } {
incr i
continue
}
} ;# Valid format
} ;# !F
} ;# No decimal point
if { [string match "" $val] } {
PB_VNC_output_debug_msg "Bad data found : ($val) ($o_buff) -> continue"
incr i
continue
}
if { ![string match "*.*" $val] } {
set val [string trimleft $val 0]
if { [string match "" $val] } {
set val 0.0
}
}
if $val_is_negative {
set val [expr -1 * $val]
}
switch $addr {
X {
set val [expr $val * $mom_sim_x_factor / $mom_sim_x_double]
}
Y {
set val [expr $val * $mom_sim_y_factor / $mom_sim_y_double]
}
Z {
set val [expr $val * $mom_sim_z_factor]
}
I {
set val [expr $val * $mom_sim_i_factor / $mom_sim_i_double]
}
J {
set val [expr $val * $mom_sim_j_factor / $mom_sim_j_double]
}
K {
set val [expr $val * $mom_sim_k_factor]
}
}
set mom_sim_nc_register($addr) $val
if { ![string compare "I" $addr] || ![string compare "J" $addr] || ![string compare "K" $addr] || ![string compare "R" $addr] } {
set mom_sim_pos($i) $val
incr simulate_block $sim_bit
set sim_bit 0
if { ![string match "R" $addr] } {
global mom_sim_heidenhain_iso_circle
set mom_sim_heidenhain_iso_circle 0
global mom_sim_o_buffer
set prev_motion_mode $mom_sim_nc_register(MOTION)
set tmp_o_buff $mom_sim_o_buffer
PB_SIM_call PB_CMD_vnc__G_motion_code
set mom_sim_o_buffer $tmp_o_buff
if { ![string match "CIRCULAR_*" $mom_sim_nc_register(MOTION)] } {
set mom_sim_heidenhain_iso_circle 1
} else {
set mom_sim_heidenhain_iso_circle 0
}
set mom_sim_nc_register(MOTION) $prev_motion_mode
if $mom_sim_heidenhain_iso_circle {
set simulate_block 0
}
}
} else {
if $handle_incr_register {
if { [lsearch $mom_sim_incr_linear_addrs "$addr"] >= 0 } {
if { ![string match "" $val] && [expr {$val != 0.0}] } {
incr simulate_block $sim_bit
set sim_bit 0
if $mom_sim_nc_register(RESET_WCS) {
set val [expr -1 * $val]
}
if { [expr $i == $n1] } {
set mom_sim_pos(0) [expr $mom_sim_pos_zcs(0) + $val]
}
if { [expr $i == $n2] } {
set mom_sim_pos(1) [expr $mom_sim_pos_zcs(1) + $val]
}
if { [expr $i == $n3] } {
set mom_sim_pos(2) [expr $mom_sim_pos_zcs(2) + $val]
}
if { [expr $i == $n4] } {
set mom_sim_pos(3) [expr $mom_sim_pos_zcs(3) + $val]
}
if { [expr $i == $n5] } {
set mom_sim_pos(4) [expr $mom_sim_pos_zcs(4) + $val]
}
}
}
} ;# Handle incr addrs
if { $i < 9 } {
if { [string match "INC" $mom_sim_nc_register(INPUT)] } {
if $mom_sim_nc_register(RESET_WCS) {
set val [expr -1 * $val]
}
if { $i < 3 } {
set mom_sim_pos($i) [expr $mom_sim_pos_zcs($i) + $val]
} else {
set mom_sim_pos($i) [expr $mom_sim_pos($i) + $val]
}
} else {
set offset [expr [lindex $mom_sim_nc_register(MAIN_OFFSET) $i] + \
[lindex $mom_sim_nc_register(LOCAL_OFFSET) $i] + \
[lindex $mom_sim_nc_register(WORK_OFFSET) $i] ]
set mom_sim_pos($i) [expr $offset + $val]
}
incr simulate_block $sim_bit
if 0 {
if { [expr {$mom_sim_pos($i) != $mom_sim_prev_pos($i)}] } {
incr simulate_block $sim_bit
}
}
}
if { $mom_sim_nc_register(SET_LOCAL) || \
$mom_sim_nc_register(RESET_WCS) } {
switch $i {
"0" {
set mom_sim_offset_pt(0) $mom_sim_pos(0)
}
"1" {
set mom_sim_offset_pt(1) $mom_sim_pos(1)
}
"2" {
set mom_sim_offset_pt(2) $mom_sim_pos(2)
}
"3" {
set mom_sim_offset_pt(3) $mom_sim_pos(3)
}
"4" {
set mom_sim_offset_pt(4) $mom_sim_pos(4)
}
}
if $handle_incr_register {
if { [expr $i == $n1] } {
set mom_sim_offset_pt(0) $mom_sim_pos(0)
}
if { [expr $i == $n2] } {
set mom_sim_offset_pt(1) $mom_sim_pos(1)
}
if { [expr $i == $n3] } {
set mom_sim_offset_pt(2) $mom_sim_pos(2)
}
if { [expr $i == $n4] } {
set mom_sim_offset_pt(3) $mom_sim_pos(3)
}
if { [expr $i == $n5] } {
set mom_sim_offset_pt(4) $mom_sim_pos(4)
}
}
}
if { $mom_sim_nc_register(RETURN_HOME) ||\
$mom_sim_nc_register(RETURN_HOME_P) ||\
$mom_sim_nc_register(FROM_HOME) } {
switch $i {
"0" {
set mom_sim_nc_register(REF_INT_PT_X) $mom_sim_pos(0)
set mom_sim_message "$i (REF_INT_PT_X) $o_buff"
PB_CMD_vnc__send_message
}
"1" {
set mom_sim_nc_register(REF_INT_PT_Y) $mom_sim_pos(1)
set mom_sim_message "$i (REF_INT_PT_Y) $o_buff"
PB_CMD_vnc__send_message
}
"2" {
set mom_sim_nc_register(REF_INT_PT_Z) $mom_sim_pos(2)
set mom_sim_message "$i (REF_INT_PT_Z) $o_buff"
PB_CMD_vnc__send_message
}
"3" {
set mom_sim_nc_register(REF_INT_PT_4) $mom_sim_pos(3)
set mom_sim_message "$i (REF_INT_PT_4) $o_buff"
PB_CMD_vnc__send_message
}
"4" {
set mom_sim_nc_register(REF_INT_PT_5) $mom_sim_pos(4)
set mom_sim_message "$i (REF_INT_PT_5) $o_buff"
PB_CMD_vnc__send_message
}
}
if $handle_incr_register {
if { [expr $i == $n1] } {
set mom_sim_nc_register(REF_INT_PT_X) $mom_sim_pos(0)
set mom_sim_message "$i (REF_INT_PT_X) $o_buff"
PB_CMD_vnc__send_message
}
if { [expr $i == $n2] } {
set mom_sim_nc_register(REF_INT_PT_Y) $mom_sim_pos(1)
set mom_sim_message "$i (REF_INT_PT_Y) $o_buff"
PB_CMD_vnc__send_message
}
if { [expr $i == $n3] } {
set mom_sim_nc_register(REF_INT_PT_Z) $mom_sim_pos(2)
set mom_sim_message "$i (REF_INT_PT_Z) $o_buff"
PB_CMD_vnc__send_message
}
if { [expr $i == $n4] } {
set mom_sim_nc_register(REF_INT_PT_4) $mom_sim_pos(3)
set mom_sim_message "$i (REF_INT_PT_4) $o_buff"
PB_CMD_vnc__send_message
}
if { [expr $i == $n5] } {
set mom_sim_nc_register(REF_INT_PT_5) $mom_sim_pos(4)
set mom_sim_message "$i (REF_INT_PT_5) $o_buff"
PB_CMD_vnc__send_message
}
}
}
}
global mom_sim_word_separator_len
set local_buff $o_buff
set leader [string range $local_buff 0 [expr [lindex $match 0] - 1]]
set idx [expr [lindex $match 1] + $mom_sim_word_separator_len + 1]
set local_buff "$leader[string range $local_buff $idx end]"
PB_VNC_output_debug_msg "+++++ $o_buff ($addr) $local_buff"
set o_buff $local_buff
} else {
if { $i < 3 } {
if { ![string match "CYCLE_*" $mom_sim_nc_register(MOTION)] || \
[string match "CYCLE_OFF" $mom_sim_nc_register(MOTION)] } {
set mom_sim_pos($i) $mom_sim_pos_zcs($i)
}
}
}
}
incr i
}