-
Notifications
You must be signed in to change notification settings - Fork 0
/
xprotolab_controller.py
executable file
·98 lines (77 loc) · 2.63 KB
/
xprotolab_controller.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
#! /usr/bin/env python3
import serial
#import threading
#import time
import sys
from usbConnect import usbConnect
#~ print(serial.VERSION)
if sys.version_info >= (3, 0):
def data(string):
return bytes(string, 'utf-8')
#return serial.to_bytes(string)
else:
def data(string): return string
class XprotolabController:
'''Controller to manage de xprotolab'''
def __init__(self):
self.ser = serial.Serial()
self.connect()
def connect(self):
self.ser.baudrate = 115200
self.ser.port = usbConnect()
self.ser.bytesize = 8
self.ser.parity = 'N'
self.ser.stopbits = 1
print("Connecting to", self.ser.name)
self.ser.open()
if self.ser.isOpen():
print("Connected to port", self.ser.name)
else:
print("Can't connect to port")
self.ser.close()
def closeConnection(self):
self.ser.close()
def show_version(self):
self.ser.write(data('a'))
return self.ser.readline(4)
def RequestSettings(self):
self.ser.write(data('u'))
for byte in self.ser.readline(43):
print(byte)
#print("Channel 1 settings:")
#print("Channel Position: ",self.ser.readline(1))
#print("Bitfield: ",self.ser.readline(1))
#print("Channel Gain: ",self.ser.readline(1))
#
#print("Channel 2 settings:")
#print("Channel Position: ",self.ser.readline(1))
#print("Bitfield: ",self.ser.readline(1))
#print("Channel Gain: ",self.ser.readline(1))
#print("Channel D settings:")
#print("Channel Position: ",self.ser.readline(1))
#print("Input mask: ",self.ser.readline(1))
#print("Option: ",self.ser.readline(1))
#print("Decode parameter: ",self.ser.readline(1))
#print("Decode option: ",self.ser.readline(1))
#print("General settings: ",self.ser.readline(10))
#
#print("AWG settings: ",self.ser.readline(8))
#print("Extras: ",self.ser.readline(14))
def Request_CH1(self):
self.ser.write(data('r'))
return self.ser.readline(256)
def Request_CH2(self):
self.ser.write(data('s'))
return self.ser.readline(256)
def increaseCH1gain(self):
self.ser.write(data('7'))
def StopScope(self):
self.ser.write(data('f'))
def StartScope(self):
self.ser.write(data('g'))
def Set_Post_Trigger_value(self):
self.ser.write(data('j'))
def write_settings(self):
self.ser.write(data('b78'))
def restore_factory_settings(self):
self.ser.write(data('k'))