forked from YehyaSHARIF/Sensor_Characterization_Plateform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Testing_Sensor.py
63 lines (45 loc) · 1.51 KB
/
Testing_Sensor.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
"""
Created on Tue Jan 25 17:23:53 2022
@author: pchaillo and Yehya SHARIF
This file represents all required functions to initialise the tested sensor
and read the measured voltage of this sensor from the arduino.
"""
from Sensor import Sensor
import serial
import time
class Testing_Sensor(Sensor):
def flush(self):
"""
to update the measured data and get a new data at each 0.1 sec
Returns
-------
None.
"""
self.ser.flush()
self.ser.flushInput()
self.ser.flushOutput()
time.sleep(0.1)
def UpdateSensor(self,index):
"""
It's only to update and split the message of the arduino and get the output voltage
measured from the tested sensor in the experiment
Returns
-------
the measured value (the voltage in V)
"""
### to update the measured data and get a new data at each 0.1 sec
Sensor.flush(self)
###to split the arduino message and get the voltage only
ligne_raw = str(self.ser.readline())
# print(ligne_raw)
ligne_cut = ligne_raw.split("'")
ligne_cut2 = ligne_cut[1].split("\\")
ligne_cut3 = ligne_cut2[0].split(";")
#print(ligne_cut3[0]) # for debug
###
try:
self.value = float(ligne_cut3[index])
except:
print('Attention, lecture impossible')
def get_value(self):
return self.value