-
Notifications
You must be signed in to change notification settings - Fork 0
/
PythonProgramGUIPortalfraese_V1_00.py
1789 lines (1559 loc) · 98.8 KB
/
PythonProgramGUIPortalfraese_V1_00.py
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
""" ############################################################################################ """
""" ############################################################################################ """
""" GUI CNC mill with Teensy4.0 """
""" V1_00, 2021-12-24, are """
""" ############################################################################################ """
""" ############################################################################################ """
"""
##### GUI <--> Mill, Shared memory
PythonProgramGUIPortalfraese.py <--> PythonProgrammPortalfraese.py
ComGUIArrayInt = multiprocessing.Array('i', range(32))
ComGUIArrayIntStringActualStep = multiprocessing.Array('i', range(100))
ComGUIArrayIntStringActualFile = multiprocessing.Array('i', range(256))
##### ComGUIArrayInt
ComGUIArrayInt[0] GUI -> Mill Command. 1=read file, 2=start program, 3=stop program. Mill -> GUI 0 = command read
ComGUIArrayInt[1] GUI -> Mill ManualCommands. Bit 0 = Manual command Spindle on
Bit 1 = Manual command Coolant on
Bit 2 = Manual command Clamp on
Bit 3 = Manual command Light on
Bit 4 = Manual command X+
Bit 5 = Manual command X-
Bit 6 = Manual command Y+
Bit 7 = Manual command Y-
Bit 8 = Manual command Z+
Bit 9 = Manual command Z-
Bit 10 = ClearDiagnosticCounterI2C
Bit 11 = Manual mode selected
Bit 12 = Measure tool length
ComGUIArrayInt[2] GUI -> Mill Spindle speed in manual mode
ComGUIArrayInt[3]
ComGUIArrayInt[4]
ComGUIArrayInt[5]
ComGUIArrayInt[6]
ComGUIArrayInt[7]
ComGUIArrayInt[8] Mill -> GUI Actual line number in file
ComGUIArrayInt[9] Mill -> GUI State. 0=Idle, 1=Program active, 2=Read file active
ComGUIArrayInt[10] Mill -> GUI Digital states. Bit 0 = Reference sensor X
Bit 1 = Reference sensor Y
Bit 2 = Reference sensor Z
Bit 3 = Emergency stop button
Bit 4 = Spindle on
Bit 5 = Coolant on
Bit 6 = Clamp on
Bit 7 = Light on
Bit 8 = Tool length sensor
Bit 9 = Measure tool length done
ComGUIArrayInt[11] Mill -> GUI Diagnostic I2C Recive good
ComGUIArrayInt[12] Mill -> GUI Diagnostic I2C Recive checksum error
ComGUIArrayInt[13] Mill -> GUI Diagnostic I2C Recive hardware error
ComGUIArrayInt[14] Mill -> GUI Diagnostic I2C Send good
ComGUIArrayInt[15] Mill -> GUI Diagnostic I2C Send hardware error
ComGUIArrayInt[16] Mill -> GUI actual position X HighHigh
ComGUIArrayInt[17] Mill -> GUI actual position X High
ComGUIArrayInt[18] Mill -> GUI actual position X Low
ComGUIArrayInt[19] Mill -> GUI actual position X LowLow
ComGUIArrayInt[20] Mill -> GUI actual position Y HighHigh
ComGUIArrayInt[21] Mill -> GUI actual position Y High
ComGUIArrayInt[22] Mill -> GUI actual position Y Low
ComGUIArrayInt[23] Mill -> GUI actual position Y LowLow
ComGUIArrayInt[24] Mill -> GUI actual position Z HighHigh
ComGUIArrayInt[25] Mill -> GUI actual position Z High
ComGUIArrayInt[26] Mill -> GUI actual position Z Low
ComGUIArrayInt[27] Mill -> GUI actual position Z LowLow
ComGUIArrayInt[28] Mill -> GUI actual position Reserve
ComGUIArrayInt[29] Mill -> GUI actual position Reserve
ComGUIArrayInt[30] Mill -> GUI actual position Reserve
ComGUIArrayInt[31] Mill -> GUI actual position Reserve
##### ComGUIArrayIntStringActualStep Mill -> GUI
Value 0 = Stringlen
Value 1..99 = Stringdata
##### ComGUIArrayIntStringActualFile GUI -> Mill
Value 0 = Stringlen
Value 1..255 = Stringdata
"""
""" ############################################################################################ """
""" Import python modules """
import time
import datetime
import tkinter as tk
from tkinter import filedialog as fd
from tkinter import messagebox
#from tkinter import ttk
import multiprocessing
#import ctypes
""" ############################################################################################ """
""" Import own modules """
# Own modules import with "as"
# so that later name of module can be changed without changing code.
import PythonProgrammPortalfraese as PPP
""" ############################################################################################ """
""" Global variables """
# Font
LARGE_FONT = ("Verdana", 12)
""" ############################################################################################ """
""" Constants """
SPEEDSPINDLEMIN = 5000
SPEEDSPINDLEMAX = 25000
""" ############################################################################################ """
""" Create Multitask "MultitaskComTeensy" and shared memory """
# 'i' = INT, 'f' = REAL
ComGUIArrayInt = multiprocessing.Array('i', range(32)) # Shared memory of INT
ComGUIArrayIntStringActualStep = multiprocessing.Array('i', range(100)) # Shared memory of INT
ComGUIArrayIntStringActualFile = multiprocessing.Array('i', range(256)) # Shared memory of INT
lock = multiprocessing.Lock()
MultitaskComTeensy = multiprocessing.Process(target=PPP.main, args=(ComGUIArrayInt, ComGUIArrayIntStringActualStep, ComGUIArrayIntStringActualFile, lock))
""" ############################################################################################ """
""" Function calculate actual position """
# Input 4 bytes, output float with 4 decimal places
def CalculateActualPosition(IntHighHigh, INTHigh, INTLow, INTLowLow):
# Local variables
ActualPositionHex = 0x0
ActualPositionFloat = 0.0
# From 4 Bytes I2C to one HEX-value
ActualPositionHex = IntHighHigh << 24
ActualPositionHex = ActualPositionHex | (INTHigh << 16)
ActualPositionHex = ActualPositionHex | (INTLow << 8)
ActualPositionHex = ActualPositionHex | INTLowLow
# When actual position is negative, then Two's complement
#TwoComplement = (-1)*(256 - Value) # 256 = 8 bit value
#OneComplement = (-1)*(255 - Value)
if IntHighHigh >> 7 == 1:
ActualPositionHex = (-1)*(4294967296 - ActualPositionHex) # 4294967296 = 32 bit value, two's complement
ActualPositionFloat = float(ActualPositionHex) / 10000.0
return ActualPositionFloat
""" ############################################################################################ """
""" ############################################################################################ """
""" Class tkinter GUI """
""" tkinter GUI Laeuft in einem eigenen thread """
class AppGUI(object):
def __init__(self, parent):
""" #################################################################################### """
""" Constructor """
""" #################################################################################### """
""" Mainwindow """
self.root = parent # Hauptfenster
self.root.title("Milling machine") # Titel Hauptfenster
self.root.geometry("800x600") # Hauptfenster Groesse
self.root.extra = "MainWindow"
self.root.bind("<Configure>", self.OnResizeMainwindow) # <Configure> = the widget changed
# size. Methode "OnResizeMainwindow"
# bei Fenstergroessenaenderung
self.root.wm_protocol("WM_DELETE_WINDOW", self.Quit) # Aufruf Methode Quit bei Programmende
self.WidthMainwindow = 500 # Hoehe Hauptfenster
self.HeightMainwindow = 300 # Breite Hauptfenster
# Clear shared memory
with lock:
for i in range(31):
ComGUIArrayInt[i] = 0
for i in range(99):
ComGUIArrayIntStringActualStep[i] = 0
for i in range(255):
ComGUIArrayIntStringActualFile[i] = 0
""" #################################################################################### """
""" Common variable """
""" #################################################################################### """
self.StringlenLine = [] # List stringlength for each line in G-Code file
self.CompareMemoryGUIReadActualLineNumberFile = 999999
self.ProgramActive = False
self.ReadFileActive = False
self.FileLoadedFirstTime = False
self.StartTimeProgram = time.time()
self.ElapsedTimeProgram = 0
self.ManualMode = False
self.ManualCommandXPlus = False
self.ManualCommandXMinus = False
self.ManualCommandYPlus = False
self.ManualCommandYMinus = False
self.ManualCommandZPlus = False
self.ManualCommandZMinus = False
self.ManualCommands = 0
self.SpindleSpeedmanualMode = SPEEDSPINDLEMIN
self.ClearCounterI2C = False
self.PulseProgramActiveOff = False
self.PulseReadFileActiveOff = False
""" #################################################################################### """
""" Menu """
""" #################################################################################### """
menubar = tk.Menu(self.root)
filemenu = tk.Menu(menubar, tearoff=0)
filemenu.add_command(label="Exit", command=self.Quit) # Aufruf Methode Quit bei Programmende
menubar.add_cascade(label="File", menu=filemenu)
self.root.config(menu=menubar)
""" #################################################################################### """
""" Frame menu, with buttons on Frame menu """
""" #################################################################################### """
self.FrameMenu = tk.Frame(master=self.root,
width=260,
height=240,
borderwidth=0,
bg="white")
self.FrameMenu.extra = "FrameMenu"
""" Buttons on Frame menu """
# Button Main, command lambda, to pass more arguments
self.ButtonFrameMenuMain = tk.Button(master=self.FrameMenu,
text="Main",
activeforeground="green",
command=lambda: self.showFrame(self.FrameMain,
"FrameMain"))
self.ButtonFrameMenuMain.extra = "ButtonFrameMenuMain"
# Button Manual, command lambda, to pass more arguments
self.ButtonFrameMenuManual = tk.Button(master=self.FrameMenu,
text="Manual",
activeforeground="green",
command=lambda: self.showFrame(self.FrameManual,
"FrameManual"))
self.ButtonFrameMenuManual.extra = "ButtonFrameMenuManual"
# Button Settings, command lambda, to pass more arguments
self.ButtonFrameMenuSettings = tk.Button(master=self.FrameMenu,
text="Settings",
activeforeground="green",
command=lambda: self.showFrame(self.FrameSettings,
"FrameSettings"))
self.ButtonFrameMenuSettings.extra = "ButtonFrameMenuSettings"
# Button Diagnostic, command lambda, to pass more arguments
self.ButtonFrameMenuDiagnostic = tk.Button(master=self.FrameMenu,
text="Diagnostic",
activeforeground="green",
command=lambda: self.showFrame(self.FrameDiagnostic,
"FrameDiagnostic"))
self.ButtonFrameMenuDiagnostic.extra = "ButtonFrameMenuDiagnostic"
# Save the buttons system colors
self.ButtonSystemColorBackground = self.ButtonFrameMenuSettings.cget("background")
self.ButtonSystemColorActiveBackground = self.ButtonFrameMenuSettings.cget("activebackground")
""" #################################################################################### """
""" Frame Main, Frame Manual, Frame Settings, Frame Diagnostic """
""" #################################################################################### """
""" Class Frameattributes """
class Frameattributes:
x = 0
y = 0
width = 0
height = 0
visible = False
""" Frame Main """
self.FrameMain = tk.Frame(master=self.root,
width=260,
height=240,
borderwidth=0,
background="grey")
self.FrameMain.place_forget() # hide the frame
self.FrameMain.extra = "FrameMain"
self.FrameMainAttributes = Frameattributes() # Class Frameattributes
""" Frame Manual """
self.FrameManual = tk.Frame(master=self.root,
width=260,
height=240,
borderwidth=0,
background="grey")
self.FrameManual.place_forget() # hide the frame
self.FrameManual.extra = "FrameManual"
self.FrameManualAttributes = Frameattributes() # Class Frameattributes
""" Frame Settings """
self.FrameSettings = tk.Frame(master=self.root,
width=260,
height=240,
borderwidth=0,
background="grey")
self.FrameSettings.place_forget() # hide the frame
self.FrameSettings.extra = "FrameSettings"
self.FrameSettingsAttributes = Frameattributes() # Class Frameattributes
""" Frame Diagnostic """
self.FrameDiagnostic = tk.Frame(master=self.root,
width=260,
height=240,
borderwidth=0,
background="grey")
self.FrameDiagnostic.place_forget() # hide the frame
self.FrameDiagnostic.extra = "FrameDiagnostic"
self.FrameDiagnosticAttributes = Frameattributes() # Class Frameattributes
""" #################################################################################### """
""" Objects on Frame Main """
""" #################################################################################### """
""" Label actual positions """
# X
self.LabelActualPosXTextvariable = tk.StringVar()
self.LabelActualPosX = tk.Label(master=self.FrameMain,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
textvariable=self.LabelActualPosXTextvariable,
font=LARGE_FONT,
borderwidth = 4,
background="red")
self.LabelActualPosX.extra = "LabelActualPosX"
# Y
self.LabelActualPosYTextvariable = tk.StringVar()
self.LabelActualPosY = tk.Label(master=self.FrameMain,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
textvariable=self.LabelActualPosYTextvariable,
font=LARGE_FONT,
borderwidth = 4,
background="green2")
self.LabelActualPosY.extra = "LabelActualPosY"
# Z
self.LabelActualPosZTextvariable = tk.StringVar()
self.LabelActualPosZ = tk.Label(master=self.FrameMain,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
textvariable=self.LabelActualPosZTextvariable,
font=LARGE_FONT,
borderwidth = 4,
background="lightblue1")
self.LabelActualPosZ.extra = "LabelActualPosZ"
""" #################################################################################### """
""" Label date time """
self.LabelDateTimeTextvariable = tk.StringVar()
self.LabelDateTime = tk.Label(master=self.FrameMain,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
textvariable=self.LabelDateTimeTextvariable,
font=LARGE_FONT,
borderwidth = 4,
background="white")
self.LabelDateTime.extra = "LabelDateTime"
""" #################################################################################### """
""" Label elapsed time program """
self.LabelElapsedTimeTextvariable = tk.StringVar()
self.LabelElapsedTime = tk.Label(master=self.FrameMain,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
textvariable=self.LabelElapsedTimeTextvariable,
font=LARGE_FONT,
borderwidth = 4,
background="white")
self.LabelElapsedTime.extra = "LabelElapsedTime"
""" #################################################################################### """
""" Label actual file """
self.LabelActualFileTextvariable = tk.StringVar()
self.LabelActualFile = tk.Label(master=self.FrameMain,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
textvariable=self.LabelActualFileTextvariable,
font=LARGE_FONT,
borderwidth = 4,
background="white")
self.LabelActualFile.extra = "LabelActualFile"
self.LabelActualFileTextvariable.set("File: No file select")
""" #################################################################################### """
""" Label actual step """
self.LabelActualStepTextvariable = tk.StringVar()
self.LabelActualStep = tk.Label(master=self.FrameMain,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
textvariable=self.LabelActualStepTextvariable,
font=LARGE_FONT,
borderwidth = 4,
background="white")
self.LabelActualStep.extra = "LabelActualStep"
""" #################################################################################### """
""" Textbox actual file G-Code and scrollbar """
self.TextboxGCode = tk.Text(master=self.FrameMain,)
self.ScrollbarGCode = tk.Scrollbar(master=self.FrameMain, orient=tk.VERTICAL, command=self.TextboxGCode.yview)
self.TextboxGCode.configure(yscrollcommand=self.ScrollbarGCode.set, font=LARGE_FONT)
self.TextboxGCode.tag_configure("TagTextWidgetGCode", background="yellow") # Tag actual step in the text widget, background = yellow
self.TextboxGCode.extra = "TextboxGCode"
self.ScrollbarGCode.extra = "ScrollbarGCode"
""" #################################################################################### """
""" Button open file """
self.ButtonOpenFile = tk.Button(master=self.FrameMain,
text="Open file",
activeforeground="green",
command=self.OpenFile)
self.ButtonOpenFile.extra = "ButtonOpenFile"
""" #################################################################################### """
""" Button start """
self.ButtonStart = tk.Button(master=self.FrameMain,
text="Start",
activeforeground="green",
state=tk.DISABLED,
command=self.ButtonStartPressed)
self.ButtonStart.extra = "ButtonStart"
""" #################################################################################### """
""" Objects on Frame Manual """
""" #################################################################################### """
""" Label actual positions """
# X
self.LabelActualPosXManual = tk.Label(master=self.FrameManual,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
textvariable=self.LabelActualPosXTextvariable, # Same textvariable as in main
font=LARGE_FONT,
borderwidth = 4,
background="red")
self.LabelActualPosXManual.extra = "LabelActualPosXManual"
# Y
self.LabelActualPosYManual = tk.Label(master=self.FrameManual,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
textvariable=self.LabelActualPosYTextvariable, # Same textvariable as in main
font=LARGE_FONT,
borderwidth = 4,
background="green2")
self.LabelActualPosYManual.extra = "LabelActualPosYManual"
# Z
self.LabelActualPosZManual = tk.Label(master=self.FrameManual,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
textvariable=self.LabelActualPosZTextvariable, # Same textvariable as in main
font=LARGE_FONT,
borderwidth = 4,
background="lightblue1")
self.LabelActualPosZManual.extra = "LabelActualPosZManual"
""" #################################################################################### """
""" Button manual """
self.ButtonManual = tk.Button(master=self.FrameManual,
text="Manual mode",
activeforeground="green",
command=lambda: self.ButtonManualPressed("ButtonManual"))
self.ButtonManual.extra = "ButtonManual"
""" #################################################################################### """
""" Button movement X/Y/Z off """
self.ButtonMovementOff = tk.Button(master=self.FrameManual,
text="Off",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonMovementOff"))
self.ButtonMovementOff.extra = "ButtonMovementOff"
""" #################################################################################### """
""" Button X+ """
self.ButtonXPlus = tk.Button(master=self.FrameManual,
text="X +",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonXPlus"))
self.ButtonXPlus.extra = "ButtonXPlus"
""" Button X- """
self.ButtonXMinus = tk.Button(master=self.FrameManual,
text="X -",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonXMinus"))
self.ButtonXMinus.extra = "ButtonXMinus"
""" #################################################################################### """
""" Button Y+ """
self.ButtonYPlus = tk.Button(master=self.FrameManual,
text="Y +",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonYPlus"))
self.ButtonYPlus.extra = "ButtonYPlus"
""" Button Y- """
self.ButtonYMinus = tk.Button(master=self.FrameManual,
text="Y -",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonYMinus"))
self.ButtonYMinus.extra = "ButtonYMinus"
""" #################################################################################### """
""" Button Z+ """
self.ButtonZPlus = tk.Button(master=self.FrameManual,
text="Z +",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonZPlus"))
self.ButtonZPlus.extra = "ButtonZPlus"
""" Button Z- """
self.ButtonZMinus = tk.Button(master=self.FrameManual,
text="Z -",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonZMinus"))
self.ButtonZMinus.extra = "ButtonZMinus"
""" #################################################################################### """
""" Outputs """
self.LabelOutputs = tk.Label(master=self.FrameManual,
anchor=tk.CENTER, # Align the text center
padx = 10, # Space left
text="Digital outputs",
font=LARGE_FONT,
borderwidth = 4,
background=self.ButtonSystemColorActiveBackground)#"grey"
self.LabelOutputs.extra = "LabelOutputs"
""" #################################################################################### """
""" Spindle """
self.LabelSpindle = tk.Label(master=self.FrameManual,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
text="Spindle M3,M5",
font=LARGE_FONT,
borderwidth = 4,
background="red")
self.LabelSpindle.extra = "LabelSpindle"
""" Button spindle on """
self.ButtonSpindleOn = tk.Button(master=self.FrameManual,
text="On",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonSpindleOn"))
self.ButtonSpindleOn.extra = "ButtonSpindleOn"
""" Button Spindle off """
self.ButtonSpindleOff = tk.Button(master=self.FrameManual,
text="Off",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonSpindleOff"))
self.ButtonSpindleOff.extra = "ButtonSpindleOff"
""" Slider spindle speed """
self.SliderSpindleSpeed = tk.Scale(master=self.FrameManual,
from_=SPEEDSPINDLEMIN, to=SPEEDSPINDLEMAX,
orient=tk.HORIZONTAL,
state=tk.DISABLED,
command=self.SliderSpindleSpeedChanged)
self.SliderSpindleSpeed.extra = "SliderSpindleSpeed"
""" #################################################################################### """
""" Coolant """
self.LabelCoolant = tk.Label(master=self.FrameManual,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
text="Coolant M8,M9",
font=LARGE_FONT,
borderwidth = 4,
background="red")
self.LabelCoolant.extra = "LabelCoolant"
""" Button coolant on """
self.ButtonCoolantOn = tk.Button(master=self.FrameManual,
text="On",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonCoolantOn"))
self.ButtonCoolantOn.extra = "ButtonCoolantOn"
""" Button coolant off """
self.ButtonCoolantOff = tk.Button(master=self.FrameManual,
text="Off",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonCoolantOff"))
self.ButtonCoolantOff.extra = "ButtonCoolantOff"
""" #################################################################################### """
""" Clamp """
self.LabelClamp = tk.Label(master=self.FrameManual,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
text="Clamp M10,M11",
font=LARGE_FONT,
borderwidth = 4,
background="red")
self.LabelClamp.extra = "LabelClamp"
""" Button clamp on """
self.ButtonClampOn = tk.Button(master=self.FrameManual,
text="On",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonClampOn"))
self.ButtonClampOn.extra = "ButtonClampOn"
""" Button clamp off """
self.ButtonClampOff = tk.Button(master=self.FrameManual,
text="Off",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonClampOff"))
self.ButtonClampOff.extra = "ButtonClampOff"
""" #################################################################################### """
""" Light """
self.LabelLight = tk.Label(master=self.FrameManual,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
text="Light M35,M36",
font=LARGE_FONT,
borderwidth = 4,
background="red")
self.LabelLight.extra = "LabelLight"
""" Button light on """
self.ButtonLightOn = tk.Button(master=self.FrameManual,
text="On",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonLightOn"))
self.ButtonLightOn.extra = "ButtonLightOn"
""" Button light off """
self.ButtonLightOff = tk.Button(master=self.FrameManual,
text="Off",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonLightOff"))
self.ButtonLightOff.extra = "ButtonLightOff"
""" #################################################################################### """
""" Label inputs: reference sensors, emergency stop, tool length sensor """
self.LabelInputs = tk.Label(master=self.FrameManual,
anchor=tk.CENTER, # Align the text center
padx = 10, # Space left
text="Digital inputs",
font=LARGE_FONT,
borderwidth = 4,
background=self.ButtonSystemColorActiveBackground)#"grey"
self.LabelInputs.extra = "LabelInputs"
self.LabelReferenceSensorX = tk.Label(master=self.FrameManual,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
text="Reference sensor X",
font=LARGE_FONT,
borderwidth = 4,
background="red")
self.LabelReferenceSensorX.extra = "LabelReferenceSensorX"
self.LabelReferenceSensorY = tk.Label(master=self.FrameManual,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
text="Reference sensor Y",
font=LARGE_FONT,
borderwidth = 4,
background="red")
self.LabelReferenceSensorY.extra = "LabelReferenceSensorY"
self.LabelReferenceSensorZ = tk.Label(master=self.FrameManual,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
text="Reference sensor Z",
font=LARGE_FONT,
borderwidth = 4,
background="red")
self.LabelReferenceSensorZ.extra = "LabelReferenceSensorZ"
self.LabelEmergencyStop = tk.Label(master=self.FrameManual,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
text="Emergency stop",
font=LARGE_FONT,
borderwidth = 4,
background="red")
self.LabelEmergencyStop.extra = "LabelEmergencyStop"
self.LabelToolLengthSensor = tk.Label(master=self.FrameManual,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
text="Tool length sensor",
font=LARGE_FONT,
borderwidth = 4,
background="red")
self.LabelToolLengthSensor.extra = "LabelToolLengthSensor"
""" #################################################################################### """
""" Measure tool length """
self.MeasureToolLength = tk.Label(master=self.FrameManual,
anchor=tk.CENTER, # Align the text center
padx = 10, # Space left
text="Measure tool length",
font=LARGE_FONT,
borderwidth = 4,
background=self.ButtonSystemColorActiveBackground)#"grey"
self.MeasureToolLength.extra = "MeasureToolLength"
self.LabelToolLength = tk.Label(master=self.FrameManual,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
text="Tool length",
font=LARGE_FONT,
borderwidth = 4,
background="red")
self.LabelToolLength.extra = "LabelToolLength"
self.ButtonToolLengthOn = tk.Button(master=self.FrameManual,
text="On",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonToolLengthOn"))
self.ButtonToolLengthOn.extra = "ButtonToolLengthOn"
self.ButtonToolLengthOff = tk.Button(master=self.FrameManual,
text="Off",
activeforeground="green",
state=tk.DISABLED,
command=lambda: self.ButtonManualPressed("ButtonToolLengthOff"))
self.ButtonToolLengthOff.extra = "ButtonToolLengthOff"
""" #################################################################################### """
""" Objects on Frame Settings """
""" #################################################################################### """
""" #################################################################################### """
""" Objects on Frame Diagnostic """
""" #################################################################################### """
""" Labels diagnistic I2C """
self.LabelI2CReciveGoodTextvariable = tk.StringVar()
self.LabelI2CReciveGood = tk.Label(master=self.FrameDiagnostic,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
textvariable=self.LabelI2CReciveGoodTextvariable,
font=LARGE_FONT,
borderwidth = 4,
background=self.ButtonSystemColorActiveBackground)#"grey")
self.LabelI2CReciveGood.extra = "LabelI2CReciveGood"
self.LabelI2CReciveChecksumErrorTextvariable = tk.StringVar()
self.LabelI2CReciveChecksumError = tk.Label(master=self.FrameDiagnostic,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
textvariable=self.LabelI2CReciveChecksumErrorTextvariable,
font=LARGE_FONT,
borderwidth = 4,
background=self.ButtonSystemColorActiveBackground)#"grey")
self.LabelI2CReciveChecksumError.extra = "LabelI2CReciveChecksumError"
self.LabelI2CReciveHardwareErrorTextvariable = tk.StringVar()
self.LabelI2CReciveHardwareError = tk.Label(master=self.FrameDiagnostic,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
textvariable=self.LabelI2CReciveHardwareErrorTextvariable,
font=LARGE_FONT,
borderwidth = 4,
background=self.ButtonSystemColorActiveBackground)#"grey")
self.LabelI2CReciveHardwareError.extra = "LabelI2CReciveHardwareError"
self.LabelI2CSendGoodTextvariable = tk.StringVar()
self.LabelI2CSendGood = tk.Label(master=self.FrameDiagnostic,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
textvariable=self.LabelI2CSendGoodTextvariable,
font=LARGE_FONT,
borderwidth = 4,
background=self.ButtonSystemColorActiveBackground)#"grey")
self.LabelI2CSendGood.extra = "LabelI2CSendGood"
self.LabelI2CSendHardwareErrorTextvariable = tk.StringVar()
self.LabelI2CSendHardwareError = tk.Label(master=self.FrameDiagnostic,
anchor=tk.W, # Align the text left (West)
padx = 10, # Space left
textvariable=self.LabelI2CSendHardwareErrorTextvariable,
font=LARGE_FONT,
borderwidth = 4,
background=self.ButtonSystemColorActiveBackground)#"grey")
self.LabelI2CSendHardwareError.extra = "LabelI2CSendHardwareError"
""" Button Clear counter I2C """
self.ButtonClearCounterI2C = tk.Button(master=self.FrameDiagnostic,
text="Clear Counter",
activeforeground="green",
command=lambda: self.ButtonDiagnosticPressed("ButtonClearCounterI2C"))
self.ButtonClearCounterI2C.extra = "ButtonClearCounterI2C"
""" #################################################################################### """
""" Call methode poll100. Methode calles itself every 100ms """
self.poll100()
""" ######################################################################################## """
""" End INIT, End Constructor """
""" ######################################################################################## """
""" ######################################################################################## """
""" Methode poll100 """
def poll100(self):
# Local variable
GUIReadActualPos = [0, 0, 0, 0, 0, 0, 0, 0, # 16 Byte actual position axis
0, 0, 0, 0, 0, 0, 0, 0]
ActualPositionFloat = 0.0
StringActualPos = ""
StringTmp = ""
EmergencyStopActive = False
GUIReadActualStep = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 100 Byte string actual step
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,]
StringActualStep = ""
TmpValue = 0
GUIReadActualLineNumberFile = 0
GUIReadDigitalStates = 0
GUIReadActualState = 0
StringElapsedTimeProgram = ""
StringDateTime = ""
GUIReadI2CReciveGood = 0
GUIReadI2CReciveChecksumError = 0
GUIReadI2CReciveHardwareError = 0
GUIReadI2CSendGood = 0
GUIReadI2CSendHardwareError = 0
StringDiagnostic = ""
""" Read shared memory """
with lock:
# Mill -> GUI read 16 values actual position
GUIReadActualPos[0] = ComGUIArrayInt[16]
GUIReadActualPos[1] = ComGUIArrayInt[17]
GUIReadActualPos[2] = ComGUIArrayInt[18]
GUIReadActualPos[3] = ComGUIArrayInt[19]
GUIReadActualPos[4] = ComGUIArrayInt[20]
GUIReadActualPos[5] = ComGUIArrayInt[21]
GUIReadActualPos[6] = ComGUIArrayInt[22]
GUIReadActualPos[7] = ComGUIArrayInt[23]
GUIReadActualPos[8] = ComGUIArrayInt[24]
GUIReadActualPos[9] = ComGUIArrayInt[25]
GUIReadActualPos[10] = ComGUIArrayInt[26]
GUIReadActualPos[11] = ComGUIArrayInt[27]
GUIReadActualPos[12] = ComGUIArrayInt[28]
GUIReadActualPos[13] = ComGUIArrayInt[29]
GUIReadActualPos[14] = ComGUIArrayInt[30]
GUIReadActualPos[15] = ComGUIArrayInt[31]
# Mill -> GUI read actual line number in file
GUIReadActualLineNumberFile = ComGUIArrayInt[8]
# Mill -> GUI State. 0=Idle, 1=Program active, 2=Read file active
GUIReadActualState = ComGUIArrayInt[9]
# Mill -> GUI Digital states
GUIReadDigitalStates = ComGUIArrayInt[10]
# Mill -> GUI Diagnostic data
GUIReadI2CReciveGood = ComGUIArrayInt[11] # Mill -> GUI Diagnostic I2C Recive good
GUIReadI2CReciveChecksumError = ComGUIArrayInt[12] # Mill -> GUI Diagnostic I2C Recive checksum error
GUIReadI2CReciveHardwareError = ComGUIArrayInt[13] # Mill -> GUI Diagnostic I2C Recive hardware error
GUIReadI2CSendGood = ComGUIArrayInt[14] # Mill -> GUI Diagnostic I2C Send good
GUIReadI2CSendHardwareError = ComGUIArrayInt[15] # Mill -> GUI Diagnostic I2C Send hardware error
# Mill -> GUI read 100 values string actual step
for i in range(99):
GUIReadActualStep[i] = ComGUIArrayIntStringActualStep[i]
# GUI -> Mill Mill Spindle speed in manual mode
ComGUIArrayInt[2] = self.SpindleSpeedmanualMode
""" Emergency stop button pressed """
EmergencyStopActive = False
if GUIReadDigitalStates & 8 != 0: # Bit 3 = Emergency stop button
EmergencyStopActive = True
if EmergencyStopActive == True and self.ProgramActive == True:
with lock:
ComGUIArrayInt[0] = 3 # 1=Command read file, 2=Command Start program, 3=Command Stop program
""" Program active, elapsed time duration program """
# Mill -> GUI State. 0=Idle, 1=Program active, 2=Read file active
# Program is active
if GUIReadActualState == 1 and self.ProgramActive == False:
self.ProgramActive = True
self.PulseProgramActiveOff = True
self.StartTimeProgram = time.time()
# Idle mode
if GUIReadActualState == 0:
self.ProgramActive = False
self.ReadFileActive = False
# Elapsed time
if self.ProgramActive == True:
self.ElapsedTimeProgram = int(time.time() - self.StartTimeProgram)
""" Program active off """
# Negaive pulse ProgramActive, chage background from orange to system color, set text to start
if self.PulseProgramActiveOff == True and self.ProgramActive == False:
self.PulseProgramActiveOff = False
self.ButtonStart.config(background=self.ButtonSystemColorBackground)
self.ButtonStart.config(activebackground=self.ButtonSystemColorActiveBackground)
self.ButtonStart.config(text="Start")
""" Read file active """
# Mill -> GUI State. 0=Idle, 1=Program active, 2=Read file active
# Read file is active
if GUIReadActualState == 2 and self.ReadFileActive == False:
self.ReadFileActive = True
self.PulseReadFileActiveOff = True
# Chage background button open file to orange
self.ButtonOpenFile.config(background="orange")
self.ButtonOpenFile.config(activebackground="orange")
""" Read file off """
# Negaive pulse ReadFileActive, chage background button open file to system color
if self.PulseReadFileActiveOff == True and self.ReadFileActive == False:
self.PulseReadFileActiveOff = False
# Chage background button open file to system color
self.ButtonOpenFile.config(background=self.ButtonSystemColorBackground)
self.ButtonOpenFile.config(activebackground=self.ButtonSystemColorActiveBackground)
""" Disable, enable buttons """
if self.ProgramActive == True:
self.ButtonManual['state'] = tk.DISABLED
self.ButtonOpenFile['state'] = tk.DISABLED
if self.ReadFileActive == True:
self.ButtonManual['state'] = tk.DISABLED
self.ButtonStart['state'] = tk.DISABLED
if self.ManualMode == True:
self.ButtonOpenFile['state'] = tk.DISABLED
self.ButtonStart['state'] = tk.DISABLED
if EmergencyStopActive == True:
self.ButtonStart['state'] = tk.DISABLED
if self.ReadFileActive == True:
self.ButtonOpenFile['state'] = tk.DISABLED
if self.ProgramActive == False and self.ReadFileActive == False:
self.ButtonManual['state'] = tk.NORMAL
if self.ManualMode == False and self.ProgramActive == False and self.ReadFileActive == False:
self.ButtonOpenFile['state'] = tk.NORMAL
if self.ManualMode == False and self.ReadFileActive == False and EmergencyStopActive == False and self.FileLoadedFirstTime == True:
self.ButtonStart['state'] = tk.NORMAL
""" Update actual position """
# In frame main or manual if visible """
if self.FrameMainAttributes.visible == True or self.FrameManualAttributes.visible == True:
""" Actual positions """
# Actual pos X with 4 decimal places
ActualPositionFloat = CalculateActualPosition(GUIReadActualPos[0], GUIReadActualPos[1], \
GUIReadActualPos[2], GUIReadActualPos[3])
StringActualPos = "X: %.4f" % ActualPositionFloat
self.LabelActualPosXTextvariable.set(StringActualPos)
# Actual pos Y with 4 decimal places
ActualPositionFloat = CalculateActualPosition(GUIReadActualPos[4], GUIReadActualPos[5], \
GUIReadActualPos[6], GUIReadActualPos[7])
StringActualPos = "Y: %.4f" % ActualPositionFloat
self.LabelActualPosYTextvariable.set(StringActualPos)
# Actual pos Z with 4 decimal places
ActualPositionFloat = CalculateActualPosition(GUIReadActualPos[8], GUIReadActualPos[9], \
GUIReadActualPos[10], GUIReadActualPos[11])
StringActualPos = "Z: %.4f" % ActualPositionFloat
self.LabelActualPosZTextvariable.set(StringActualPos)
""" Update frame main if visible """
if self.FrameMainAttributes.visible == True: