diff --git a/html/telemetrix/index.html b/html/telemetrix/index.html index 3ab404b..8ef72f7 100644 --- a/html/telemetrix/index.html +++ b/html/telemetrix/index.html @@ -349,13 +349,6 @@

Module telemetrix.telemetrix

print(f'Waiting for Arduino to reset') print(f'Reset Complete') - # print('Retrieving Arduino ID...') - # self._get_arduino_id() - # if self.reported_arduino_id != self.arduino_instance_id: - # if self.shutdown_on_exception: - # self.shutdown() - # raise RuntimeError(f'Incorrect Arduino ID: {self.reported_arduino_id}') - # print('Valid Arduino ID Found.') # get telemetrix firmware version and print it print('\nRetrieving Telemetrix4Arduino firmware ID...') self._get_firmware_version() @@ -379,8 +372,6 @@

Module telemetrix.telemetrix

command = [PrivateConstants.RESET] self._send_command(command) - time.sleep(1.2) - def _find_arduino(self): """ This method will search all potential serial ports for an Arduino @@ -577,39 +568,50 @@

Module telemetrix.telemetrix

time.sleep(.5) def i2c_read(self, address, register, number_of_bytes, - callback=None, i2c_port=0): + callback=None, i2c_port=0, + write_register=True): """ - Read the specified number of bytes from the specified register for - the i2c device. + Read the specified number of bytes from the + specified register for the i2c device. :param address: i2c device address - :param register: i2c register (or None if no register selection is needed) + :param register: i2c register (or None if no register + selection is needed) :param number_of_bytes: number of bytes to be read - :param callback: Required callback function to report i2c data as a - result of read command + :param callback: Required callback function to report + i2c data as a result of read command :param i2c_port: 0 = default, 1 = secondary + :param write_register: If True, the register is written + before read + Else, the write is suppressed + callback returns a data list: - [I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp] + + [I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp] """ self._i2c_read_request(address, register, number_of_bytes, - callback=callback, i2c_port=i2c_port) + callback=callback, i2c_port=i2c_port, + write_register=write_register) def i2c_read_restart_transmission(self, address, register, number_of_bytes, - callback=None, i2c_port=0): + callback=None, i2c_port=0, + write_register=True): """ - Read the specified number of bytes from the specified register for - the i2c device. This restarts the transmission after the read. It is - required for some i2c devices such as the MMA8452Q accelerometer. + Read the specified number of bytes from the specified + register for the i2c device. This restarts the transmission + after the read. It is required for some i2c devices such as the MMA8452Q + accelerometer. :param address: i2c device address @@ -619,24 +621,31 @@

Module telemetrix.telemetrix

:param number_of_bytes: number of bytes to be read - :param callback: Required callback function to report i2c data as a - result of read command + :param callback: Required callback function to report i2c + data as a result of read command :param i2c_port: 0 = default 1 = secondary + :param write_register: If True, the register is written before read + Else, the write is suppressed + + callback returns a data list: - [I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp] + [I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp] """ self._i2c_read_request(address, register, number_of_bytes, stop_transmission=False, - callback=callback, i2c_port=i2c_port) + callback=callback, i2c_port=i2c_port, + write_register=write_register) def _i2c_read_request(self, address, register, number_of_bytes, - stop_transmission=True, callback=None, i2c_port=0): + stop_transmission=True, callback=None, i2c_port=0, + write_register=True): """ This method requests the read of an i2c device. Results are retrieved via callback. @@ -652,6 +661,9 @@

Module telemetrix.telemetrix

:param callback: Required callback function to report i2c data as a result of read command. + :param write_register: If True, the register is written before read + Else, the write is suppressed + """ if not i2c_port: if not self.i2c_1_active: @@ -680,15 +692,21 @@

Module telemetrix.telemetrix

if not register: register = 0 + if write_register: + write_register = 1 + else: + write_register = 0 + # message contains: # 1. address # 2. register # 3. number of bytes # 4. restart_transmission - True or False # 5. i2c port + # 6. suppress write flag command = [PrivateConstants.I2C_READ, address, register, number_of_bytes, - stop_transmission, i2c_port] + stop_transmission, i2c_port, write_register] self._send_command(command) def i2c_write(self, address, args, i2c_port=0): @@ -819,8 +837,8 @@

Module telemetrix.telemetrix

The pin_type for digital input pins with pullups enabled = 11 """ - self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP, callback= - callback) + self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP, + callback=callback) def set_pin_mode_digital_output(self, pin_number): """ @@ -1115,7 +1133,11 @@

Module telemetrix.telemetrix

:param position: target position. Maximum value is 32 bits. """ - + if position < 0: + polarity = 1 + else: + polarity = 0 + position = abs(position) if not self.stepper_info_list[motor_id]['instance']: if self.shutdown_on_exception: self.shutdown() @@ -1126,6 +1148,7 @@

Module telemetrix.telemetrix

command = [PrivateConstants.STEPPER_MOVE_TO, motor_id] for value in position_bytes: command.append(value) + command.append(polarity) self._send_command(command) def stepper_move(self, motor_id, relative_position): @@ -1138,6 +1161,12 @@

Module telemetrix.telemetrix

position. Negative is anticlockwise from the current position. Maximum value is 32 bits. """ + if relative_position < 0: + polarity = 1 + else: + polarity = 0 + + relative_position = abs(relative_position) if not self.stepper_info_list[motor_id]['instance']: if self.shutdown_on_exception: self.shutdown() @@ -1148,6 +1177,7 @@

Module telemetrix.telemetrix

command = [PrivateConstants.STEPPER_MOVE, motor_id] for value in position_bytes: command.append(value) + command.append(polarity) self._send_command(command) def stepper_run(self, motor_id, completion_callback=None): @@ -2857,13 +2887,6 @@

Classes

print(f'Waiting for Arduino to reset') print(f'Reset Complete') - # print('Retrieving Arduino ID...') - # self._get_arduino_id() - # if self.reported_arduino_id != self.arduino_instance_id: - # if self.shutdown_on_exception: - # self.shutdown() - # raise RuntimeError(f'Incorrect Arduino ID: {self.reported_arduino_id}') - # print('Valid Arduino ID Found.') # get telemetrix firmware version and print it print('\nRetrieving Telemetrix4Arduino firmware ID...') self._get_firmware_version() @@ -2887,8 +2910,6 @@

Classes

command = [PrivateConstants.RESET] self._send_command(command) - time.sleep(1.2) - def _find_arduino(self): """ This method will search all potential serial ports for an Arduino @@ -3085,39 +3106,50 @@

Classes

time.sleep(.5) def i2c_read(self, address, register, number_of_bytes, - callback=None, i2c_port=0): + callback=None, i2c_port=0, + write_register=True): """ - Read the specified number of bytes from the specified register for - the i2c device. + Read the specified number of bytes from the + specified register for the i2c device. :param address: i2c device address - :param register: i2c register (or None if no register selection is needed) + :param register: i2c register (or None if no register + selection is needed) :param number_of_bytes: number of bytes to be read - :param callback: Required callback function to report i2c data as a - result of read command + :param callback: Required callback function to report + i2c data as a result of read command :param i2c_port: 0 = default, 1 = secondary + :param write_register: If True, the register is written + before read + Else, the write is suppressed + callback returns a data list: - [I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp] + + [I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp] """ self._i2c_read_request(address, register, number_of_bytes, - callback=callback, i2c_port=i2c_port) + callback=callback, i2c_port=i2c_port, + write_register=write_register) def i2c_read_restart_transmission(self, address, register, number_of_bytes, - callback=None, i2c_port=0): + callback=None, i2c_port=0, + write_register=True): """ - Read the specified number of bytes from the specified register for - the i2c device. This restarts the transmission after the read. It is - required for some i2c devices such as the MMA8452Q accelerometer. + Read the specified number of bytes from the specified + register for the i2c device. This restarts the transmission + after the read. It is required for some i2c devices such as the MMA8452Q + accelerometer. :param address: i2c device address @@ -3127,24 +3159,31 @@

Classes

:param number_of_bytes: number of bytes to be read - :param callback: Required callback function to report i2c data as a - result of read command + :param callback: Required callback function to report i2c + data as a result of read command :param i2c_port: 0 = default 1 = secondary + :param write_register: If True, the register is written before read + Else, the write is suppressed + + callback returns a data list: - [I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp] + [I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp] """ self._i2c_read_request(address, register, number_of_bytes, stop_transmission=False, - callback=callback, i2c_port=i2c_port) + callback=callback, i2c_port=i2c_port, + write_register=write_register) def _i2c_read_request(self, address, register, number_of_bytes, - stop_transmission=True, callback=None, i2c_port=0): + stop_transmission=True, callback=None, i2c_port=0, + write_register=True): """ This method requests the read of an i2c device. Results are retrieved via callback. @@ -3160,6 +3199,9 @@

Classes

:param callback: Required callback function to report i2c data as a result of read command. + :param write_register: If True, the register is written before read + Else, the write is suppressed + """ if not i2c_port: if not self.i2c_1_active: @@ -3188,15 +3230,21 @@

Classes

if not register: register = 0 + if write_register: + write_register = 1 + else: + write_register = 0 + # message contains: # 1. address # 2. register # 3. number of bytes # 4. restart_transmission - True or False # 5. i2c port + # 6. suppress write flag command = [PrivateConstants.I2C_READ, address, register, number_of_bytes, - stop_transmission, i2c_port] + stop_transmission, i2c_port, write_register] self._send_command(command) def i2c_write(self, address, args, i2c_port=0): @@ -3327,8 +3375,8 @@

Classes

The pin_type for digital input pins with pullups enabled = 11 """ - self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP, callback= - callback) + self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP, + callback=callback) def set_pin_mode_digital_output(self, pin_number): """ @@ -3623,7 +3671,11 @@

Classes

:param position: target position. Maximum value is 32 bits. """ - + if position < 0: + polarity = 1 + else: + polarity = 0 + position = abs(position) if not self.stepper_info_list[motor_id]['instance']: if self.shutdown_on_exception: self.shutdown() @@ -3634,6 +3686,7 @@

Classes

command = [PrivateConstants.STEPPER_MOVE_TO, motor_id] for value in position_bytes: command.append(value) + command.append(polarity) self._send_command(command) def stepper_move(self, motor_id, relative_position): @@ -3646,6 +3699,12 @@

Classes

position. Negative is anticlockwise from the current position. Maximum value is 32 bits. """ + if relative_position < 0: + polarity = 1 + else: + polarity = 0 + + relative_position = abs(relative_position) if not self.stepper_info_list[motor_id]['instance']: if self.shutdown_on_exception: self.shutdown() @@ -3656,6 +3715,7 @@

Classes

command = [PrivateConstants.STEPPER_MOVE, motor_id] for value in position_bytes: command.append(value) + command.append(polarity) self._send_command(command) def stepper_run(self, motor_id, completion_callback=None): @@ -5220,78 +5280,98 @@

Methods

-def i2c_read(self, address, register, number_of_bytes, callback=None, i2c_port=0) +def i2c_read(self, address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True)
-

Read the specified number of bytes from the specified register for -the i2c device.

+

Read the specified number of bytes from the +specified register for the i2c device.

:param address: i2c device address

-

:param register: i2c register (or None if no register selection is needed)

+

:param register: i2c register (or None if no register +selection is needed)

:param number_of_bytes: number of bytes to be read

-

:param callback: Required callback function to report i2c data as a -result of read command

+

:param callback: Required callback function to report +i2c data as a result of read command

:param i2c_port: 0 = default, 1 = secondary

-

callback returns a data list: -[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]

+

:param write_register: If True, the register is written +before read +Else, the write is suppressed

+

callback returns a data list:

+

[I2C_READ_REPORT, address, register, count of data bytes, +data bytes, time-stamp]

Expand source code
def i2c_read(self, address, register, number_of_bytes,
-             callback=None, i2c_port=0):
+             callback=None, i2c_port=0,
+             write_register=True):
     """
-    Read the specified number of bytes from the specified register for
-    the i2c device.
+    Read the specified number of bytes from the
+    specified register for the i2c device.
 
 
     :param address: i2c device address
 
-    :param register: i2c register (or None if no register selection is needed)
+    :param register: i2c register (or None if no register
+                                   selection is needed)
 
     :param number_of_bytes: number of bytes to be read
 
-    :param callback: Required callback function to report i2c data as a
-               result of read command
+    :param callback: Required callback function to report
+                     i2c data as a result of read command
 
    :param i2c_port: 0 = default, 1 = secondary
 
+   :param write_register: If True, the register is written
+                                   before read
+                          Else, the write is suppressed
+
 
     callback returns a data list:
-    [I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]
+
+    [I2C_READ_REPORT, address, register, count of data bytes,
+     data bytes, time-stamp]
 
     """
 
     self._i2c_read_request(address, register, number_of_bytes,
-                           callback=callback, i2c_port=i2c_port)
+ callback=callback, i2c_port=i2c_port, + write_register=write_register)
-def i2c_read_restart_transmission(self, address, register, number_of_bytes, callback=None, i2c_port=0) +def i2c_read_restart_transmission(self, address, register, number_of_bytes, callback=None, i2c_port=0, write_register=True)
-

Read the specified number of bytes from the specified register for -the i2c device. This restarts the transmission after the read. It is -required for some i2c devices such as the MMA8452Q accelerometer.

+

Read the specified number of bytes from the specified +register for the i2c device. This restarts the transmission +after the read. It is required for some i2c devices such as the MMA8452Q +accelerometer.

:param address: i2c device address

:param register: i2c register (or None if no register selection is needed)

:param number_of_bytes: number of bytes to be read

-

:param callback: Required callback function to report i2c data as a -result of read command

+

:param callback: Required callback function to report i2c +data as a result of read command

:param i2c_port: 0 = default 1 = secondary

+

:param write_register: If True, the register is written before read +Else, the write is suppressed

callback returns a data list:

-

[I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp]

+

[I2C_READ_REPORT, address, register, count of data bytes, +data bytes, time-stamp]

Expand source code
def i2c_read_restart_transmission(self, address, register,
                                   number_of_bytes,
-                                  callback=None, i2c_port=0):
+                                  callback=None, i2c_port=0,
+                                  write_register=True):
     """
-    Read the specified number of bytes from the specified register for
-    the i2c device. This restarts the transmission after the read. It is
-    required for some i2c devices such as the MMA8452Q accelerometer.
+    Read the specified number of bytes from the specified
+    register for the i2c device. This restarts the transmission
+    after the read. It is required for some i2c devices such as the MMA8452Q
+    accelerometer.
 
 
     :param address: i2c device address
@@ -5301,21 +5381,27 @@ 

Methods

:param number_of_bytes: number of bytes to be read - :param callback: Required callback function to report i2c data as a - result of read command + :param callback: Required callback function to report i2c + data as a result of read command :param i2c_port: 0 = default 1 = secondary + :param write_register: If True, the register is written before read + Else, the write is suppressed + + callback returns a data list: - [I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp] + [I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp] """ self._i2c_read_request(address, register, number_of_bytes, stop_transmission=False, - callback=callback, i2c_port=i2c_port)
+ callback=callback, i2c_port=i2c_port, + write_register=write_register)
@@ -5956,8 +6042,8 @@

Methods

The pin_type for digital input pins with pullups enabled = 11 """ - self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP, callback= - callback)
+ self._set_pin_mode(pin_number, PrivateConstants.AT_INPUT_PULLUP, + callback=callback)
@@ -6878,6 +6964,12 @@

Methods

position. Negative is anticlockwise from the current position. Maximum value is 32 bits. """ + if relative_position < 0: + polarity = 1 + else: + polarity = 0 + + relative_position = abs(relative_position) if not self.stepper_info_list[motor_id]['instance']: if self.shutdown_on_exception: self.shutdown() @@ -6888,6 +6980,7 @@

Methods

command = [PrivateConstants.STEPPER_MOVE, motor_id] for value in position_bytes: command.append(value) + command.append(polarity) self._send_command(command)
@@ -6925,7 +7018,11 @@

Methods

:param position: target position. Maximum value is 32 bits. """ - + if position < 0: + polarity = 1 + else: + polarity = 0 + position = abs(position) if not self.stepper_info_list[motor_id]['instance']: if self.shutdown_on_exception: self.shutdown() @@ -6936,6 +7033,7 @@

Methods

command = [PrivateConstants.STEPPER_MOVE_TO, motor_id] for value in position_bytes: command.append(value) + command.append(polarity) self._send_command(command) diff --git a/setup.py b/setup.py index 64d5e86..59fceaa 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ packages=['telemetrix'], install_requires=['pyserial'], - version='1.9', + version='1.10', description="Remotely Control And Monitor Arduino-Core devices", long_description=long_description, long_description_content_type='text/markdown', diff --git a/telemetrix/private_constants.py b/telemetrix/private_constants.py index 778761e..b968a3d 100644 --- a/telemetrix/private_constants.py +++ b/telemetrix/private_constants.py @@ -101,7 +101,7 @@ class PrivateConstants: FEATURES = 20 DEBUG_PRINT = 99 - TELEMETRIX_VERSION = "1.9" + TELEMETRIX_VERSION = "1.10" # reporting control REPORTING_DISABLE_ALL = 0 diff --git a/telemetrix/telemetrix.py b/telemetrix/telemetrix.py index 11be2a5..b14b357 100644 --- a/telemetrix/telemetrix.py +++ b/telemetrix/telemetrix.py @@ -315,6 +315,8 @@ def __init__(self, com_port=None, arduino_instance_id=1, raise RuntimeError(f'Telemetrix4Arduino firmware version') else: + if self.firmware_version[0] < 5: + raise RuntimeError('Please upgrade the server firmware to version 5.0.0 or greater') print(f'Telemetrix4Arduino firmware version: {self.firmware_version[0]}.' f'{self.firmware_version[1]}.{self.firmware_version[2]}') command = [PrivateConstants.ENABLE_ALL_REPORTS] @@ -525,39 +527,50 @@ def _get_firmware_version(self): time.sleep(.5) def i2c_read(self, address, register, number_of_bytes, - callback=None, i2c_port=0): + callback=None, i2c_port=0, + write_register=True): """ - Read the specified number of bytes from the specified register for - the i2c device. + Read the specified number of bytes from the + specified register for the i2c device. :param address: i2c device address - :param register: i2c register (or None if no register selection is needed) + :param register: i2c register (or None if no register + selection is needed) :param number_of_bytes: number of bytes to be read - :param callback: Required callback function to report i2c data as a - result of read command + :param callback: Required callback function to report + i2c data as a result of read command :param i2c_port: 0 = default, 1 = secondary + :param write_register: If True, the register is written + before read + Else, the write is suppressed + callback returns a data list: - [I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp] + + [I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp] """ self._i2c_read_request(address, register, number_of_bytes, - callback=callback, i2c_port=i2c_port) + callback=callback, i2c_port=i2c_port, + write_register=write_register) def i2c_read_restart_transmission(self, address, register, number_of_bytes, - callback=None, i2c_port=0): + callback=None, i2c_port=0, + write_register=True): """ - Read the specified number of bytes from the specified register for - the i2c device. This restarts the transmission after the read. It is - required for some i2c devices such as the MMA8452Q accelerometer. + Read the specified number of bytes from the specified + register for the i2c device. This restarts the transmission + after the read. It is required for some i2c devices such as the MMA8452Q + accelerometer. :param address: i2c device address @@ -567,24 +580,31 @@ def i2c_read_restart_transmission(self, address, register, :param number_of_bytes: number of bytes to be read - :param callback: Required callback function to report i2c data as a - result of read command + :param callback: Required callback function to report i2c + data as a result of read command :param i2c_port: 0 = default 1 = secondary + :param write_register: If True, the register is written before read + Else, the write is suppressed + + callback returns a data list: - [I2C_READ_REPORT, address, register, count of data bytes, data bytes, time-stamp] + [I2C_READ_REPORT, address, register, count of data bytes, + data bytes, time-stamp] """ self._i2c_read_request(address, register, number_of_bytes, stop_transmission=False, - callback=callback, i2c_port=i2c_port) + callback=callback, i2c_port=i2c_port, + write_register=write_register) def _i2c_read_request(self, address, register, number_of_bytes, - stop_transmission=True, callback=None, i2c_port=0): + stop_transmission=True, callback=None, i2c_port=0, + write_register=True): """ This method requests the read of an i2c device. Results are retrieved via callback. @@ -600,6 +620,9 @@ def _i2c_read_request(self, address, register, number_of_bytes, :param callback: Required callback function to report i2c data as a result of read command. + :param write_register: If True, the register is written before read + Else, the write is suppressed + """ if not i2c_port: if not self.i2c_1_active: @@ -628,15 +651,21 @@ def _i2c_read_request(self, address, register, number_of_bytes, if not register: register = 0 + if write_register: + write_register = 1 + else: + write_register = 0 + # message contains: # 1. address # 2. register # 3. number of bytes # 4. restart_transmission - True or False # 5. i2c port + # 6. suppress write flag command = [PrivateConstants.I2C_READ, address, register, number_of_bytes, - stop_transmission, i2c_port] + stop_transmission, i2c_port, write_register] self._send_command(command) def i2c_write(self, address, args, i2c_port=0):