Fix showing graph
This commit is contained in:
0
tcd1304_viewer/WIP/__init__.py
Normal file
0
tcd1304_viewer/WIP/__init__.py
Normal file
@@ -8,22 +8,26 @@ import sys
|
||||
from tcd1304_viewer.viewer import Viewer
|
||||
|
||||
viewer = Viewer()
|
||||
cfg = [1680, 8400000]
|
||||
sh = 84 * 20
|
||||
icg = 84 * 1000 * 200
|
||||
cfg = [sh, icg]
|
||||
|
||||
if len(sys.argv) > 2:
|
||||
cfg = [int(i) for i in sys.argv[1:]]
|
||||
|
||||
msg = struct.pack("<HBII", 0x1304, 0, *cfg)
|
||||
msg = struct.pack("<HBIIIx", 0x1304, 0, 8, *cfg)
|
||||
|
||||
viewer.show()
|
||||
# viewer.show()
|
||||
|
||||
# Open the serial port
|
||||
ser = serial.Serial('/dev/serial0', baudrate=921600)
|
||||
print("Opening serial")
|
||||
ser = serial.Serial('/dev/ttyUSB0', baudrate=2457600)
|
||||
|
||||
ser.write(msg)
|
||||
|
||||
# Now read and print data from the serial port forever
|
||||
while True:
|
||||
# viewer.pause()
|
||||
m = ser.read(1)[0] << 8
|
||||
|
||||
while m != 0x1304:
|
||||
@@ -37,11 +41,11 @@ while True:
|
||||
if t == 0x00:
|
||||
print(f"content {c}")
|
||||
if t == 0x01:
|
||||
data = np.array()
|
||||
data = []
|
||||
|
||||
while len(c):
|
||||
d, c = c[:2], c[2:]
|
||||
(r, ) = struct.unpack("<H", d)
|
||||
data.append(r * 3.3 / 4096)
|
||||
|
||||
viewer.update_data(data)
|
||||
viewer.update_data(np.array(data) * -1 + 3.3)
|
||||
@@ -9,11 +9,20 @@ class Viewer:
|
||||
|
||||
plt.xlabel("Pixel")
|
||||
plt.ylabel("Tension (V)")
|
||||
plt.legend()
|
||||
# plt.legend()
|
||||
plt.ylim(0, 3.4)
|
||||
|
||||
x = np.arange(1, len(data) + 1)
|
||||
|
||||
plt.plot(x, data, label="Intensity")
|
||||
# plt.draw()
|
||||
|
||||
self.show()
|
||||
self.pause()
|
||||
|
||||
def show(self) -> None:
|
||||
plt.show()
|
||||
plt.ion()
|
||||
plt.show(block=False)
|
||||
|
||||
def pause(self, secs: float = 0.001) -> None:
|
||||
plt.pause(secs)
|
||||
Reference in New Issue
Block a user