smartpi 0.1.16__py3-none-any.whl → 0.1.18__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.
- smartpi/__init__.py +1 -1
- smartpi/base_driver.py +54 -15
- smartpi/trace.py +0 -2
- {smartpi-0.1.16.dist-info → smartpi-0.1.18.dist-info}/METADATA +1 -1
- {smartpi-0.1.16.dist-info → smartpi-0.1.18.dist-info}/RECORD +7 -7
- {smartpi-0.1.16.dist-info → smartpi-0.1.18.dist-info}/WHEEL +0 -0
- {smartpi-0.1.16.dist-info → smartpi-0.1.18.dist-info}/top_level.txt +0 -0
smartpi/__init__.py
CHANGED
smartpi/base_driver.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# coding=utf-8
|
|
2
|
-
import serial,time,struct,threading
|
|
2
|
+
import serial,time,struct,threading,fcntl
|
|
3
3
|
from typing import List, Optional
|
|
4
4
|
from collections import deque
|
|
5
5
|
from . import servo,motor,cw2015,gui
|
|
@@ -201,6 +201,7 @@ def process_received_data():
|
|
|
201
201
|
##############################################################################读取设备信息
|
|
202
202
|
"""读取设备型号"""
|
|
203
203
|
def read_device_model() -> Optional[bytes]:
|
|
204
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
204
205
|
serial_lock.acquire() #获取线程锁
|
|
205
206
|
write_data(READ_MODEL_H, READ_MODEL_L)
|
|
206
207
|
start_time = time.time()
|
|
@@ -208,6 +209,7 @@ def read_device_model() -> Optional[bytes]:
|
|
|
208
209
|
response =process_received_data()
|
|
209
210
|
if response:
|
|
210
211
|
serial_lock.release() #释放线程锁
|
|
212
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
211
213
|
display_data = response[6:-3].decode(errors="ignore")
|
|
212
214
|
# print(f"设备型号: {display_data}")
|
|
213
215
|
return display_data
|
|
@@ -216,10 +218,12 @@ def read_device_model() -> Optional[bytes]:
|
|
|
216
218
|
print("读取超时")
|
|
217
219
|
buffer.clear()
|
|
218
220
|
serial_lock.release() #释放线程锁
|
|
221
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
219
222
|
return None
|
|
220
223
|
|
|
221
224
|
"""读取版本号"""
|
|
222
225
|
def read_version() -> Optional[bytes]:
|
|
226
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
223
227
|
serial_lock.acquire() #获取线程锁
|
|
224
228
|
write_data(READ_VERSION_H, READ_VERSION_L)
|
|
225
229
|
start_time = time.time()
|
|
@@ -227,6 +231,7 @@ def read_version() -> Optional[bytes]:
|
|
|
227
231
|
response =process_received_data()
|
|
228
232
|
if response:
|
|
229
233
|
serial_lock.release() #释放线程锁
|
|
234
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
230
235
|
display_data = response[6:-3].decode(errors="ignore")
|
|
231
236
|
# print(f"版本号: {display_data}")
|
|
232
237
|
return display_data
|
|
@@ -235,10 +240,12 @@ def read_version() -> Optional[bytes]:
|
|
|
235
240
|
print("读取超时")
|
|
236
241
|
buffer.clear()
|
|
237
242
|
serial_lock.release() #释放线程锁
|
|
243
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
238
244
|
return None
|
|
239
245
|
|
|
240
246
|
"""读取工厂信息"""
|
|
241
247
|
def read_factory_data() -> Optional[bytes]:
|
|
248
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
242
249
|
serial_lock.acquire() #获取线程锁
|
|
243
250
|
write_data(READ_FACTORY_H, READ_FACTORY_L)
|
|
244
251
|
start_time = time.time()
|
|
@@ -246,6 +253,7 @@ def read_factory_data() -> Optional[bytes]:
|
|
|
246
253
|
response =process_received_data()
|
|
247
254
|
if response:
|
|
248
255
|
serial_lock.release() #释放线程锁
|
|
256
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
249
257
|
display_data = response[6:-3].decode(errors="ignore")
|
|
250
258
|
# print(f"厂家信息: {display_data}")
|
|
251
259
|
return display_data
|
|
@@ -254,10 +262,12 @@ def read_factory_data() -> Optional[bytes]:
|
|
|
254
262
|
print("读取超时")
|
|
255
263
|
buffer.clear()
|
|
256
264
|
serial_lock.release() #释放线程锁
|
|
265
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
257
266
|
return None
|
|
258
267
|
|
|
259
268
|
"""读取硬件ID"""
|
|
260
269
|
def read_hardware_ID() -> Optional[bytes]:
|
|
270
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
261
271
|
serial_lock.acquire() #获取线程锁
|
|
262
272
|
write_data(READ_HW_ID_H, READ_HW_ID_L)
|
|
263
273
|
start_time = time.time()
|
|
@@ -265,6 +275,7 @@ def read_hardware_ID() -> Optional[bytes]:
|
|
|
265
275
|
response =process_received_data()
|
|
266
276
|
if response:
|
|
267
277
|
serial_lock.release() #释放线程锁
|
|
278
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
268
279
|
display_data = response[6:-3].decode(errors="ignore")
|
|
269
280
|
# print(f"硬件ID: {display_data}")
|
|
270
281
|
return display_data
|
|
@@ -273,10 +284,12 @@ def read_hardware_ID() -> Optional[bytes]:
|
|
|
273
284
|
print("读取超时")
|
|
274
285
|
buffer.clear()
|
|
275
286
|
serial_lock.release() #释放线程锁
|
|
287
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
276
288
|
return None
|
|
277
289
|
|
|
278
290
|
"""读取设备名称"""
|
|
279
291
|
def read_device_name() -> Optional[bytes]:
|
|
292
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
280
293
|
serial_lock.acquire() #获取线程锁
|
|
281
294
|
write_data(READ_NAME_H, READ_NAME_L)
|
|
282
295
|
start_time = time.time()
|
|
@@ -284,6 +297,7 @@ def read_device_name() -> Optional[bytes]:
|
|
|
284
297
|
response =process_received_data()
|
|
285
298
|
if response:
|
|
286
299
|
serial_lock.release() #释放线程锁
|
|
300
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
287
301
|
display_data = response[6:-3].decode(errors="ignore")
|
|
288
302
|
# print(f"设备名称: {display_data}")
|
|
289
303
|
return display_data
|
|
@@ -292,10 +306,12 @@ def read_device_name() -> Optional[bytes]:
|
|
|
292
306
|
print("读取超时")
|
|
293
307
|
buffer.clear()
|
|
294
308
|
serial_lock.release() #释放线程锁
|
|
309
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
295
310
|
return None
|
|
296
311
|
|
|
297
312
|
"""设置设备名称"""
|
|
298
313
|
def write_device_name(send_data: str) -> Optional[bytes]:
|
|
314
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
299
315
|
serial_lock.acquire() #获取线程锁
|
|
300
316
|
data_bytes = send_data.encode('utf-8')
|
|
301
317
|
write_data(WRITE_NAME_H, WRITE_NAME_L, data_bytes)
|
|
@@ -304,6 +320,7 @@ def write_device_name(send_data: str) -> Optional[bytes]:
|
|
|
304
320
|
response =process_received_data()
|
|
305
321
|
if response:
|
|
306
322
|
serial_lock.release() #释放线程锁
|
|
323
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
307
324
|
display_data = response[6:-3].decode(errors="ignore")
|
|
308
325
|
# print(f"设置状态: {display_data}")
|
|
309
326
|
return 0
|
|
@@ -312,10 +329,12 @@ def write_device_name(send_data: str) -> Optional[bytes]:
|
|
|
312
329
|
print("读取超时")
|
|
313
330
|
buffer.clear()
|
|
314
331
|
serial_lock.release() #释放线程锁
|
|
332
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
315
333
|
return None
|
|
316
334
|
|
|
317
335
|
"""读取连接方式"""
|
|
318
|
-
def read_connected() -> Optional[bytes]:
|
|
336
|
+
def read_connected() -> Optional[bytes]:
|
|
337
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
319
338
|
serial_lock.acquire() #获取线程锁
|
|
320
339
|
write_data(READ_CONNECT_H, READ_CONNECT_L)
|
|
321
340
|
start_time = time.time()
|
|
@@ -323,6 +342,7 @@ def read_connected() -> Optional[bytes]:
|
|
|
323
342
|
response =process_received_data()
|
|
324
343
|
if response:
|
|
325
344
|
serial_lock.release() #释放线程锁
|
|
345
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
326
346
|
display_data = response[6:-3].decode(errors="ignore")
|
|
327
347
|
# print(f"连接方式: {display_data}")
|
|
328
348
|
return display_data
|
|
@@ -330,7 +350,8 @@ def read_connected() -> Optional[bytes]:
|
|
|
330
350
|
if time.time() - start_time > 3:
|
|
331
351
|
print("读取超时")
|
|
332
352
|
buffer.clear()
|
|
333
|
-
serial_lock.release() #释放线程锁
|
|
353
|
+
serial_lock.release() #释放线程锁
|
|
354
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
334
355
|
return None
|
|
335
356
|
|
|
336
357
|
"""读取电池电量百分比"""
|
|
@@ -442,14 +463,16 @@ def read_battery() -> Optional[bytes]:
|
|
|
442
463
|
###############################################################################读取传感器信息
|
|
443
464
|
|
|
444
465
|
"""读取外设连接情况"""
|
|
445
|
-
def read_peripheral() -> Optional[bytes]:
|
|
446
|
-
|
|
466
|
+
def read_peripheral() -> Optional[bytes]:
|
|
467
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
468
|
+
serial_lock.acquire() #获取线程锁
|
|
447
469
|
write_data(READ_PERIPH_H, READ_PERIPH_L)
|
|
448
470
|
start_time = time.time()
|
|
449
471
|
while True:
|
|
450
472
|
response =process_received_data()
|
|
451
473
|
if response:
|
|
452
|
-
|
|
474
|
+
serial_lock.release() #释放线程锁
|
|
475
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
453
476
|
display_data = response[6:-3]
|
|
454
477
|
# for x in display_data:
|
|
455
478
|
# print(f"{x:02X}", end=' ')
|
|
@@ -459,11 +482,13 @@ def read_peripheral() -> Optional[bytes]:
|
|
|
459
482
|
if time.time() - start_time > 3:
|
|
460
483
|
print("读取超时")
|
|
461
484
|
buffer.clear()
|
|
462
|
-
|
|
485
|
+
serial_lock.release() #释放线程锁
|
|
486
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
463
487
|
return None
|
|
464
488
|
|
|
465
489
|
"""单次操作外设"""
|
|
466
|
-
def single_operate_sensor(op_struct: bytes) -> Optional[bytes]:
|
|
490
|
+
def single_operate_sensor(op_struct: bytes) -> Optional[bytes]:
|
|
491
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
467
492
|
serial_lock.acquire() #获取线程锁
|
|
468
493
|
write_data(SINGLE_OP_H, SINGLE_OP_L, op_struct)
|
|
469
494
|
start_time = time.time()
|
|
@@ -471,6 +496,7 @@ def single_operate_sensor(op_struct: bytes) -> Optional[bytes]:
|
|
|
471
496
|
response =process_received_data()
|
|
472
497
|
if response:
|
|
473
498
|
serial_lock.release() #释放线程锁
|
|
499
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
474
500
|
display_data = response[6:-3]
|
|
475
501
|
# for x in display_data:
|
|
476
502
|
# print(f"{x:02X}", end=' ')
|
|
@@ -481,6 +507,7 @@ def single_operate_sensor(op_struct: bytes) -> Optional[bytes]:
|
|
|
481
507
|
print("读取超时")
|
|
482
508
|
buffer.clear()
|
|
483
509
|
serial_lock.release() #释放线程锁
|
|
510
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
484
511
|
return None
|
|
485
512
|
|
|
486
513
|
#P端口初始化释放
|
|
@@ -494,7 +521,8 @@ def P_port_init(port:bytes) -> Optional[bytes]:
|
|
|
494
521
|
return None
|
|
495
522
|
|
|
496
523
|
"""从机模式转换"""
|
|
497
|
-
def mode_change(send_data: str) -> Optional[bytes]:
|
|
524
|
+
def mode_change(send_data: str) -> Optional[bytes]:
|
|
525
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
498
526
|
serial_lock.acquire() #获取线程锁
|
|
499
527
|
write_data(MODE_CHANGE_H, MODE_CHANGE_L, send_data)
|
|
500
528
|
start_time = time.time()
|
|
@@ -502,6 +530,7 @@ def mode_change(send_data: str) -> Optional[bytes]:
|
|
|
502
530
|
response =process_received_data()
|
|
503
531
|
if response:
|
|
504
532
|
serial_lock.release() #释放线程锁
|
|
533
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
505
534
|
display_data = response[6:-3]
|
|
506
535
|
# for x in display_data:
|
|
507
536
|
# print(f"{x:02X}", end=' ')
|
|
@@ -512,10 +541,12 @@ def mode_change(send_data: str) -> Optional[bytes]:
|
|
|
512
541
|
print("读取超时")
|
|
513
542
|
buffer.clear()
|
|
514
543
|
serial_lock.release() #释放线程锁
|
|
544
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
515
545
|
return None
|
|
516
546
|
|
|
517
547
|
"""智能模式发送周期"""
|
|
518
|
-
def mode_change(send_data: str) -> Optional[bytes]:
|
|
548
|
+
def mode_change(send_data: str) -> Optional[bytes]:
|
|
549
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
519
550
|
serial_lock.acquire() #获取线程锁
|
|
520
551
|
write_data(SEND_CYCLE_H, SEND_CYCLE_L, send_data)
|
|
521
552
|
start_time = time.time()
|
|
@@ -523,6 +554,7 @@ def mode_change(send_data: str) -> Optional[bytes]:
|
|
|
523
554
|
response =process_received_data()
|
|
524
555
|
if response:
|
|
525
556
|
serial_lock.release() #释放线程锁
|
|
557
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
526
558
|
display_data = response[6:-3]
|
|
527
559
|
# for x in display_data:
|
|
528
560
|
# print(f"{x:02X}", end=' ')
|
|
@@ -532,28 +564,35 @@ def mode_change(send_data: str) -> Optional[bytes]:
|
|
|
532
564
|
if time.time() - start_time > 3:
|
|
533
565
|
print("读取超时")
|
|
534
566
|
buffer.clear()
|
|
535
|
-
serial_lock.release() #释放线程锁
|
|
567
|
+
serial_lock.release() #释放线程锁
|
|
568
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
536
569
|
return None
|
|
537
570
|
|
|
538
|
-
def shut_down(
|
|
571
|
+
def shut_down():
|
|
572
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
539
573
|
serial_lock.acquire() #获取线程锁
|
|
540
|
-
|
|
574
|
+
write_data(0XFF, 0XFE)
|
|
541
575
|
serial_lock.release() #释放线程锁
|
|
576
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
542
577
|
time.sleep(0.5)
|
|
543
578
|
|
|
544
|
-
def shut_down_state(
|
|
579
|
+
def shut_down_state() -> bool:
|
|
580
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
545
581
|
serial_lock.acquire() #获取线程锁
|
|
546
|
-
response =
|
|
582
|
+
response =process_received_data()
|
|
547
583
|
if response:
|
|
548
584
|
receive_data = response[4:-3]
|
|
549
585
|
if receive_data[0]==0XFF and receive_data[1]==0XFE:
|
|
550
586
|
serial_lock.release() #释放线程锁
|
|
587
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
551
588
|
return True
|
|
552
589
|
else:
|
|
553
590
|
serial_lock.release() #释放线程锁
|
|
591
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
554
592
|
return False
|
|
555
593
|
else:
|
|
556
594
|
serial_lock.release() #释放线程锁
|
|
595
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
557
596
|
return False
|
|
558
597
|
|
|
559
598
|
"""H2-RCU初始化"""
|
smartpi/trace.py
CHANGED
|
@@ -12,8 +12,6 @@ def get_analog(port:bytes, chn:bytes) -> Optional[bytes]:
|
|
|
12
12
|
if response == None:
|
|
13
13
|
return None
|
|
14
14
|
else:
|
|
15
|
-
trace_data=response[4:-1]
|
|
16
|
-
trace_num=int.from_bytes(trace_data, byteorder='big', signed=True)
|
|
17
15
|
return response[4]
|
|
18
16
|
|
|
19
17
|
#循迹卡设置全部颜色 port:连接P端口;正常返回:通道光值数据; 读取错误:None
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
smartpi/__init__.py,sha256
|
|
2
|
-
smartpi/base_driver.py,sha256=
|
|
1
|
+
smartpi/__init__.py,sha256=yJNr8Bjm6Zi2geMqxDuEXaioVKTS4NGMUm5hfEW0TLQ,55
|
|
2
|
+
smartpi/base_driver.py,sha256=3acmLtIcCW9sgPlPN7C10TGPIO_tCISC_QWLzNTM2X4,23846
|
|
3
3
|
smartpi/color_sensor.py,sha256=sTqD3jApjmc6qHMrDyEy2UjaRt8vhJZNR88vzgUiLKs,496
|
|
4
4
|
smartpi/cw2015.py,sha256=1lAF-pi_ye_ya1AZQS1sjbgsDf7MThO5IAskKsNGBzA,5695
|
|
5
5
|
smartpi/flash.py,sha256=Luz0TjinQSkx31uVknqfSWkiAiVrqIE2Iba7lk3AOzM,4132
|
|
@@ -12,9 +12,9 @@ smartpi/move.py,sha256=3qzrJCGA-qbsLXBpklY2DErtw0jlzMELzozjhEvRzKs,6028
|
|
|
12
12
|
smartpi/servo.py,sha256=B6X3yCoEz82qqpUIE5MSO0Eg9YZJ5zDzJEcRpioZpUo,4625
|
|
13
13
|
smartpi/temperature.py,sha256=px2YeqgG63nPkyhJA1wDg3dwYx_oOCYuhMjtsVm_YO0,460
|
|
14
14
|
smartpi/touch_sensor.py,sha256=F6IIQGewNRhC9U1RbHpVzuGYqb8H41lpeQ1Ejwsc_T8,438
|
|
15
|
-
smartpi/trace.py,sha256=
|
|
15
|
+
smartpi/trace.py,sha256=dtZQAkUUIsq578hycwrfR9GJUsIUCbHCF4ZvJv9GLrs,984
|
|
16
16
|
smartpi/ultrasonic.py,sha256=0meczFKXFLUt92kLxipeEc37vb5duvJjPs4kgtlpO8M,622
|
|
17
|
-
smartpi-0.1.
|
|
18
|
-
smartpi-0.1.
|
|
19
|
-
smartpi-0.1.
|
|
20
|
-
smartpi-0.1.
|
|
17
|
+
smartpi-0.1.18.dist-info/METADATA,sha256=ShLsBIEi6ruwSr-BoqJWYwrvHyrc8Mn0xinRrWmYgng,311
|
|
18
|
+
smartpi-0.1.18.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
19
|
+
smartpi-0.1.18.dist-info/top_level.txt,sha256=PoLhUCmWAiQUg5UeN2fS-Y1iQyBbF2rdUlizXtpHGRQ,8
|
|
20
|
+
smartpi-0.1.18.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|