1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| fenêtre interactive Python 3.10 (64-bit) [PTVS 17.0.22089.1-17.0]
Tapez $help pour obtenir la liste des commandes.
>>> import sys
>>> import asyncio
>>> import platform
>>> import logging
>>> import keyboard
>>> import csv
>>> from multimeter import *
>>> import matplotlib.pyplot as plt
>>> from bleak import BleakClient
>>> ADDRESS = ("FC:58:FA:53:61:C0")
>>> CHARACTERISTIC_UUID = '0000fff0-0000-1000-8000-00805f9b34fb' # <--- Change to the characteristic you want to enable notifications from.
>>> dataGraph = []
>>> multimeter = ['AN9002']
>>> lastDisplayedUnit = ""
>>> def notification_handler(sender, data):
... global dataGraph
... global multimeter
... global lastDisplayedUnit
... """Simple notification handler which prints the data received."""
... #print("Data multimeter: {0}".format(data.hex(' ') ))
... multimeter.SetMeasuredValue(data)
... displayedData = multimeter.GetDisplayedValue()
... if multimeter.overloadFlag:
... displayedData = 99999
... print("Overload")
...
... unit = multimeter.GetDisplayedUnit()
... if lastDisplayedUnit == "":
... lastDisplayedUnit = unit
...
... if unit != lastDisplayedUnit:
... lastDisplayedUnit = unit
... dataGraph.clear()
... plt.clf()
...
... dataGraph.append(displayedData)
... plt.ylabel(unit)
... print(str(displayedData) + " " + unit)
...
...
>>> async def run(address): client: BleakClient(address)
>>> try:
File "<stdin>", line 1
try:
IndentationError: unexpected indent
>>> await client.connect()
File "<stdin>", line 1
await client.connect()
IndentationError: unexpected indent
>>> await client.start_notify(CHARACTERISTIC_UUID, notification_handler)
File "<stdin>", line 1
await client.start_notify(CHARACTERISTIC_UUID, notification_handler)
IndentationError: unexpected indent
>>> while(1):
File "<stdin>", line 1
while(1):
IndentationError: unexpected indent
>>> if keyboard.is_pressed("q"):
File "<stdin>", line 1
if keyboard.is_pressed("q"):
IndentationError: unexpected indent
>>> print("Shutting down!");
File "<stdin>", line 1
print("Shutting down!");
IndentationError: unexpected indent
>>> break;
File "<stdin>", line 1
break;
IndentationError: unexpected indent
>>> else:
File "<stdin>", line 1
else:
IndentationError: unexpected indent
>>> plt.plot(dataGraph, color='b')
File "<stdin>", line 1
plt.plot(dataGraph, color='b')
IndentationError: unexpected indent
>>> plt.draw()
File "<stdin>", line 1
plt.draw()
IndentationError: unexpected indent
>>> plt.pause(0.1)
File "<stdin>", line 1
plt.pause(0.1)
IndentationError: unexpected indent
>>> await asyncio.sleep(0.5)
File "<stdin>", line 1
await asyncio.sleep(0.5)
IndentationError: unexpected indent
>>> except Exception as e:
File "<stdin>", line 1
except Exception as e:
IndentationError: unexpected indent
>>> print(e)
File "<stdin>", line 1
print(e)
IndentationError: unexpected indent
>>> finally:
File "<stdin>", line 1
finally:
IndentationError: unexpected indent
>>> await client.stop_notify(CHARACTERISTIC_UUID)
File "<stdin>", line 1
await client.stop_notify(CHARACTERISTIC_UUID)
IndentationError: unexpected indent
>>> await client.disconnect()
File "<stdin>", line 1
await client.disconnect()
IndentationError: unexpected indent
>>> if __name__ == "__main__":
... loop = asyncio.get_event_loop()
... loop.set_debug(False)
... loop.run_until_complete(run(ADDRESS))
...
...
<stdin>:2: DeprecationWarning: There is no current event loop
>>> with open('plot.csv', 'w') as f:
File "<stdin>", line 1
with open('plot.csv', 'w') as f:
IndentationError: unexpected indent
>>> wr = csv.writer(f)
File "<stdin>", line 1
wr = csv.writer(f)
IndentationError: unexpected indent
>>> wr.writerow(dataGraph) |
Partager