From 566595669ef5403f011ada7be18337c912de9b07 Mon Sep 17 00:00:00 2001
From: Clement Remi <remi.clement@irstea.fr>
Date: Mon, 4 Apr 2022 20:56:57 +0200
Subject: [PATCH] Update ohmpi.py, updating RScheck function

---
 ohmpi.py | 66 ++++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 50 insertions(+), 16 deletions(-)

diff --git a/ohmpi.py b/ohmpi.py
index aed0e665..bb8f95e8 100644
--- a/ohmpi.py
+++ b/ohmpi.py
@@ -509,6 +509,7 @@ class OhmPi(object):
     def rs_check(self):
         """Check contact resistance.
         """
+        
         # create custom sequence where MN == AB
         nelec = self.sequence.max()  # number of elec used in the sequence
         quads = np.vstack([
@@ -517,25 +518,58 @@ class OhmPi(object):
             np.arange(nelec - 1) + 1,
             np.arange(nelec - 1) + 2
             ]).T
+              
         
-        # create backup TODO not good
-        export_path = self.pardict['export_path'].copy()
-        sequence = self.sequence.copy()
-
-        # assign new value
-        self.pardict['export_path'] = export_path.replace('.csv', '_rs.csv')
-        self.sequence = quads
+        for i in range(0, quads.shape[0]):
+                    quad = quads[i, :]  # quadrupole
+                    self.reset_mux()
+                    self.switch_mux_on(quad)
+                    pin0 = self.mcp.get_pin(0)
+                    pin0.direction = Direction.OUTPUT
+                    pin1 = self.mcp.get_pin(1)
+                    pin1.direction = Direction.OUTPUT
+                    pin0.value = False
+                    pin1.value = False
+                                       
+                    print(quad)                                       
+                    # call the switch_mux function to switch to the right electrodes
+                    self.ads_current = ads.ADS1115(self.i2c, gain=2/3, data_rate=860, address=0x48)
+                    # ADS1115 for voltage measurement (MN)
+                    self.ads_voltage = ads.ADS1115(self.i2c, gain=2/3, data_rate=860, address=0x49)
+                    pin1.value = True
+                    pin0.value = False
+                    time.sleep(0.2)
+                    A=AnalogIn(self.ads_current,ads.P0).voltage/(50 * self.r_shunt)
+                    B=-AnalogIn(self.ads_voltage,ads.P0,ads.P1).voltage*2.5
+                    R=B/A
+                    #print(B)
+                    #print(A)
+                    print(abs(round(R/1000,1)),"Kohm")
+                    self.switch_mux_off(quad)
+                    pin0.value = False
+                    pin1.value = False
+                    
         
-        # run the RS check
-        self.log_exec('RS check (check contact resistance)', level='debug')
-        self.measure()
         
-        # restore
-        self.pardict['export_path'] = export_path
-        self.sequence = sequence
-
-        # TODO if interrupted, we would need to restore the values
-        # TODO or we offer the possiblity in 'run_measurement' to have rs_check each time?
+#         # create backup TODO not good
+#         export_path = self.pardict['export_path']
+#         sequence = self.sequence.copy()
+# 
+#         # assign new value
+#         self.pardict['export_path'] = export_path.replace('.csv', '_rs.csv')
+#         self.sequence = quads
+#         print(self.sequence)
+#         
+#         # run the RS check
+#         self.log_exec('RS check (check contact resistance)', level='debug')
+#         self.measure()
+#         
+#         # restore
+#         self.pardict['export_path'] = export_path
+#         self.sequence = sequence
+# 
+#         # TODO if interrupted, we would need to restore the values
+#         # TODO or we offer the possiblity in 'run_measurement' to have rs_check each time?
 
     @staticmethod
     def append_and_save(fname, last_measurement):
-- 
GitLab