-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgsv8.py
More file actions
1512 lines (1190 loc) · 53.2 KB
/
gsv8.py
File metadata and controls
1512 lines (1190 loc) · 53.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
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
# -*- coding: utf-8 -*-
"""
Datum 01.2016
@author: ME-Meßsysteme GmbH, Robert Bremsat, Dennis Rump
@version 1.2
"""
from ThreadSafeVar import TSVar
__author__ = 'Robert bremsat & Dennis Rump'
###############################################################################
#
# The MIT License (MIT)
#
# Copyright (c) 2015 ME-Meßsysteme GmbH
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# Hiermit wird unentgeltlich, jeder Person, die eine Kopie der Software
# und der zugehörigen Dokumentationen (die "Software") erhält, die
# Erlaubnis erteilt, uneingeschränkt zu benutzen, inklusive und ohne
# Ausnahme, dem Recht, sie zu verwenden, kopieren, ändern, fusionieren,
# verlegen, verbreiten, unter-lizenzieren und/oder zu verkaufen, und
# Personen, die diese Software erhalten, diese Rechte zu geben, unter
# den folgenden Bedingungen:
#
# Der obige Urheberrechtsvermerk und dieser Erlaubnisvermerk sind in
# alle Kopien oder Teilkopien der Software beizulegen.
#
# DIE SOFTWARE WIRD OHNE JEDE AUSDRÜCKLICHE ODER IMPLIZIERTE GARANTIE
# BEREITGESTELLT, EINSCHLIESSLICH DER GARANTIE ZUR BENUTZUNG FÜR DEN
# VORGESEHENEN ODER EINEM BESTIMMTEN ZWECK SOWIE JEGLICHER
# RECHTSVERLETZUNG, JEDOCH NICHT DARAUF BESCHRÄNKT. IN KEINEM FALL SIND
# DIE AUTOREN ODER COPYRIGHTINHABER FÜR JEGLICHEN SCHADEN ODER SONSTIGE
# ANSPRUCH HAFTBAR ZU MACHEN, OB INFOLGE DER ERFÜLLUNG VON EINEM
# VERTRAG, EINEM DELIKT ODER ANDERS IM ZUSAMMENHANG MIT DER BENUTZUNG
# ODER SONSTIGE VERWENDUNG DER SOFTWARE ENTSTANDEN.
#
###############################################################################
import copy
import logging
import threading
from queue import Queue
from collections import deque
import time
import serial
from GSV6_FrameRouter import FrameRouter
from GSV6_Protocol import GSV_6Protocol
from GSV6_SeriallLib import GSV6_seriall_lib
from GSV_BasicMeasurement import BasicMeasurement
'''
from twisted.internet import reactor
from twisted.internet.serialport import SerialPort
import sys
from twisted.internet.error import ReactorAlreadyInstalledError
'''
# load default Logging config
from GSV_Exceptions import GSV6_ConversionError_Exception, GSV_CommunicationException
logging.basicConfig()
useTwisted = False
class ThreadingReadFromSerial(threading.Thread):
def __init__(self, gsvSerialPort, serialProtocol):
threading.Thread.__init__(self)
self.gsvSerialPort = gsvSerialPort
self.serialProtocol = serialProtocol
self.runnng = True
self.setDaemon(True)
def run(self):
while (self.runnng):
if (serial.VERSION[0] == '2'):
bytesToRead = self.gsvSerialPort.inWaiting()
else:
bytesToRead = self.gsvSerialPort.in_waiting
if (bytesToRead > 0):
self.serialProtocol.dataReceived(bytearray(self.gsvSerialPort.read(bytesToRead)))
#time.sleep(0.001)
def stop(self):
self.runnng = False
class gsv8:
"""
Die Klasse gsv8 stellt alle GSV-8 Methoden zur Verfügung. Sie müssen in Ihrem Python Script ein Objekt für jeden
GSV-8 erstellen, um ein Objekt zu erzeugen verwenden Sie Variable = gsv8(port, baudrate)
Sie können mehrere GSV8-Objekte erzeugen.
:param port: Name des zu verwenden seriellen ports
:param baudrate: Bautrate
"""
_gsvSerialPort = None
# The Queue-Object is an threadsafe FIFO Buffer.
# Operations like put and get are atomic
# this queue holds all incomming complete Frames
_frameInBuffer = Queue(50)
# this queue holds the ordered config requests
_antwortQueue = Queue(50)
# _messwertRotatingQueue = deque([], 1)
_lastMesswert = TSVar()
# GSV Lib
_gsvLib = None
transmissionIsRunning = True
def __init__(self, port, baudrate):
logging.getLogger('gsv8').setLevel(logging.INFO)
logging.getLogger('gsv8').info('Start with config: Serialport: {}; Baudrate: {};'.format(port, baudrate))
'''
if (useTwisted):
if sys.platform == 'win32':
# on windows, we need to use the following reactor for serial support
# http://twistedmatrix.com/trac/ticket/3802
##
from twisted.internet import win32eventreactor
try:
win32eventreactor.install()
except ReactorAlreadyInstalledError:
pass
'''
if (not useTwisted):
self._gsvSerialPort = serial.Serial()
self._gsvSerialPort.baudrate = baudrate
self._gsvSerialPort.port = port
self._gsvSerialPort.parity = serial.PARITY_NONE
self._gsvSerialPort.stopbits = serial.STOPBITS_ONE
self._gsvSerialPort.bytesize = 8
self._gsvSerialPort.timeout = 1
self._gsvSerialPort.open()
self._gsvLib = GSV6_seriall_lib();
# create GSV6 Serial-Protocol-Object
self.serialProtocol = GSV_6Protocol(self._frameInBuffer, self._antwortQueue)
if (useTwisted):
'''
try:
self._gsvSerialPort = SerialPort(self.serialProtocol, port, reactor, baudrate=baudrate)
except Exception as e:
logging.getLogger('gsv8t').critical('Could not open serial port: {0}. exit!'.format(e))
raise Exception()
'''
else:
self.serialReadThread = ThreadingReadFromSerial(self._gsvSerialPort, self.serialProtocol)
# create an router object/thread
# self.router = FrameRouter(self._frameInBuffer, self._antwortQueue, self._messwertRotatingQueue, self._gsvLib)
self.router = FrameRouter(self._frameInBuffer, self._antwortQueue, self._lastMesswert, self._gsvLib)
# start threaded read from serial
if (not useTwisted):
self.serialReadThread.start()
# start frame-router-thread
self.router.start()
result = self.StopTransmission()
if (result[0] == 0x00):
logging.getLogger('gsv8').info('GSV8 detected and stopped.')
else:
logging.getLogger('gsv8').critical('some error occurred; GSV answer: ' + str(result))
def __del__(self):
if (not useTwisted):
self.serialReadThread.stop()
self.router.stop()
self.router.stopCSVRecording()
def isResultOk(self, result):
'''
Die Methode erhält die Ergebnisliste (AntwortErrorCode und AntwortErrorText) und gibt True zurück, wenn kein Fehler vorliegt.
:return: True wenn AntwortErrorCode == 0x00; False wenn AntwortErrorCode != 0x00
:rtype: bool
'''
if (result[0] == 0):
return True
else:
return False
def StopTransmission(self):
'''
Die Methode StopTransmission teilt dem GSV mit, das die Messwertübertragung angehalten werden soll.
Sobald der Befehl abgesendet wird sendet der GSV8 keine Messdaten mehr über die serielle Schnittstelle.
Sie können StartTransmission verwenden um die Übertragung erneut zu starten.
Verwenden Sie getValue um einzel Werte abzurufen.
:return: AntwortCode und AntwortErrorText
:rtype: liste
'''
if not self.transmissionIsRunning:
return
# erstelle zu sendene Bytefolge für StopTransmission
output = self._gsvLib.buildStopTransmission()
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0x00):
self.transmissionIsRunning = False
result = [antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText()]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def StartTransmission(self):
'''
Die Methode StartTransmission teilt dem GSV mit, das er Messdaten senden darf.
:return: AntwortCode und AntwortErrorText
:rtype: liste
'''
if self.transmissionIsRunning:
return
# erstelle zu sendene Bytefolge für StartTransmission
output = self._gsvLib.buildStartTransmission()
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0x00):
self.transmissionIsRunning = True
result = [antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText()]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def setTXmodefloat(self):
'''
Setzt float als Messwert-Datenformat
:return: AntwortCode und AntwortErrorText
:rtype: the return type description
'''
# command = array.array('B', [0xAA, 0x93, 0x81, 0x03, 0x00, 0x10, 0x85]).tostring()
# self.gsvSerialPort.write(command)
# erstelle zu sendene Bytefolge für setTXmodefloat
output = self._gsvLib.buildSetTXModeToFloat()
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0x00):
result = [antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText()]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def ReadValue(self):
'''
Die Methode ruft einmal Messwerte vom GSV ab (one shot).
:return: AntwortCode und AntwortErrorText
:rtype: liste
'''
if(self.transmissionIsRunning):
# return self._messwertRotatingQueue[0]
result = copy.deepcopy(self._lastMesswert.getVar())
else:
# alte Messwerte löschen
# self._messwertRotatingQueue.clear()
self._lastMesswert.setVar(None)
# erstelle zu sendene Bytefolge für GetValue (OneShot)
output = self._gsvLib.buildGetValue()
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
# hier keine Antwort!!!
# [seconds]
abort_after = 2
start = time.time()
result = None
# auf Messwert warten, aber maximal 2 sec.
while True:
try:
#result = copy.deepcopy(self._messwertRotatingQueue.pop())
# result = copy.copy(self._messwertRotatingQueue[0])
tmp = self._lastMesswert.getVar()
if(tmp != None):
result = copy.copy(tmp)
break
except IndexError:
pass
# timeout berechnung
delta = time.time() - start
if delta >= abort_after:
break
# return BasicMeasurement(result)
return BasicMeasurement(result)
def SetZero(self, channel):
'''
Die Methode setzt die Kanäle des GSV null.
:return: AntwortCode und AntwortErrorText
:rtype: liste
'''
# erstelle zu sendene Bytefolge für SetZero
output = self._gsvLib.buildWriteSetZero(channel)
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0x00):
result = [antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText()]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def getDIOdirection(self, gruppe):
'''
Ruft die DIOdirection vom GSV ab
:param gruppe: Muss die DIO Gruppennummer beinhalten
:type gruppe: uint8
:return: AntwortCode und AntwortErrorText
:rtype: liste
'''
# erstelle zu sendene Bytefolge für getDIOdirection
output = self._gsvLib.buildGetDIOdirection(gruppe)
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0x00):
result = antwortFrame.getPayload()[0]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def isDIOgroupOutput(self, gruppe):
'''
gibt True zurueck, wenn die Direction der gewaehlten DIO Gruppe als Output konfiguriert ist.
:param gruppe: Muss die DIO Gruppennummer beinhalten
:type gruppe: uint8
:return: True wenn die Direction der DIO Gruppe Output ist, False wenn die Direction der DIO Gruppe kein Output ist (als Input)
:rtype: bool
'''
if (self.getDIOdirection(gruppe) == 0x00):
return True
else:
return False
def isDIOgroupInput(self, gruppe):
'''
gibt True zurueck, wenn die Direction der gewaehlten DIO Gruppe als Input konfiguriert ist.
:param gruppe: Muss die DIO Gruppennummer beinhalten
:type gruppe: uint8
:return: True wenn die Direction der DIO Gruppe Input ist, False wenn die Direction der DIO Gruppe kein Input ist (als Output)
:rtype: bool
'''
return not self.isDIOgroupOutput(gruppe)
def setDIOdirection(self, gruppe, direction):
'''
setzt die DIOdirection der jeweiligen Gruppe vom GSV
:param gruppe: Muss die DIO Gruppennummer beinhalten
:param direction: Muss die DIO Gruppendirection beinhalten
:type gruppe: uint8
:type direction: uint8
:return: AntwortErrorCode und AntwortErrorText
:rtype: liste
'''
# erstelle zu sendene Bytefolge für WriteDataRate
output = self._gsvLib.buildSetDIOdirection(gruppe, direction)
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0x00):
result = [antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText()]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def setDIOgroupToOutput(self, gruppe):
'''
Setzt die Direction der Gruppe zu Output
:param gruppe: Muss die DIO Gruppennummer beinhalten
:type gruppe: uint8
:return: AntwortErrorCode und AntwortErrorText
:rtype: liste
'''
return self.setDIOdirection(gruppe, 0)
def setDIOgroupToInput(self, gruppe):
'''
Setzt die Direction der Gruppe zu Input
:param gruppe: Muss die DIO Gruppennummer beinhalten
:type gruppe: uint8
:return: AntwortErrorCode und AntwortErrorText
:rtype: liste
'''
return self.setDIOdirection(gruppe, 1)
def getDIOlevel(self, IOPin):
'''
Ruft das jeweilige DIOlevel vom GSV ab
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:type IOPin: uint8
:return: 0 wenn Low; 1 wenn high
:rtype: uint8
'''
# erstelle zu sendene Bytefolge für getDIOlevel
output = self._gsvLib.buildGetDIOlevel(IOPin)
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0x00):
result = self._gsvLib.convertToUint16_t(antwortFrame.getPayload())[0]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def setDIOlevel(self, IOPin, level):
'''
Setzt das DIO level am gewünschten Pin
level 1 = high 0 low
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:param level: high=1; low=0
:type IOPin: uint8
:type level: uint8
:return: AntwortErrorCode und AntwortErrorText
:rtype: liste
'''
# erstelle zu sendene Bytefolge für WriteDataRate
output = self._gsvLib.buildSetDIOlevel(IOPin, level)
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0x00):
result = [antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText()]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def setPinToHigh(self, IOPin):
'''
Setzt IOPin auf High
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:type IOPin: uint8
:return: AntwortErrorCode und AntwortErrorText
:rtype: liste
'''
return self.setDIOlevel(IOPin, 1)
def setPinToLow(self, IOPin):
'''
Setzt IOPin auf Low
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:type IOPin: uint8
:return: AntwortErrorCode und AntwortErrorText
:rtype: liste
'''
return self.setDIOlevel(IOPin, 0)
def isPinHigh(self, IOPin):
'''
IOPin level Abfrage
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:type IOPin: uint8
:return: True wenn IOPin High; False wenn IOPin Low
:rtype: bool
'''
if (IOPin == 0):
raise Exception('Dieser Befehl ist nicht auf alle Kanaele gleichzeitig anwendbar.')
if (self.getDIOlevel(IOPin) == 0):
return False
else:
return True
def isPinLow(self, IOPin):
'''
IOPin level Abfrage
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:type IOPin: uint8
:return: True wenn IOPin Low; False wenn IOPin High
:rtype: bool
'''
return not self.isPinHigh(IOPin)
def getDIOinitialLevel(self, IOPin):
'''
Ruft das jeweilige initial DIOlevel vom GSV ab
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:type IOPin: uint8
:return: 0 wenn Low; 1 wenn high
:rtype: uint8
'''
# erstelle zu sendene Bytefolge für getDIOlevel
output = self._gsvLib.buildGetDIOinitialLevel(IOPin)
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0x00):
result = self._gsvLib.convertToUint16_t(antwortFrame.getPayload())[0]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def setDIOinitialLevel(self, IOPin, level):
'''
Setzt das DIO level am gewünschten Pin
level 1 = high 0 low
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:param level: high=1; low=0
:type IOPin: uint8
:type level: uint8
:return: AntwortErrorCode und AntwortErrorText
:rtype: liste
'''
# erstelle zu sendene Bytefolge für WriteDataRate
output = self._gsvLib.buildSetDIOinitialLevel(IOPin, level)
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0x00):
result = [antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText()]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def writeDataRate(self, frequenz):
'''
Setzt die Datenrate in Hz
:param frequenz: Gibt die gewuenschte Frequenz in Hz an
:type frequenz: float
:return: AntwortErrorCode und AntwortErrorText
:rtype: liste
'''
# frequenz umwandeln
data = self._gsvLib.convertFloatToBytes(frequenz)
# erstelle zu sendene Bytefolge für WriteDataRate
output = self._gsvLib.buildWriteDataRate(data)
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0x00):
result = [antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText()]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def readDataRate(self):
'''
Ließt die Datenrate in Hz
:return: Frequenz in Hz
:rtype: float
'''
# erstelle zu sendene Bytefolge für WriteDataRate
output = self._gsvLib.buildGetDataRate()
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0):
result = self._gsvLib.convertToFloat(antwortFrame.getPayload())[0]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def isSixAxisMatrixActive(self):
'''
gibt den Status der Calibration Matrix wieder
:return: True wenn Matrix aktiv; False wenn Matrix inaktiv
:rtype: bool
'''
# erstelle zu sendene Bytefolge für WriteDataRate
output = self._gsvLib.buildGetMode()
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() != 0):
# return [antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText(), 'Get']
return False
# Fehlerall
if (len(antwortFrame.getPayload()) != 4):
return None
flags = antwortFrame.getPayload()
if ((flags[3] & 0x01) == 1):
return True
else:
return False
def setSixAxisMatrixActive(self, state):
'''
Setzt den Status der Calibration Matrix (aktiv oder inaktiv)
:param state: gewuenschter neuer Status der Matrix
:type state: bool
:return: AntwortErrorCode und AntwortErrorText
:rtype: liste
'''
# erstelle zu sendene Bytefolge für WriteDataRate
output = self._gsvLib.buildGetMode()
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() != 0):
return [antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText(), 'Get']
# Fehlerall
if (len(antwortFrame.getPayload()) != 4):
return None
flags = antwortFrame.getPayload()
if (state):
# set to active
flags[3] = flags[3] | 0x01
else:
# set to inactive
flags[3] = flags[3] & 0xFE
# erstelle zu sendene Bytefolge für WriteDataRate
output = self._gsvLib.buildSetMode(flags)
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
result = None
if (antwortFrame.getAntwortErrorCode() == 0):
[antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText()]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def writeDIOthreshold(self, IOPin, upper_or_lower_trigger, threshold_value):
'''
Setzt die oberen oder unteren Schwellwert für den angegeben IO Pin
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:param upper_or_lower_trigger: Lower=0; Upper=1
:param threshold_value: Schwellwert
:type IOPin: uint8
:type upper_or_lower_trigger: uint8
:type threshold_value: float
:return: AntwortErrorCode und AntwortErrorText
:rtype: liste
'''
# erstelle zu sendene Bytefolge für writeDIOthreshold
output = self._gsvLib.buildWriteDIOthreshold(IOPin, upper_or_lower_trigger, threshold_value)
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0x00):
result = [antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText()]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def writeLowerDIOthreshold(self, IOPin, threshold_value):
'''
Setzt den unteren Schwellwert des gegeben IOPin´s
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:param threshold_value: Schwellwert
:type IOPin: uint8
:type threshold_value: float
:return: AntwortErrorCode und AntwortErrorText
:rtype: liste
'''
return self.writeDIOthreshold(IOPin, 0, threshold_value)
def writeUpperDIOthreshold(self, IOPin, threshold_value):
'''
Setzt den oberen Schwellwert des gegeben IOPin´s
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:param threshold_value: Schwellwert
:type IOPin: uint8
:type threshold_value: float
:return: AntwortErrorCode und AntwortErrorText
:rtype: liste
'''
return self.writeDIOthreshold(IOPin, 1, threshold_value)
def readDIOthreshold(self, IOPin, upper_or_lower_trigger):
'''
Ließt die oberen oder unteren Schwellwert für den angegeben IOPin
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:param upper_or_lower_trigger: Lower=0; Upper=1
:type IOPin: uint8
:type upper_or_lower_trigger: uint8
:return: AntwortErrorCode und AntwortErrorText
:rtype: liste
'''
# erstelle zu sendene Bytefolge für readDIOthreshold
output = self._gsvLib.buildReadDIOthreshold(IOPin, upper_or_lower_trigger)
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0):
result = self._gsvLib.convertToFloat(antwortFrame.getPayload())[0]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def readLowerDIOthreshold(self, IOPin):
'''
Ließt den unteren Schwellwert des angegeben IOPin´s
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:type IOPin: uint8
:return: unterer Schwellwert
:rtype: float
'''
return self.readDIOthreshold(IOPin, 0)
def readUpperDIOthreshold(self, IOPin):
'''
Ließt den oberen Schwellwert des angegeben IOPin´s
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:type IOPin: uint8
:return: unterer Schwellwert
:rtype: float
'''
return self.readDIOthreshold(IOPin, 1)
def setUserScaleBySensor(self, kanal, sensor_messbereich, sensor_kennwert):
'''
Errechnet und setzt einen neuen ScalierungsFaktor fuer den jeweiligen DMS-Kanal
:param kanal: DMS-Kanal 1..8 oder 0
:param sensor_messbereich: Messbereich des Sensors
:param sensor_kennwert: IOPin Kennwert des Sensors
:type kanal: uint8
:type sensor_messbereich: float
:type sensor_kennwert: float
:return: AntwortErrorCode und AntwortErrorText
:rtype: liste
'''
# erstelle zu sendene Bytefolge für readDIOthreshold
output = self._gsvLib.buildReadInputType(kanal, 0xFF)
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0):
sensIndex = antwortFrame.getPayload()[0]
sense = self._gsvLib.convertToUint32_t(antwortFrame.getPayload()[1:])[0]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
newUserScale = (sensor_messbereich / sensor_kennwert) * (sense / 100)
# frequenz umwandeln
data = self._gsvLib.convertFloatToBytes(newUserScale)
# erstelle zu sendene Bytefolge für WriteUserScale
output = self._gsvLib.buildWriteUserScale(kanal, data)
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0x00):
result = [antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText()]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def setDIOtype(self, IOPin, dioType, assignedDMSchannel=0):
'''
Setzt DIOtype für den angegeben IO Pin
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:param dioType: DIO Type aus Datenblatt
:param assignedDMSchannel: zugehoeriger DMS-Kanal; default=0
:type IOPin: uint8
:type dioType: uint8
:type assignedDMSchannel: uint8
:return: AntwortErrorCode und AntwortErrorText
:rtype: liste
'''
# erstelle zu sendene Bytefolge für SetDIOtype
output = self._gsvLib.buildSetDIOtype(IOPin, dioType, assignedDMSchannel)
# print 'output: ' + ' '.join(format(x, '02x') for x in bytearray(output))
# sende Daten via serialport
self._gsvSerialPort.write(output)
# ersten AntwortFrame aus der Queue holen
antwortFrame = self._antwortQueue.get()
# returnstatment erzeugen
if (antwortFrame.getAntwortErrorCode() == 0x00):
result = [antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText()]
else:
raise GSV_CommunicationException(antwortFrame.getAntwortErrorCode(), antwortFrame.getAntwortErrorText())
return result
def setOutputHighByThreshold(self, IOPin, assignedDMSchannel):
'''
Setzt DIOtype für den angegeben IO Pin
Der gewaehlte IOPin wird auf high wenn Messwert unterhalb des unteren Schwellwerts faellt und low wenn er ueber den oberen Schwellwert steigt
:parameter: IOPin: 1..16; assignedDMSchannel uint8
:rtype: [antwortFrame.ErrorCode, AntwortErrorText]
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:param assignedDMSchannel: zugehoeriger DMS-Kanal; default=0
:type IOPin: uint8
:type assignedDMSchannel: uint8
:return: AntwortErrorCode und AntwortErrorText
:rtype: liste
'''
# siehe Tabelle Typen der digitalen Ein- und Ausgaenge des GSV-8 pos. 11
newDIOtype = bytearray([0x01, 0x00, 0x00])
return self.setDIOtype(IOPin, newDIOtype, assignedDMSchannel)
def setOutputLowByThreshold(self, IOPin, assignedDMSchannel):
'''
Setzt DIOtype für den angegeben IO Pin
Der gewaehlte IOPin wir auf low wenn Messwert unterhalb des unteren Schwellwerts faellt und high wenn er ueber den oberen Schwellwert steigt
:param IOPin: IOPin 1..16 (1.1 - 4.4)
:param assignedDMSchannel: zugehoeriger DMS-Kanal; default=0
:type IOPin: uint8
:type assignedDMSchannel: uint8
:return: AntwortErrorCode und AntwortErrorText