Skip to content

Commit 2cddcf2

Browse files
authored
Merge pull request fossasia#51 from viveksb007/development
added reference for values in MCP4728.py and fixed some warnings
2 parents 83710f4 + ee92d0d commit 2cddcf2

File tree

3 files changed

+61
-48
lines changed

3 files changed

+61
-48
lines changed

PSL/Peripherals.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -276,29 +276,32 @@ def read_repeat(self):
276276
self.H.__sendByte__(CP.I2C_READ_MORE)
277277
val = self.H.__getByte__()
278278
self.H.__get_ack__()
279+
return val
279280
except Exception as ex:
280281
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
281-
return val
282+
282283

283284
def read_end(self):
284285
try:
285286
self.H.__sendByte__(CP.I2C_HEADER)
286287
self.H.__sendByte__(CP.I2C_READ_END)
287288
val = self.H.__getByte__()
288289
self.H.__get_ack__()
290+
return val
289291
except Exception as ex:
290292
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
291-
return val
293+
292294

293295
def read_status(self):
294296
try:
295297
self.H.__sendByte__(CP.I2C_HEADER)
296298
self.H.__sendByte__(CP.I2C_STATUS)
297299
val = self.H.__getInt__()
298300
self.H.__get_ack__()
301+
return val
299302
except Exception as ex:
300303
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
301-
return val
304+
302305

303306
def readBulk(self, device_address, register_address, bytes_to_read):
304307
try:
@@ -626,9 +629,10 @@ def send8(self, value):
626629
self.H.__sendByte__(value) # value byte
627630
v = self.H.__getByte__()
628631
self.H.__get_ack__()
632+
return v
629633
except Exception as ex:
630634
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
631-
return v
635+
632636

633637
def send16(self, value):
634638
"""
@@ -651,9 +655,10 @@ def send16(self, value):
651655
self.H.__sendInt__(value) # value byte
652656
v = self.H.__getInt__()
653657
self.H.__get_ack__()
658+
return v
654659
except Exception as ex:
655660
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
656-
return v
661+
657662

658663
def send8_burst(self, value):
659664
"""
@@ -762,6 +767,7 @@ def __init__(self, H, vref=3.3, devid=0):
762767
self.CHANS = {'PCS': DACCHAN('PCS', [0, 3.3e-3], 0), 'PV3': DACCHAN('PV3', [0, 3.3], 1),
763768
'PV2': DACCHAN('PV2', [-3.3, 3.3], 2), 'PV1': DACCHAN('PV1', [-5., 5.], 3)}
764769
self.CHANNEL_MAP = {0: 'PCS', 1: 'PV3', 2: 'PV2', 3: 'PV1'}
770+
self.values = {'PV1': 0, 'PV2': 0, 'PV3': 0, 'PCS': 0}
765771

766772
def __ignoreCalibration__(self, name):
767773
self.CHANS[name].calibration_enabled = False
@@ -798,7 +804,8 @@ def __setRawVoltage__(self, name, v):
798804
'''
799805
val = self.CHANS[name].apply_calibration(v)
800806
self.I2C.writeBulk(self.addr, [64 | (CHAN.channum << 1), (val >> 8) & 0x0F, val & 0xFF])
801-
return CHAN.CodeToV(v)
807+
self.values[name] = CHAN.CodeToV(v)
808+
return self.values[name]
802809

803810
def __writeall__(self, v1, v2, v3, v4):
804811
self.I2C.start(self.addr, 0)
@@ -871,7 +878,7 @@ class NRF24L01():
871878
I2C_COMMANDS = 2
872879
I2C_TRANSACTION = 0 << 4
873880
I2C_WRITE = 1 << 4
874-
SCAN_I2C = 2 << 4
881+
I2C_SCAN = 2 << 4
875882
PULL_SCL_LOW = 3 << 4
876883
I2C_CONFIG = 4 << 4
877884
I2C_READ = 5 << 4
@@ -964,9 +971,10 @@ def rxchar(self):
964971
self.H.__sendByte__(CP.NRF_RXCHAR)
965972
value = self.H.__getByte__()
966973
self.H.__get_ack__()
974+
return value
967975
except Exception as ex:
968976
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
969-
return value
977+
970978

971979
def txchar(self, char):
972980
'''
@@ -989,9 +997,10 @@ def hasData(self):
989997
self.H.__sendByte__(CP.NRF_HASDATA)
990998
value = self.H.__getByte__()
991999
self.H.__get_ack__()
1000+
return value
9921001
except Exception as ex:
9931002
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
994-
return value
1003+
9951004

9961005
def flush(self):
9971006
'''
@@ -1031,9 +1040,10 @@ def read_register(self, address):
10311040
self.H.__sendByte__(address)
10321041
val = self.H.__getByte__()
10331042
self.H.__get_ack__()
1043+
return val
10341044
except Exception as ex:
10351045
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
1036-
return val
1046+
10371047

10381048
def get_status(self):
10391049
'''
@@ -1070,9 +1080,9 @@ def write_address(self, register, address):
10701080
self.H.__sendByte__(CP.NRFL01)
10711081
self.H.__sendByte__(CP.NRF_WRITEADDRESS)
10721082
self.H.__sendByte__(register)
1073-
self.H.__sendByte__(address & 0xFF);
1074-
self.H.__sendByte__((address >> 8) & 0xFF);
1075-
self.H.__sendByte__((address >> 16) & 0xFF);
1083+
self.H.__sendByte__(address & 0xFF)
1084+
self.H.__sendByte__((address >> 8) & 0xFF)
1085+
self.H.__sendByte__((address >> 16) & 0xFF)
10761086
self.H.__get_ack__()
10771087
except Exception as ex:
10781088
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
@@ -1085,9 +1095,9 @@ def selectAddress(self, address):
10851095
try:
10861096
self.H.__sendByte__(CP.NRFL01)
10871097
self.H.__sendByte__(CP.NRF_WRITEADDRESSES)
1088-
self.H.__sendByte__(address & 0xFF);
1089-
self.H.__sendByte__((address >> 8) & 0xFF);
1090-
self.H.__sendByte__((address >> 16) & 0xFF);
1098+
self.H.__sendByte__(address & 0xFF)
1099+
self.H.__sendByte__((address >> 8) & 0xFF)
1100+
self.H.__sendByte__((address >> 16) & 0xFF)
10911101
self.H.__get_ack__()
10921102
self.CURRENT_ADDRESS = address
10931103
if address not in self.sigs:

PSL/packet_handler.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,19 @@ def listPorts(self):
6262
return glob.glob('/dev/ttyACM*') + glob.glob('/dev/ttyUSB*')
6363

6464
def connectToPort(self, portname):
65-
try:
65+
import platform
66+
if platform.system() not in ["Windows", "Darwin"]:
6667
import socket
67-
self.blockingSocket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
68-
self.blockingSocket.bind('\0PSghhhLab%s' % portname)
69-
self.blockingSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
70-
except socket.error as e:
71-
self.occupiedPorts.add(portname)
72-
raise RuntimeError("Another program is using %s (%d)" % (portname))
68+
try:
69+
self.blockingSocket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
70+
self.blockingSocket.bind('\0PSghhhLab%s' % portname)
71+
self.blockingSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
72+
except socket.error as e:
73+
self.occupiedPorts.add(portname)
74+
raise RuntimeError("Another program is using %s (%d)" % (portname))
7375

7476
fd = serial.Serial(portname, 9600, stopbits=1, timeout=0.02)
75-
fd.read(100);
77+
fd.read(100)
7678
fd.close()
7779
fd = serial.Serial(portname, self.BAUD, stopbits=1, timeout=1.0)
7880
if (fd.inWaiting()):
@@ -172,9 +174,10 @@ def __getByte__(self):
172174
reads a byte from the serial port and returns it
173175
"""
174176
ss = self.fd.read(1)
175-
if len(ss):
176-
return CP.Byte.unpack(ss)[0]
177-
else:
177+
try:
178+
if len(ss):
179+
return CP.Byte.unpack(ss)[0]
180+
except Exception as ex:
178181
print('byte communication error.', time.ctime())
179182
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
180183
# sys.exit(1)
@@ -185,9 +188,10 @@ def __getInt__(self):
185188
returns an integer after combining them
186189
"""
187190
ss = self.fd.read(2)
188-
if len(ss) == 2:
189-
return CP.ShortInt.unpack(ss)[0]
190-
else:
191+
try:
192+
if len(ss) == 2:
193+
return CP.ShortInt.unpack(ss)[0]
194+
except Exception as ex:
191195
print('int communication error.', time.ctime())
192196
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
193197
# sys.exit(1)

PSL/sciencelab.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@ def start_one_channel_LA_backup__(self, trigger=1, channel='ID1', maximum_time=6
19381938
19391939
"""
19401940
try:
1941-
self.clear_buffer(0, self.MAX_SAMPLES / 2);
1941+
self.clear_buffer(0, self.MAX_SAMPLES / 2)
19421942
self.H.__sendByte__(CP.TIMING)
19431943
self.H.__sendByte__(CP.START_ONE_CHAN_LA)
19441944
self.H.__sendInt__(self.MAX_SAMPLES / 4)
@@ -2085,7 +2085,7 @@ def start_one_channel_LA(self, **args):
20852085
# trigger_mode same as channel_mode.
20862086
# default_value : 3
20872087
try:
2088-
self.clear_buffer(0, self.MAX_SAMPLES / 2);
2088+
self.clear_buffer(0, self.MAX_SAMPLES / 2)
20892089
self.H.__sendByte__(CP.TIMING)
20902090
self.H.__sendByte__(CP.START_ALTERNATE_ONE_CHAN_LA)
20912091
self.H.__sendInt__(self.MAX_SAMPLES / 4)
@@ -2167,7 +2167,7 @@ def start_two_channel_LA(self, **args):
21672167
trigger = 0
21682168

21692169
try:
2170-
self.clear_buffer(0, self.MAX_SAMPLES);
2170+
self.clear_buffer(0, self.MAX_SAMPLES)
21712171
self.H.__sendByte__(CP.TIMING)
21722172
self.H.__sendByte__(CP.START_TWO_CHAN_LA)
21732173
self.H.__sendInt__(self.MAX_SAMPLES / 4)
@@ -2176,13 +2176,13 @@ def start_two_channel_LA(self, **args):
21762176
self.H.__sendByte__((modes[1] << 4) | modes[0]) # Modes. four bits each
21772177
self.H.__sendByte__((chans[1] << 4) | chans[0]) # Channels. four bits each
21782178
self.H.__get_ack__()
2179-
n = 0;
2179+
n = 0
21802180
for a in self.dchans[:2]:
2181-
a.prescaler = 0;
2182-
a.length = self.MAX_SAMPLES / 4;
2183-
a.datatype = 'long';
2181+
a.prescaler = 0
2182+
a.length = self.MAX_SAMPLES / 4
2183+
a.datatype = 'long'
21842184
a.maximum_time = maximum_time * 1e6 # conversion to uS
2185-
a.mode = modes[n];
2185+
a.mode = modes[n]
21862186
a.channel_number = chans[n]
21872187
a.name = strchans[n]
21882188
n += 1
@@ -2221,7 +2221,7 @@ def start_three_channel_LA(self, **args):
22212221
22222222
"""
22232223
try:
2224-
self.clear_buffer(0, self.MAX_SAMPLES);
2224+
self.clear_buffer(0, self.MAX_SAMPLES)
22252225
self.H.__sendByte__(CP.TIMING)
22262226
self.H.__sendByte__(CP.START_THREE_CHAN_LA)
22272227
self.H.__sendInt__(self.MAX_SAMPLES / 4)
@@ -2289,7 +2289,7 @@ def start_four_channel_LA(self, trigger=1, maximum_time=0.001, mode=[1, 1, 1, 1]
22892289
Use :func:`fetch_long_data_from_LA` (points to read,x) to get data acquired from channel x.
22902290
The read data can be accessed from :class:`~ScienceLab.dchans` [x-1]
22912291
"""
2292-
self.clear_buffer(0, self.MAX_SAMPLES);
2292+
self.clear_buffer(0, self.MAX_SAMPLES)
22932293
prescale = 0
22942294
"""
22952295
if(maximum_time > 0.26):
@@ -2403,7 +2403,7 @@ def fetch_int_data_from_LA(self, bytes, chan=1):
24032403
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
24042404

24052405
t = np.trim_zeros(t)
2406-
b = 1;
2406+
b = 1
24072407
rollovers = 0
24082408
while b < len(t):
24092409
if (t[b] < t[b - 1] and t[b] != 0):
@@ -3277,7 +3277,7 @@ def load_equation(self, chan, function, span=None, **kwargs):
32773277
32783278
'''
32793279
if function == 'sine' or function == np.sin:
3280-
function = np.sin;
3280+
function = np.sin
32813281
span = [0, 2 * np.pi]
32823282
self.WType[chan] = 'sine'
32833283
elif function == 'tria':
@@ -3759,11 +3759,11 @@ def WS2812B(self, cols, output='CS1'):
37593759
self.H.__sendByte__(len(cols) * 3)
37603760
for col in cols:
37613761
# R=reverse_bits(int(col[0]));G=reverse_bits(int(col[1]));B=reverse_bits(int(col[2]))
3762-
R = col[0];
3763-
G = col[1];
3764-
B = col[2];
3765-
self.H.__sendByte__(G);
3766-
self.H.__sendByte__(R);
3762+
R = col[0]
3763+
G = col[1]
3764+
B = col[2]
3765+
self.H.__sendByte__(G)
3766+
self.H.__sendByte__(R)
37673767
self.H.__sendByte__(B)
37683768
# print(col)
37693769
self.H.__get_ack__()
@@ -3892,7 +3892,6 @@ def __stepperMotor__(self, steps, delay, direction):
38923892
except Exception as ex:
38933893
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)
38943894

3895-
t = time.time()
38963895
time.sleep(steps * delay * 1e-3) # convert mS to S
38973896

38983897
def stepForward(self, steps, delay):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy