PyTmcStepper 0.7.2__tar.gz → 0.7.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. {pytmcstepper-0.7.2/src/PyTmcStepper.egg-info → pytmcstepper-0.7.3}/PKG-INFO +10 -7
  2. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/README.md +9 -6
  3. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/setup.cfg +1 -1
  4. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3/src/PyTmcStepper.egg-info}/PKG-INFO +10 -7
  5. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/com/_tmc_com.py +6 -0
  6. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/com/_tmc_com_spi.py +54 -27
  7. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/com/_tmc_com_uart.py +13 -8
  8. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/reg/_tmc_reg.py +12 -3
  9. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/tests/test_tmc_com_spi.py +2 -3
  10. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/tests/test_tmc_com_uart.py +2 -3
  11. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/LICENSE +0 -0
  12. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/pyproject.toml +0 -0
  13. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/PyTmcStepper.egg-info/SOURCES.txt +0 -0
  14. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/PyTmcStepper.egg-info/dependency_links.txt +0 -0
  15. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/PyTmcStepper.egg-info/requires.txt +0 -0
  16. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/PyTmcStepper.egg-info/top_level.txt +0 -0
  17. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/__init__.py +0 -0
  18. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/_tmc_gpio_board.py +0 -0
  19. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/_tmc_logger.py +0 -0
  20. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/_tmc_math.py +0 -0
  21. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/_tmc_stallguard.py +0 -0
  22. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/_tmc_stepperdriver.py +0 -0
  23. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/com/__init__.py +0 -0
  24. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/enable_control/__init__.py +0 -0
  25. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/enable_control/_tmc_ec.py +0 -0
  26. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/enable_control/_tmc_ec_pin.py +0 -0
  27. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/enable_control/_tmc_ec_toff.py +0 -0
  28. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/motion_control/__init__.py +0 -0
  29. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/motion_control/_tmc_mc.py +0 -0
  30. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/motion_control/_tmc_mc_step_dir.py +0 -0
  31. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/motion_control/_tmc_mc_step_reg.py +0 -0
  32. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/motion_control/_tmc_mc_vactual.py +0 -0
  33. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/reg/__init__.py +0 -0
  34. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/reg/_tmc2209_reg.py +0 -0
  35. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/reg/_tmc220x_reg.py +0 -0
  36. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/reg/_tmc224x_reg.py +0 -0
  37. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/tmc_2208.py +0 -0
  38. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/tmc_2209.py +0 -0
  39. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/tmc_220x.py +0 -0
  40. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/src/tmc_driver/tmc_2240.py +0 -0
  41. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/tests/test_tmc2209.py +0 -0
  42. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/tests/test_tmc2240.py +0 -0
  43. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/tests/test_tmc_ec_pin.py +0 -0
  44. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/tests/test_tmc_math.py +0 -0
  45. {pytmcstepper-0.7.2 → pytmcstepper-0.7.3}/tests/test_tmc_move.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: PyTmcStepper
3
- Version: 0.7.2
3
+ Version: 0.7.3
4
4
  Summary: This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi
5
5
  Home-page: https://github.com/Chr157i4n/PyTmcStepper
6
6
  Author: Christian Köhlke
@@ -96,7 +96,6 @@ RPi.GPIO | RASPBERRY_PI | Pi4, Pi3 etc.
96
96
  gpiozero | RASPBERRY_PI5 | Pi5
97
97
  Jetson.GPIO | NVIDIA_JETSON | Nvidia Jetson
98
98
  pheriphery | LUCKFOX_PICO | Luckfox Pico
99
- pheriphery | LUCKFOX_PICO | Luckfox Pico
100
99
  OPi.GPIO | ORANGE_PI | Orange Pi
101
100
 
102
101
  Those libraries are needed for this library to work. You can either install the correct library yourself.
@@ -123,6 +122,8 @@ is split into their own classes to be able to support the diverse methods.
123
122
 
124
123
  ### EnableControl
125
124
 
125
+ The EnableControl module controls the motor current output. It has a function `set_motor_enabled` with one boolean parameter. This function is used to enable or disable the Motor current output.
126
+
126
127
  EnableControl | Class | Driver | Notes
127
128
  -- | -- | -- | --
128
129
  Pin | [TmcEnableControlPin](src/tmc_driver/enable_control/_tmc_ec_pin.py) | all | the EN Pin of the Driver needs to be connected to a GPIO of the Pi
@@ -130,13 +131,15 @@ TOff | [TmcEnableControlToff](src/tmc_driver/enable_control/_tmc_ec_t
130
131
 
131
132
  ### MotionControl
132
133
 
134
+ The MotionControl module controls the motion of the motor. Before a movement the motor current output needs to be enabled by the [EnableControl](#enablecontrol) module.
135
+
133
136
  MotionControl | Class | Driver | Notes
134
137
  -- | -- | -- | --
135
138
  STEP/DIR | [TmcMotionControlStepDir](src/tmc_driver/motion_control/_tmc_mc_step_dir.py) | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
136
139
  STEP/REG | [TmcMotionControlStepReg](src/tmc_driver/motion_control/_tmc_mc_step_reg.py) | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
137
140
  VACTUAL | [TmcMotionControlVActual](src/tmc_driver/motion_control/_tmc_mc_vactual.py) | TMC220x | the Direction and Speed is controlled via Register. But VActual does only allow setting a speed and therefore cannot control positioning of the Motor.
138
141
 
139
- Further methods of controlling a motor could be:
142
+ Further methods of controlling the motion of a motor could be:
140
143
 
141
144
  - using the built in Motion Controller of the TMC5130
142
145
  - via a µC which controlls the Motor
@@ -159,10 +162,10 @@ VDD | | 3,3V of Raspberry Pi | recommended, for forcing t
159
162
  GND | BLACK | GND of Raspberry Pi | GND for VDD and Signals
160
163
  VM | RED | 12V or 24V of power supply | power for the motor
161
164
  GND | BLACK | GND of power supply | power for the motor
162
- EN | RED |GPIO21 of Raspberry Pi | enable the motor output
163
- STEP | GREEN |GPIO16 of Raspberry Pi | moves the motor one step per pulse
164
- DIR | WHITE |GPIO20 of Raspberry Pi | set the direction of the motor
165
- DIAG | ORANGE | GPIO26 of Raspberry Pi | optional, for StallGuard
165
+ EN | RED | GPIO21 of Raspberry Pi | enable the motor output
166
+ STEP | GREEN | GPIO16 of Raspberry Pi | moves the motor one step per pulse
167
+ DIR | WHITE | GPIO20 of Raspberry Pi | set the direction of the motor
168
+ DIAG | ORANGE | GPIO26 of Raspberry Pi | optional, for StallGuard
166
169
 
167
170
  The GPIO pins can be specific when initiating the class.
168
171
  If you test this on a breadboard, make sure to cut off the bottomside of the pins (Vref and DIAG) next to the EN pin, so that they are not shorted trough the breadboard.
@@ -66,7 +66,6 @@ RPi.GPIO | RASPBERRY_PI | Pi4, Pi3 etc.
66
66
  gpiozero | RASPBERRY_PI5 | Pi5
67
67
  Jetson.GPIO | NVIDIA_JETSON | Nvidia Jetson
68
68
  pheriphery | LUCKFOX_PICO | Luckfox Pico
69
- pheriphery | LUCKFOX_PICO | Luckfox Pico
70
69
  OPi.GPIO | ORANGE_PI | Orange Pi
71
70
 
72
71
  Those libraries are needed for this library to work. You can either install the correct library yourself.
@@ -93,6 +92,8 @@ is split into their own classes to be able to support the diverse methods.
93
92
 
94
93
  ### EnableControl
95
94
 
95
+ The EnableControl module controls the motor current output. It has a function `set_motor_enabled` with one boolean parameter. This function is used to enable or disable the Motor current output.
96
+
96
97
  EnableControl | Class | Driver | Notes
97
98
  -- | -- | -- | --
98
99
  Pin | [TmcEnableControlPin](src/tmc_driver/enable_control/_tmc_ec_pin.py) | all | the EN Pin of the Driver needs to be connected to a GPIO of the Pi
@@ -100,13 +101,15 @@ TOff | [TmcEnableControlToff](src/tmc_driver/enable_control/_tmc_ec_t
100
101
 
101
102
  ### MotionControl
102
103
 
104
+ The MotionControl module controls the motion of the motor. Before a movement the motor current output needs to be enabled by the [EnableControl](#enablecontrol) module.
105
+
103
106
  MotionControl | Class | Driver | Notes
104
107
  -- | -- | -- | --
105
108
  STEP/DIR | [TmcMotionControlStepDir](src/tmc_driver/motion_control/_tmc_mc_step_dir.py) | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
106
109
  STEP/REG | [TmcMotionControlStepReg](src/tmc_driver/motion_control/_tmc_mc_step_reg.py) | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
107
110
  VACTUAL | [TmcMotionControlVActual](src/tmc_driver/motion_control/_tmc_mc_vactual.py) | TMC220x | the Direction and Speed is controlled via Register. But VActual does only allow setting a speed and therefore cannot control positioning of the Motor.
108
111
 
109
- Further methods of controlling a motor could be:
112
+ Further methods of controlling the motion of a motor could be:
110
113
 
111
114
  - using the built in Motion Controller of the TMC5130
112
115
  - via a µC which controlls the Motor
@@ -129,10 +132,10 @@ VDD | | 3,3V of Raspberry Pi | recommended, for forcing t
129
132
  GND | BLACK | GND of Raspberry Pi | GND for VDD and Signals
130
133
  VM | RED | 12V or 24V of power supply | power for the motor
131
134
  GND | BLACK | GND of power supply | power for the motor
132
- EN | RED |GPIO21 of Raspberry Pi | enable the motor output
133
- STEP | GREEN |GPIO16 of Raspberry Pi | moves the motor one step per pulse
134
- DIR | WHITE |GPIO20 of Raspberry Pi | set the direction of the motor
135
- DIAG | ORANGE | GPIO26 of Raspberry Pi | optional, for StallGuard
135
+ EN | RED | GPIO21 of Raspberry Pi | enable the motor output
136
+ STEP | GREEN | GPIO16 of Raspberry Pi | moves the motor one step per pulse
137
+ DIR | WHITE | GPIO20 of Raspberry Pi | set the direction of the motor
138
+ DIAG | ORANGE | GPIO26 of Raspberry Pi | optional, for StallGuard
136
139
 
137
140
  The GPIO pins can be specific when initiating the class.
138
141
  If you test this on a breadboard, make sure to cut off the bottomside of the pins (Vref and DIAG) next to the EN pin, so that they are not shorted trough the breadboard.
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = PyTmcStepper
3
- version = 0.7.2
3
+ version = 0.7.3
4
4
  author = Christian Köhlke
5
5
  author_email = christian@koehlke.de
6
6
  description = This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: PyTmcStepper
3
- Version: 0.7.2
3
+ Version: 0.7.3
4
4
  Summary: This is a Python libary to drive a stepper motor with a Trinamic stepper driver and a single board computer like a Raspberry Pi
5
5
  Home-page: https://github.com/Chr157i4n/PyTmcStepper
6
6
  Author: Christian Köhlke
@@ -96,7 +96,6 @@ RPi.GPIO | RASPBERRY_PI | Pi4, Pi3 etc.
96
96
  gpiozero | RASPBERRY_PI5 | Pi5
97
97
  Jetson.GPIO | NVIDIA_JETSON | Nvidia Jetson
98
98
  pheriphery | LUCKFOX_PICO | Luckfox Pico
99
- pheriphery | LUCKFOX_PICO | Luckfox Pico
100
99
  OPi.GPIO | ORANGE_PI | Orange Pi
101
100
 
102
101
  Those libraries are needed for this library to work. You can either install the correct library yourself.
@@ -123,6 +122,8 @@ is split into their own classes to be able to support the diverse methods.
123
122
 
124
123
  ### EnableControl
125
124
 
125
+ The EnableControl module controls the motor current output. It has a function `set_motor_enabled` with one boolean parameter. This function is used to enable or disable the Motor current output.
126
+
126
127
  EnableControl | Class | Driver | Notes
127
128
  -- | -- | -- | --
128
129
  Pin | [TmcEnableControlPin](src/tmc_driver/enable_control/_tmc_ec_pin.py) | all | the EN Pin of the Driver needs to be connected to a GPIO of the Pi
@@ -130,13 +131,15 @@ TOff | [TmcEnableControlToff](src/tmc_driver/enable_control/_tmc_ec_t
130
131
 
131
132
  ### MotionControl
132
133
 
134
+ The MotionControl module controls the motion of the motor. Before a movement the motor current output needs to be enabled by the [EnableControl](#enablecontrol) module.
135
+
133
136
  MotionControl | Class | Driver | Notes
134
137
  -- | -- | -- | --
135
138
  STEP/DIR | [TmcMotionControlStepDir](src/tmc_driver/motion_control/_tmc_mc_step_dir.py) | all | the STEP and DIR pin of the driver must each be connected to a GPIO of the Pi
136
139
  STEP/REG | [TmcMotionControlStepReg](src/tmc_driver/motion_control/_tmc_mc_step_reg.py) | all | only the STEP pin needs to be connected to a GPIO of the Pi.<br />The direction is controlled via the Register.
137
140
  VACTUAL | [TmcMotionControlVActual](src/tmc_driver/motion_control/_tmc_mc_vactual.py) | TMC220x | the Direction and Speed is controlled via Register. But VActual does only allow setting a speed and therefore cannot control positioning of the Motor.
138
141
 
139
- Further methods of controlling a motor could be:
142
+ Further methods of controlling the motion of a motor could be:
140
143
 
141
144
  - using the built in Motion Controller of the TMC5130
142
145
  - via a µC which controlls the Motor
@@ -159,10 +162,10 @@ VDD | | 3,3V of Raspberry Pi | recommended, for forcing t
159
162
  GND | BLACK | GND of Raspberry Pi | GND for VDD and Signals
160
163
  VM | RED | 12V or 24V of power supply | power for the motor
161
164
  GND | BLACK | GND of power supply | power for the motor
162
- EN | RED |GPIO21 of Raspberry Pi | enable the motor output
163
- STEP | GREEN |GPIO16 of Raspberry Pi | moves the motor one step per pulse
164
- DIR | WHITE |GPIO20 of Raspberry Pi | set the direction of the motor
165
- DIAG | ORANGE | GPIO26 of Raspberry Pi | optional, for StallGuard
165
+ EN | RED | GPIO21 of Raspberry Pi | enable the motor output
166
+ STEP | GREEN | GPIO16 of Raspberry Pi | moves the motor one step per pulse
167
+ DIR | WHITE | GPIO20 of Raspberry Pi | set the direction of the motor
168
+ DIAG | ORANGE | GPIO26 of Raspberry Pi | optional, for StallGuard
166
169
 
167
170
  The GPIO pins can be specific when initiating the class.
168
171
  If you test this on a breadboard, make sure to cut off the bottomside of the pins (Vref and DIAG) next to the EN pin, so that they are not shorted trough the breadboard.
@@ -95,6 +95,9 @@ class TmcCom:
95
95
 
96
96
  Args:
97
97
  addr (int): HEX, which register to read
98
+ Returns:
99
+ int: register value
100
+ Dict: flags
98
101
  """
99
102
  raise NotImplementedError
100
103
 
@@ -106,6 +109,9 @@ class TmcCom:
106
109
  Args:
107
110
  addr (int): HEX, which register to read
108
111
  tries (int): how many tries, before error is raised (Default value = 10)
112
+ Returns:
113
+ int: register value
114
+ Dict: flags
109
115
  """
110
116
  raise NotImplementedError
111
117
 
@@ -4,11 +4,12 @@
4
4
  #pylint: disable=wildcard-import
5
5
  #pylint: disable=unused-wildcard-import
6
6
  #pylint: disable=too-few-public-methods
7
+ #pylint: disable=too-many-arguments
8
+ #pylint: disable=too-many-positional-arguments
7
9
  """
8
10
  TmcComSpi stepper driver spi module
9
11
  """
10
12
 
11
- import sys
12
13
  import spidev
13
14
  from ._tmc_com import *
14
15
 
@@ -35,13 +36,17 @@ class TmcComSpi(TmcCom):
35
36
  like the current or the microsteppingmode
36
37
  """
37
38
 
38
- _spi = spidev.SpiDev()
39
+ spi = spidev.SpiDev()
39
40
  _spi_bus: int
40
41
  _spi_dev: int
42
+ _spi_speed: int
43
+
44
+
41
45
 
42
46
  def __init__(self,
43
47
  spi_bus,
44
48
  spi_dev,
49
+ spi_speed:int = 8000000,
45
50
  mtr_id:int = 0,
46
51
  tmc_logger = None
47
52
  ):
@@ -55,6 +60,7 @@ class TmcComSpi(TmcCom):
55
60
 
56
61
  self._spi_bus = spi_bus
57
62
  self._spi_dev = spi_dev
63
+ self._spi_speed = spi_speed
58
64
 
59
65
  self._r_frame = [0x55, 0, 0, 0, 0]
60
66
  self._w_frame = [0x55, 0, 0, 0, 0]
@@ -63,18 +69,18 @@ class TmcComSpi(TmcCom):
63
69
  def init(self):
64
70
  """init"""
65
71
  try:
66
- self._spi.open(self._spi_bus, self._spi_dev)
72
+ self.spi.open(self._spi_bus, self._spi_dev)
67
73
  except Exception as e:
68
74
  self._tmc_logger.log(f"Error opening SPI: {e}", Loglevel.ERROR)
69
75
  errnum = e.args[0]
70
76
  if errnum == 2:
71
77
  self._tmc_logger.log(f"SPI Device {self._spi_dev} on Bus {self._spi_bus} does not exist.", Loglevel.ERROR)
72
78
  self._tmc_logger.log("You need to activate the SPI interface with \"sudo raspi-config\"", Loglevel.ERROR)
73
- sys.exit()
79
+ raise SystemExit from e
74
80
 
75
- self._spi.max_speed_hz = 5000
76
- self._spi.mode = 0b11
77
- self._spi.lsbfirst = False
81
+ self.spi.max_speed_hz = self._spi_speed
82
+ self.spi.mode = 0b11
83
+ self.spi.lsbfirst = False
78
84
 
79
85
 
80
86
  def __del__(self):
@@ -87,30 +93,34 @@ class TmcComSpi(TmcCom):
87
93
 
88
94
  Args:
89
95
  addr (int): HEX, which register to read
96
+ Returns:
97
+ int: register value
98
+ Dict: flags
90
99
  """
91
100
  self._w_frame = [addr, 0x00, 0x00, 0x00, 0x00]
92
101
  dummy_data = [0x00, 0x00, 0x00, 0x00, 0x00]
93
102
 
94
- self._spi.xfer2(self._w_frame)
95
- rtn = self._spi.xfer2(dummy_data)
103
+ self.spi.xfer2(self._w_frame)
104
+ rtn = self.spi.xfer2(dummy_data)
96
105
 
97
- reset_flag = rtn[0] >> 0 & 0x01
98
- driver_error = rtn[0] >> 1 & 0x01
99
- sg2 = rtn[0] >> 2 & 0x01
100
- standstill = rtn[0] >> 3 & 0x01
106
+ flags = {
107
+ "reset_flag": rtn[0] >> 0 & 0x01,
108
+ "driver_error": rtn[0] >> 1 & 0x01,
109
+ "sg2": rtn[0] >> 2 & 0x01,
110
+ "standstill": rtn[0] >> 3 & 0x01
111
+ }
101
112
 
102
-
103
- if reset_flag:
113
+ if flags["reset_flag"]:
104
114
  self._tmc_logger.log("TMC reset flag is set", Loglevel.ERROR)
105
- if driver_error:
115
+ if flags["driver_error"]:
106
116
  self._tmc_logger.log("TMC driver error flag is set", Loglevel.ERROR)
107
- if sg2:
117
+ if flags["sg2"]:
108
118
  self._tmc_logger.log("TMC stallguard2 flag is set", Loglevel.MOVEMENT)
109
- if standstill:
119
+ if flags["standstill"]:
110
120
  self._tmc_logger.log("TMC standstill flag is set", Loglevel.MOVEMENT)
111
121
 
112
122
 
113
- return rtn[1:]
123
+ return rtn[1:], flags
114
124
 
115
125
 
116
126
  def read_int(self, addr:hex, tries:int = 10):
@@ -120,9 +130,12 @@ class TmcComSpi(TmcCom):
120
130
  Args:
121
131
  addr (int): HEX, which register to read
122
132
  tries (int): how many tries, before error is raised (Default value = 10)
133
+ Returns:
134
+ int: register value
135
+ Dict: flags
123
136
  """
124
- data = self.read_reg(addr)
125
- return int.from_bytes(data, byteorder='big', signed=False)
137
+ data, flags = self.read_reg(addr)
138
+ return int.from_bytes(data, byteorder='big', signed=False), flags
126
139
 
127
140
 
128
141
  def write_reg(self, addr:hex, val:int):
@@ -143,13 +156,12 @@ class TmcComSpi(TmcCom):
143
156
  self._w_frame[4] = 0xFF & val
144
157
  # self.w_frame[7] = compute_crc8_atm(self.w_frame[:-1])
145
158
 
146
- self._spi.xfer2(self._w_frame)
159
+ self.spi.xfer2(self._w_frame)
147
160
 
148
161
 
149
162
  def write_reg_check(self, addr:hex, val:int, tries:int=10):
150
- """this function als writes a value to the register of the TMC
151
- but it also checks if the writing process was successfully by checking
152
- the InterfaceTransmissionCounter before and after writing
163
+ """IFCNT is disabled in SPI mode. Therefore, no check is possible.
164
+ This only calls the write_reg function
153
165
 
154
166
  Args:
155
167
  addr: HEX, which register to write
@@ -165,7 +177,14 @@ class TmcComSpi(TmcCom):
165
177
 
166
178
  def handle_error(self):
167
179
  """error handling"""
168
- raise NotImplementedError
180
+ if self.error_handler_running:
181
+ return
182
+ self.error_handler_running = True
183
+ self._tmc_registers["gstat"].read()
184
+ self._tmc_registers["gstat"].log(self.tmc_logger)
185
+
186
+ self._tmc_logger.log("EXITING!", Loglevel.INFO)
187
+ raise SystemExit
169
188
 
170
189
 
171
190
  def test_com(self, addr):
@@ -174,4 +193,12 @@ class TmcComSpi(TmcCom):
174
193
  Args:
175
194
  addr (int): HEX, which register to test
176
195
  """
177
- raise NotImplementedError
196
+ self._tmc_registers["ioin"].read()
197
+ self._tmc_registers["ioin"].log(self.tmc_logger)
198
+ if self._tmc_registers["ioin"].data_int == 0:
199
+ self._tmc_logger.log("No answer from TMC received", Loglevel.ERROR)
200
+ return False
201
+ if self._tmc_registers["ioin"].version < 0x40:
202
+ self._tmc_logger.log("No correct Version from TMC received", Loglevel.ERROR)
203
+ return False
204
+ return True
@@ -6,7 +6,6 @@
6
6
  TmcComUart stepper driver uart module
7
7
  """
8
8
 
9
- import sys
10
9
  import serial
11
10
  from ._tmc_com import *
12
11
 
@@ -59,13 +58,13 @@ class TmcComUart(TmcCom):
59
58
  if errnum == 2:
60
59
  self._tmc_logger.log(f""""{self.ser.serialport} does not exist.
61
60
  You need to activate the serial port with \"sudo raspi-config\"""", Loglevel.ERROR)
62
- sys.exit()
61
+ raise SystemExit from e
63
62
 
64
63
  if errnum == 13:
65
64
  self._tmc_logger.log("""you have no permission to use the serial port.
66
65
  You may need to add your user to the dialout group
67
66
  with \"sudo usermod -a -G dialout pi\"""", Loglevel.ERROR)
68
- sys.exit()
67
+ raise SystemExit from e
69
68
 
70
69
  # adjust per baud and hardware. Sequential reads without some delay fail.
71
70
  self.communication_pause = 500 / self.ser.baudrate
@@ -96,6 +95,9 @@ class TmcComUart(TmcCom):
96
95
 
97
96
  Args:
98
97
  register (int): HEX, which register to read
98
+ Returns:
99
+ int: register value
100
+ Dict: flags
99
101
  """
100
102
  if self.ser is None:
101
103
  self._tmc_logger.log("Cannot read reg, serial is not initialized", Loglevel.ERROR)
@@ -122,7 +124,7 @@ class TmcComUart(TmcCom):
122
124
 
123
125
  time.sleep(self.communication_pause)
124
126
 
125
- return rtn
127
+ return rtn, None
126
128
 
127
129
 
128
130
  def read_int(self, addr:hex, tries:int = 10):
@@ -132,13 +134,16 @@ class TmcComUart(TmcCom):
132
134
  Args:
133
135
  addr (int): HEX, which register to read
134
136
  tries (int): how many tries, before error is raised (Default value = 10)
137
+ Returns:
138
+ int: register value
139
+ Dict: flags
135
140
  """
136
141
  if self.ser is None:
137
142
  self._tmc_logger.log("Cannot read int, serial is not initialized", Loglevel.ERROR)
138
143
  return -1
139
144
  while True:
140
145
  tries -= 1
141
- rtn = self.read_reg(addr)
146
+ rtn, flags = self.read_reg(addr)
142
147
  rtn_data = rtn[7:11]
143
148
  not_zero_count = len([elem for elem in rtn if elem != 0])
144
149
 
@@ -153,13 +158,13 @@ class TmcComUart(TmcCom):
153
158
 
154
159
  if tries<=0:
155
160
  self._tmc_logger.log("after 10 tries not valid answer", Loglevel.ERROR)
156
- self._tmc_logger.log(f"snd:\t{bytes(self.r_frame)}", Loglevel.DEBUG)
161
+ self._tmc_logger.log(f"addr:\t{addr}", Loglevel.DEBUG)
157
162
  self._tmc_logger.log(f"rtn:\t{rtn}", Loglevel.DEBUG)
158
163
  self.handle_error()
159
164
  return -1
160
165
 
161
166
  val = struct.unpack(">i",rtn_data)[0]
162
- return val
167
+ return val, flags
163
168
 
164
169
 
165
170
  def write_reg(self, addr:hex, val:int):
@@ -232,7 +237,7 @@ class TmcComUart(TmcCom):
232
237
  if tries<=0:
233
238
  self._tmc_logger.log("after 10 tries no valid write access", Loglevel.ERROR)
234
239
  self.handle_error()
235
- return -1
240
+ return False
236
241
 
237
242
 
238
243
  def flush_serial_buffer(self):
@@ -17,6 +17,7 @@ class TmcReg():
17
17
  _tmc_com: TmcCom
18
18
  _reg_map: typing.List
19
19
  _data_int: int
20
+ _flags: typing.Dict
20
21
 
21
22
 
22
23
  @property
@@ -39,6 +40,11 @@ class TmcReg():
39
40
  """data_int property"""
40
41
  return self._data_int
41
42
 
43
+ @property
44
+ def flags(self) -> typing.Dict:
45
+ """flags property"""
46
+ return self._flags
47
+
42
48
 
43
49
  def __init__(self, address:hex, name:str, tmc_com:TmcCom, reg_map:typing.List):
44
50
  """Constructor"""
@@ -54,8 +60,6 @@ class TmcReg():
54
60
  Args:
55
61
  data (int): register value
56
62
  """
57
- self._data_int = data
58
-
59
63
  for reg in self._reg_map:
60
64
  name, pos, mask, reg_class, _, _ = reg
61
65
  value = data >> pos & mask
@@ -93,8 +97,13 @@ class TmcReg():
93
97
 
94
98
  def read(self):
95
99
  """read this register"""
96
- data = self._tmc_com.read_int(self._addr)
100
+ data, flags = self._tmc_com.read_int(self._addr)
101
+
102
+ self._data_int = data
103
+ self._flags = flags
104
+
97
105
  self.deserialise(data)
106
+ return data, flags
98
107
 
99
108
 
100
109
  def write(self):
@@ -18,9 +18,8 @@ class TestTmcComSpi(unittest.TestCase):
18
18
 
19
19
  def test_read_int(self):
20
20
  """test_read_int"""
21
- with mock.patch.object(TmcComSpi, 'read_reg', return_value=
22
- b'U\xc0\x1e\x00\x00\xca'):
23
- reg_ans = self.tmc_uart.read_int(0x00)
21
+ with mock.patch.object(TmcComSpi, 'read_reg', return_value= (b'U\xc0\x1e\x00\x00\xca', None)):
22
+ reg_ans, _ = self.tmc_uart.read_int(0x00)
24
23
  self.assertEqual(reg_ans, 94283625398474, "read_int is wrong")
25
24
 
26
25
 
@@ -19,9 +19,8 @@ class TestTmcComUart(unittest.TestCase):
19
19
  def test_read_int(self):
20
20
  """test_read_int"""
21
21
  self.tmc_uart.ser = 1 # to avoid early return, due to ser being None
22
- with mock.patch.object(TmcComUart, 'read_reg', return_value=
23
- b'U\x00o\x03\x05\xffo\xc0\x1e\x00\x00\xca'):
24
- reg_ans = self.tmc_uart.read_int(0x00)
22
+ with mock.patch.object(TmcComUart, 'read_reg', return_value= (b'U\x00o\x03\x05\xffo\xc0\x1e\x00\x00\xca', None)):
23
+ reg_ans, _ = self.tmc_uart.read_int(0x00)
25
24
  self.assertEqual(reg_ans, -1071775744, "read_int is wrong")
26
25
 
27
26
 
File without changes