Skip to content

Commit b713437

Browse files
bessmanAlexander Bessman
authored andcommitted
Merge branch 'development' of https://github.com/fossasia/pslab-python into development
2 parents 5ebfada + 7c0153d commit b713437

File tree

4 files changed

+39
-25
lines changed

4 files changed

+39
-25
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pslab-python can be installed from PyPI:
2727

2828
**Note**: Linux users must either install a udev rule by running 'pslab install' as root, or be part of the 'dialout' group in order for pslab-python to be able to communicate with the PSLab device.
2929

30+
**Note**: Windows users who use the PSLab v6 device must download and install the CP210x Windows Drivers from the [Silicon Labs website](https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers?tab=downloads) in order for pslab-python to be able to communicate with the PSLab device.
31+
3032
**Note**: If you are only interested in using PSLab as an acquisition device without a display/GUI, only pslab-python needs to be installed. If you would like a GUI, install the [pslab-desktop app](https://github.com/fossasia/pslab-desktop) and follow the instructions of the Readme in that repo.
3133

3234

pslab/bus/uart.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ def _write_byte(self, data: int):
170170
self._device.send_byte(CP.UART_2)
171171
self._device.send_byte(CP.SEND_BYTE)
172172
self._device.send_byte(data)
173-
self._device.get_ack()
173+
174+
if self._device.firmware.major < 3:
175+
self._device.get_ack()
174176

175177
def _write_int(self, data: int):
176178
"""Write a single int to the UART bus.

pslab/protocol.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""TODO"""
22

3+
import enum
34
import struct
45

56

@@ -179,16 +180,16 @@
179180
FILL_BUFFER = Byte.pack(27)
180181

181182
# /*---------- BAUDRATE for main comm channel----*/
182-
SETBAUD = Byte.pack(12)
183-
BAUD9600 = Byte.pack(1)
184-
BAUD14400 = Byte.pack(2)
185-
BAUD19200 = Byte.pack(3)
186-
BAUD28800 = Byte.pack(4)
187-
BAUD38400 = Byte.pack(5)
188-
BAUD57600 = Byte.pack(6)
189-
BAUD115200 = Byte.pack(7)
190-
BAUD230400 = Byte.pack(8)
191-
BAUD1000000 = Byte.pack(9)
183+
SETBAUD_LEGACY = Byte.pack(12)
184+
BAUD9600_LEGACY = Byte.pack(1)
185+
BAUD14400_LEGACY = Byte.pack(2)
186+
BAUD19200_LEGACY = Byte.pack(3)
187+
BAUD28800_LEGACY = Byte.pack(4)
188+
BAUD38400_LEGACY = Byte.pack(5)
189+
BAUD57600_LEGACY = Byte.pack(6)
190+
BAUD115200_LEGACY = Byte.pack(7)
191+
BAUD230400_LEGACY = Byte.pack(8)
192+
BAUD1000000_LEGACY = Byte.pack(9)
192193

193194
# /*-----------NRFL01 radio module----------*/
194195
NRFL01 = Byte.pack(13)
@@ -229,7 +230,8 @@
229230
# --------COMMUNICATION PASSTHROUGHS--------
230231
# Data sent to the device is directly routed to output ports such as (SCL, SDA for UART)
231232

232-
PASSTHROUGHS = Byte.pack(15)
233+
PASSTHROUGHS = Byte.pack(12)
234+
PASSTHROUGHS_LEGACY = Byte.pack(15)
233235
PASS_UART = Byte.pack(1)
234236

235237
# /*--------STOP STREAMING------*/

pslab/sciencelab.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -272,30 +272,38 @@ def _write_data_address(self, address: int, value: int):
272272
self.send_int(value)
273273
self.get_ack()
274274

275-
def enable_uart_passthrough(self, baudrate: int, persist=False):
275+
def enable_uart_passthrough(self, baudrate: int):
276276
"""Relay all data received by the device to TXD/RXD.
277277
278-
If a period > 0.5 seconds elapses between two transmit/receive events,
279-
the device resets and resumes normal mode. This timeout feature has
280-
been implemented in lieu of a hard reset option.
281-
282278
Can be used to load programs into secondary microcontrollers with
283279
bootloaders such ATMEGA or ESP8266
284280
285281
Parameters
286282
----------
287283
baudrate : int
288-
Baudrate of the UART bus.
289-
persist : bool, optional
290-
If set to True, the device will stay in passthrough mode until the
291-
next power cycle. Otherwise(default scenario), the device will
292-
return to normal operation if no data is sent/received for a period
293-
greater than one second at a time.
284+
Baudrate of the UART2 bus.
294285
"""
286+
if self.firmware.major < 3:
287+
self._uart_passthrough_legacy(baudrate)
288+
else:
289+
self._uart_passthrough(baudrate)
290+
291+
def _uart_passthrough(self, baudrate: int) -> None:
295292
self.send_byte(CP.PASSTHROUGHS)
296293
self.send_byte(CP.PASS_UART)
297-
self.send_byte(1 if persist else 0)
298-
self.send_int(int(round(((64e6 / baudrate) / 4) - 1)))
294+
self.send_int(self._get_brgval(baudrate))
295+
self.interface.baudrate = baudrate
296+
297+
def _uart_passthrough_legacy(self, baudrate: int) -> None:
298+
self.send_byte(CP.PASSTHROUGHS_LEGACY)
299+
self.send_byte(CP.PASS_UART)
300+
disable_watchdog = 1
301+
self.send_byte(disable_watchdog)
302+
self.send_int(self._get_brgval(baudrate))
303+
304+
@staticmethod
305+
def _get_brgval(baudrate: int) -> int:
306+
return int((CP.CLOCK_RATE / (4 * baudrate)) - 1)
299307

300308
def read_log(self):
301309
"""Read hardware debug log.

0 commit comments

Comments
 (0)