Navigation Menu

Skip to content

Commit

Permalink
[ref] Final major change for v1.3 refactory
Browse files Browse the repository at this point in the history
  • Loading branch information
Dad0u committed Apr 24, 2017
1 parent 927bd41 commit a21d3f1
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 634 deletions.
2 changes: 1 addition & 1 deletion clean.sh
Expand Up @@ -2,7 +2,7 @@
echo "This script will remove every compiled files, pyc and dist-packages"
echo "related to Crappy. RUN AT YOUR OWN RISK"
echo "This script requires trash-cli package and sudo access"
echo "Continue?"
echo "Continue? (y/[n])"
read conf
if [ "$conf" != "y" ];then
exit 0
Expand Down
12 changes: 11 additions & 1 deletion crappy/inout/__init__.py
@@ -1,9 +1,19 @@
#coding: utf-8
from __future__ import absolute_import

from .._global import NotInstalled
from .inout import InOut,MetaIO

from .agilent34420A import Agilent34420A
from .arduino import Arduino
from .comedi import Comedi
from .labjackT7 import Labjack_T7
from .labjackUE9 import Labjack_UE9
from .comedi import Comedi
try:
from .openDAQ import OpenDAQ
except ImportError:
openDAQ = NotInstalled('OpenDAQ')

inout_list = MetaIO.IOclasses
in_list = MetaIO.Iclasses
in_list.update(inout_list)
Expand Down
Expand Up @@ -2,21 +2,21 @@
## @addtogroup sensor
# @{

## @defgroup Agilent34420ASensor Agilent34420ASensor
## @defgroup Agilent34420A Agilent34420A
# @{

## @file _Agilent34420ASensor.py
## @file agilent34420A.py
# @brief Sensor class for Agilent34420A devices.
#
# @author Robin Siemiatkowski
# @version 0.1
# @date 29/06/2016
# @author Robin Siemiatkowski, Victor Couty
# @version 0.2
# @date 20/04/2017

import serial
from .inout import InOut


class Agilent34420ASensor(InOut):
class Agilent34420A(InOut):
"""Sensor class for Agilent34420A devices."""

def __init__(self, mode="VOLT", device='/dev/ttyUSB0', baudrate=9600, timeout=10):
Expand All @@ -37,7 +37,7 @@ def __init__(self, mode="VOLT", device='/dev/ttyUSB0', baudrate=9600, timeout=10
timeout : int or float, default = 10
Timeout for the serial connection.
"""
super(Agilent34420ASensor, self).__init__()
InOut.__init__(self)
## path to the device
self.device = device
## desired baudrate
Expand All @@ -46,11 +46,10 @@ def __init__(self, mode="VOLT", device='/dev/ttyUSB0', baudrate=9600, timeout=10
self.timeout = timeout
## desired value to measure
self.mode = mode
## Serial instance
self.ser = serial.Serial(port=self.device, baudrate=self.baudrate, timeout=self.timeout)
self.new()

def new(self):
def open(self):
self.ser = serial.Serial(port=self.device, baudrate=self.baudrate,
timeout=self.timeout)
self.ser.write("*RST;*CLS;*OPC?\n")
self.ser.write("SENS:FUNC \"" + self.mode + "\"; \n")
self.ser.write("SENS:" + self.mode + ":NPLC 2 \n")
Expand All @@ -62,20 +61,10 @@ def get_data(self):
"""
Read the signal, return False if error and print 'bad serial'.
"""
try:
self.ser.write("READ? \n")
# tmp = self.ser.readline()
tmp = self.ser.read(self.ser.in_waiting)
self.ser.flush()
# print tmp
return float(tmp)
except Exception as e:
print e
# self.ser.read(self.ser.inWaiting())
# print self.ser.inWaiting()
# self.ser.flush()
# time.sleep(0.5)
return False
self.ser.write("READ? \n")
tmp = self.ser.read(self.ser.in_waiting)
self.ser.flush()
return float(tmp)

def close(self):
"""
Expand Down
41 changes: 21 additions & 20 deletions crappy/inout/arduino.py
Expand Up @@ -12,7 +12,7 @@
from .inout import InOut

class MonitorFrame(tk.Frame):
def __init__(self, parent, *args, **kwargs):
def __init__(self, parent, **kwargs):
"""
A frame that displays everything enters the serial port.
Args:
Expand Down Expand Up @@ -51,15 +51,13 @@ def create_widgets(self, **kwargs):
self.top_frame.grid(row=0)
self.serial_monitor.grid(row=1)

def update_widgets(self, *args):
def update_widgets(self, arg):
if self.enabled_checkbox.get():
self.serial_monitor.insert("0.0", args[0]) # To insert at the top
else:
pass
self.serial_monitor.insert("0.0", arg) # To insert at the top


class SubmitSerialFrame(tk.Frame):
def __init__(self, parent, *args, **kwargs):
def __init__(self, parent, **kwargs):
"""
Frame that permits to submit to the serial port of arduino.
Args:
Expand Down Expand Up @@ -97,7 +95,7 @@ def create_widgets(self, **kwargs):
self.submit_label.grid(row=0, column=1)
self.submit_button.grid(row=0, column=2, sticky=tk.E)

def update_widgets(self, *args):
def update_widgets(self):
try:
message = self.queue.get(block=False)
except Empty:
Expand All @@ -114,7 +112,7 @@ def update_widgets(self, *args):


class MinitensFrame(tk.Frame):
def __init__(self, parent, *args, **kwargs):
def __init__(self, parent, **kwargs):
"""
Special frame used in case of a minitens machine.
"""
Expand Down Expand Up @@ -183,8 +181,8 @@ def create_widgets(self, **kwargs):
value="UNLOAD",
variable=self.unload_mode).grid(row=1, sticky=tk.W)

def update_widgets(self, *args):
if args[0] == "STOP":
def update_widgets(self, arg):
if arg == "STOP":
message = str({"mode": 0,
"vitesse": 255,
"boucle": 0})
Expand All @@ -197,7 +195,7 @@ def update_widgets(self, *args):


class ArduinoHandler(object):
def __init__(self, *args, **kwargs):
def __init__(self, port, baudrate, queue_process, width, fontsize, frames):
"""Special class called in a new process, that handles
connection between crappy and the GUI."""

Expand All @@ -206,12 +204,12 @@ def collect_serial(arduino, queue):
while True:
queue.put(arduino.readline())

self.port = args[0]
self.baudrate = args[1]
self.queue_process = args[2]
self.width = args[3]
self.fontsize = args[4]
self.frames = args[5]
self.port = port
self.baudrate = baudrate
self.queue_process = queue_process
self.width = width
self.fontsize = fontsize
self.frames = frames

self.arduino_ser = serial.Serial(port=self.port,
baudrate=self.baudrate)
Expand Down Expand Up @@ -286,7 +284,7 @@ def main_loop(self):


class Arduino(InOut):
def __init__(self, *args, **kwargs):
def __init__(self, **kwargs):
"""
Main class used ton interface Arduino, its GUI and crappy. For
reusability, make sure the program inside the arduino sends to the serial
Expand All @@ -301,14 +299,17 @@ def __init__(self, *args, **kwargs):
self.baudrate = kwargs.get("baudrate", 9600)
self.labels = kwargs.get("labels", None)
self.frames = kwargs.get("frames", ["monitor", "submit"])
self.width = kwargs.get("width", 100)
self.fontsize = kwargs.get("fontsize",11)

def open(self):
self.queue_get_data = Queue()
self.arduino_handler = Process(target=ArduinoHandler,
args=(self.port,
self.baudrate,
self.queue_get_data,
kwargs.get("width", 100),
kwargs.get("fontsize", 11),
self.width,
self.fontsize,
self.frames))
self.handler_t0 = time()
self.arduino_handler.start()
Expand Down
7 changes: 2 additions & 5 deletions crappy/inout/comedi.py
Expand Up @@ -23,7 +23,6 @@ class Comedi(InOut):
"""Comedi object, for IO with cards using comedi driver"""
def __init__(self, **kwargs):
InOut.__init__(self)
print("DEBUG Comedi Init")
self.default = {'device':'/dev/comedi0',
'subdevice':0,
'channels':[0],
Expand Down Expand Up @@ -87,7 +86,6 @@ def __init__(self, **kwargs):
def open(self):
"""Starts commmunication with the device, must be called before any
set_cmd or get_data"""
print("DEBUG Comedi open")
self.device = c.comedi_open(self.device_name)
for chan in self.channels:
chan['maxdata'] = c.comedi_get_maxdata(self.device, self.subdevice,
Expand Down Expand Up @@ -127,8 +125,7 @@ def get_data(self,channel="all"):
channel = [channel]
to_read = [self.channels[self.channels_dict[i]] for i in channel]

t = time()
data = []
data = [time()]
for chan in to_read:
data_read = c.comedi_data_read(self.device,
self.subdevice,
Expand All @@ -138,7 +135,7 @@ def get_data(self,channel="all"):

val = c.comedi_to_phys(data_read[1], chan['range_ds'], chan['maxdata'])
data.append(val*chan['gain']+chan['offset'])
return t,data
return data


def close(self):
Expand Down
47 changes: 0 additions & 47 deletions crappy/inout/command.py

This file was deleted.

0 comments on commit a21d3f1

Please sign in to comment.