moons-motor 0.1.2__py3-none-any.whl → 0.1.3__py3-none-any.whl
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.
- moons_motor/motor.py +51 -21
- {moons_motor-0.1.2.dist-info → moons_motor-0.1.3.dist-info}/METADATA +1 -1
- {moons_motor-0.1.2.dist-info → moons_motor-0.1.3.dist-info}/RECORD +6 -6
- {moons_motor-0.1.2.dist-info → moons_motor-0.1.3.dist-info}/WHEEL +1 -1
- {moons_motor-0.1.2.dist-info → moons_motor-0.1.3.dist-info}/licenses/LICENSE +0 -0
- {moons_motor-0.1.2.dist-info → moons_motor-0.1.3.dist-info}/top_level.txt +0 -0
moons_motor/motor.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import serial
|
2
|
+
import serial.rs485
|
2
3
|
from serial.tools import list_ports
|
3
4
|
import re
|
4
5
|
import threading
|
@@ -110,9 +111,10 @@ class MoonsStepper(Subject):
|
|
110
111
|
self.Opened = False
|
111
112
|
self.recvQueue = queue.Queue()
|
112
113
|
self.sendQueue = queue.Queue()
|
113
|
-
self.pending_callbacks =
|
114
|
+
self.pending_callbacks = queue.Queue()
|
114
115
|
self.update_thread = None
|
115
116
|
self.is_updating = False
|
117
|
+
self.readBuffer = ""
|
116
118
|
|
117
119
|
self.console = Console()
|
118
120
|
|
@@ -183,7 +185,22 @@ class MoonsStepper(Subject):
|
|
183
185
|
|
184
186
|
def attempt_connect(COM, baudrate):
|
185
187
|
try:
|
186
|
-
self.ser = serial.Serial(
|
188
|
+
# self.ser = serial.Serial(
|
189
|
+
# port=COM,
|
190
|
+
# baudrate=baudrate,
|
191
|
+
# bytesize=serial.EIGHTBITS,
|
192
|
+
# parity=serial.PARITY_NONE,
|
193
|
+
# stopbits=serial.STOPBITS_ONE,
|
194
|
+
# timeout=0.5,
|
195
|
+
# )
|
196
|
+
self.ser = serial.rs485.RS485(port=COM, baudrate=baudrate)
|
197
|
+
self.ser.rs485_mode = serial.rs485.RS485Settings(
|
198
|
+
rts_level_for_tx=True,
|
199
|
+
rts_level_for_rx=False,
|
200
|
+
loopback=False,
|
201
|
+
delay_before_tx=0.02,
|
202
|
+
delay_before_rx=0.02,
|
203
|
+
)
|
187
204
|
if self.ser is None:
|
188
205
|
self.Opened = False
|
189
206
|
if self.ser.is_open:
|
@@ -236,6 +253,8 @@ class MoonsStepper(Subject):
|
|
236
253
|
callback(self.device, self.Opened)
|
237
254
|
|
238
255
|
def disconnect(self):
|
256
|
+
self.send_command(command=StepperCommand.STOP_KILL)
|
257
|
+
time.sleep(0.5)
|
239
258
|
self.sendQueue.queue.clear()
|
240
259
|
self.recvQueue.queue.clear()
|
241
260
|
self.is_updating = False
|
@@ -259,7 +278,6 @@ class MoonsStepper(Subject):
|
|
259
278
|
self.temp_cmd = command + "\r"
|
260
279
|
|
261
280
|
if self.ser is not None or not self.only_simulate:
|
262
|
-
self.temp_cmd += "\r"
|
263
281
|
self.ser.write(self.temp_cmd.encode("ascii"))
|
264
282
|
if self.is_log_message:
|
265
283
|
print(
|
@@ -287,20 +305,28 @@ class MoonsStepper(Subject):
|
|
287
305
|
if self.ser.in_waiting > 0:
|
288
306
|
response = self.ser.read(self.ser.in_waiting)
|
289
307
|
response = response.decode("ascii", errors="ignore").strip()
|
290
|
-
|
291
|
-
|
308
|
+
response = response.split("\r")
|
309
|
+
|
310
|
+
for r in response:
|
311
|
+
if r != "":
|
312
|
+
self.readBuffer += r
|
313
|
+
self.handle_recv(r)
|
314
|
+
|
292
315
|
if self.sendQueue.empty() != True:
|
316
|
+
# time.sleep(
|
317
|
+
# 0.02
|
318
|
+
# ) # Time for RS485 converter to switch between Transmit and Receive mode
|
293
319
|
while not self.sendQueue.empty():
|
320
|
+
# time.sleep(
|
321
|
+
# 0.05
|
322
|
+
# ) # Time for RS485 converter to switch between Transmit and Receive mode
|
294
323
|
cmd = self.sendQueue.get_nowait()
|
295
324
|
self.send(cmd)
|
296
325
|
self.sendQueue.task_done()
|
297
|
-
time.sleep(
|
298
|
-
0.01
|
299
|
-
) # Time for RS485 converter to switch between Transmit and Receive mode
|
300
326
|
|
301
327
|
def handle_recv(self, response):
|
302
328
|
if "*" in response:
|
303
|
-
print("buffered_ack")
|
329
|
+
print(f"[bold green](o)buffered_ack[/bold green]")
|
304
330
|
elif "%" in response:
|
305
331
|
print(f"[bold green](v)success_ack[/bold green]")
|
306
332
|
elif "?" in response:
|
@@ -309,22 +335,26 @@ class MoonsStepper(Subject):
|
|
309
335
|
print(f"[bold blue]Received from {self.device}: [/bold blue]", response)
|
310
336
|
self.recvQueue.put_nowait(response)
|
311
337
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
338
|
+
if "=" in response:
|
339
|
+
callback = self.pending_callbacks.get_nowait()
|
340
|
+
if callback:
|
341
|
+
callback(response)
|
342
|
+
# for command, callback in list(self.pending_callbacks.items()):
|
343
|
+
# if command in response:
|
344
|
+
# if callback:
|
345
|
+
# callback(response)
|
346
|
+
# del self.pending_callbacks[command]
|
347
|
+
# break
|
318
348
|
|
319
349
|
# endregion
|
320
350
|
|
321
351
|
# region motor motion functions
|
322
352
|
|
323
|
-
def setup_motor(self, motor_address="", kill=False):
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
353
|
+
# def setup_motor(self, motor_address="", kill=False):
|
354
|
+
# if kill:
|
355
|
+
# self.stop_and_kill(motor_address)
|
356
|
+
# self.set_transmit_delay(motor_address, 25)
|
357
|
+
# self.set_return_format_dexcimal(motor_address)
|
328
358
|
|
329
359
|
def home(self, motor_address="", speed=0.3, onComplete=None):
|
330
360
|
self.send_command(
|
@@ -348,7 +378,7 @@ class MoonsStepper(Subject):
|
|
348
378
|
def get_status(self, motor_address, command: StepperCommand, callback=None):
|
349
379
|
command = self.addressed_cmd(motor_address, command)
|
350
380
|
if callback:
|
351
|
-
self.pending_callbacks
|
381
|
+
self.pending_callbacks.put_nowait(callback)
|
352
382
|
self.sendQueue.put_nowait(command)
|
353
383
|
|
354
384
|
# endregion
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: moons_motor
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.3
|
4
4
|
Summary: This is a python library for controlling the Moons' motor through the serial port.
|
5
5
|
Author-email: miroc <mike8503111@gmail.com>
|
6
6
|
Project-URL: Repository, https://github.com/miroc99/moons_motor.git
|
@@ -1,11 +1,11 @@
|
|
1
1
|
moons_motor/__init__.py,sha256=qOpsRwizV-DpKSvNzyvj8ju3cs6vwgIICur1Oe6sxOA,27
|
2
|
-
moons_motor/motor.py,sha256=
|
2
|
+
moons_motor/motor.py,sha256=rpunJXViqvSpMW9uRJDctBPyfSJnZh5WZtBtci16-Ck,13308
|
3
3
|
moons_motor/observer.py,sha256=PXzuPYKRb2HpjArJcD8HakYIPfFGAs1uBDIL8PSizgA,124
|
4
4
|
moons_motor/simulate.py,sha256=J0y1fZhoOim9i-BAkprxnPern1SAdkDfKPqT2MWyDwU,2561
|
5
5
|
moons_motor/status.py,sha256=jXQZFZTt9ugHktkWKLII8MpEQQaeO-UjlwTrrP4LJNE,2872
|
6
6
|
moons_motor/subject.py,sha256=L_GS6fvJTeX7X23o3T92oiZ4rtLVKA2OEd9GpHn_Dz4,445
|
7
|
-
moons_motor-0.1.
|
8
|
-
moons_motor-0.1.
|
9
|
-
moons_motor-0.1.
|
10
|
-
moons_motor-0.1.
|
11
|
-
moons_motor-0.1.
|
7
|
+
moons_motor-0.1.3.dist-info/licenses/LICENSE,sha256=nsYjO800SjIjI85y2kVHR5mC3tca2vs4kK_BhNe89bM,1074
|
8
|
+
moons_motor-0.1.3.dist-info/METADATA,sha256=Zaj25TLKPvBv0qJWRInaALURr8bcOtDLNWfxQymFdtY,1304
|
9
|
+
moons_motor-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
10
|
+
moons_motor-0.1.3.dist-info/top_level.txt,sha256=0dE-CR5_NYBw34jHIDGQNWpMllzO6mtUIuKyRv_rJLg,12
|
11
|
+
moons_motor-0.1.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|