I am trying to display the real time data of a instrument which communicating through serial port with baudrate of 9600. System streaming data in every 1 min. some time not streaming for 5 minutes.
I have written the code and its working but sum time not working due to error ValueError: PyCapsule_New called with null pointer.
I have tried following code
My code is follows…
import serial
import time
import keyboard
from itertools import islice
import csv
from drawnow import *
import numpy
import matplotlib.pyplot as plt
from datetime import datetime
BC880 = []
def makeFig():
plt.plot(BC880, 'ko', label='Black Carbon Conc. (ng m-3)')
plt.legend(loc='upper left')
Ser = serial.Serial('COM5')
while True:
res = Ser.readline()
decoded_bytes = res.decode('utf-8')
AE33data = islice(decoded_bytes.split(","), 11)
list_AE33data = list(AE33data)
print(list_AE33data)
with open("AE33_data.csv","a") as f:
writer = csv.writer(f,delimiter=",")
writer.writerow(list_AE33data)
BC = int(list_AE33data[8])
BC880.append(BC)
drawnow(makeFig)
Ser.close()
print('Serial Port Disconnected')
I am getting following error
Traceback (most recent call last):
File “C:/Users/AML/AppData/Local/Programs/Python/Python312/test.py”, line 30, in
drawnow(makeFig)
File “C:UsersAMLAppDataLocalProgramsPythonPython312Libsite-packagesdrawnowdrawnow.py”, line 72, in drawnow
plt.clf()
File “C:UsersAMLAppDataLocalProgramsPythonPython312Libsite-packagesmatplotlibpyplot.py”, line 1195, in clf
gcf().clear()
File “C:UsersAMLAppDataLocalProgramsPythonPython312Libsite-packagesmatplotlibpyplot.py”, line 1088, in gcf
return figure()
File “C:UsersAMLAppDataLocalProgramsPythonPython312Libsite-packagesmatplotlibpyplot.py”, line 1022, in figure
manager = new_figure_manager(
File “C:UsersAMLAppDataLocalProgramsPythonPython312Libsite-packagesmatplotlibpyplot.py”, line 545, in new_figure_manager
return _get_backend_mod().new_figure_manager(*args, **kwargs)
File “C:UsersAMLAppDataLocalProgramsPythonPython312Libsite-packagesmatplotlibbackend_bases.py”, line 3521, in new_figure_manager
return cls.new_figure_manager_given_figure(num, fig)
File “C:UsersAMLAppDataLocalProgramsPythonPython312Libsite-packagesmatplotlibbackend_bases.py”, line 3526, in new_figure_manager_given_figure
return cls.FigureCanvas.new_manager(figure, num)
File “C:UsersAMLAppDataLocalProgramsPythonPython312Libsite-packagesmatplotlibbackend_bases.py”, line 1811, in new_manager
return cls.manager_class.create_with_canvas(cls, figure, num)
File “C:UsersAMLAppDataLocalProgramsPythonPython312Libsite-packagesmatplotlibbackends_backend_tk.py”, line 479, in create_with_canvas
with _restore_foreground_window_at_end():
File “C:UsersAMLAppDataLocalProgramsPythonPython312Libcontextlib.py”, line 137, in enter
return next(self.gen)
File “C:UsersAMLAppDataLocalProgramsPythonPython312Libsite-packagesmatplotlibbackends_backend_tk.py”, line 43, in _restore_foreground_window_at_end
foreground = _c_internal_utils.Win32_GetForegroundWindow()
ValueError: PyCapsule_New called with null pointer
Expected data printing and plotting by code in real time:
[‘0683’, ‘”06-Jun-24″‘, ‘”15:06″‘, ‘ 635’, ‘ 656’, ‘ 557’, ‘ 554’, ‘ 484’, ‘ 431’, ‘ 419’, ‘ 3.0’]
[‘0683’, ‘”06-Jun-24″‘, ‘”15:07″‘, ‘ -40’, ‘ 45’, ‘ 146’, ‘ 6’, ‘ -37’, ‘ -97’, ‘ -56’, ‘ 3.0’]
[‘0683’, ‘”06-Jun-24″‘, ‘”15:08″‘, ‘ 1086’, ‘ 1089’, ‘ 862’, ‘ 843’, ‘ 777’, ‘ 809’, ‘ 765’, ‘ 3.0’]
[‘0683’, ‘”06-Jun-24″‘, ‘”15:09″‘, ‘ 996’, ‘ 909’, ‘ 1013’, ‘ 890’, ‘ 801’, ‘ 800’, ‘ 871’, ‘ 3.0’]
[‘0683’, ‘”06-Jun-24″‘, ‘”15:10″‘, ‘ 1441’, ‘ 1387’, ‘ 1219’, ‘ 1219’, ‘ 1162’, ‘ 1158’, ‘ 1113’, ‘ 3.0’]
[‘0683’, ‘”06-Jun-24″‘, ‘”15:11″‘, ‘ 735’, ‘ 796’, ‘ 679’, ‘ 624’, ‘ 535’, ‘ 545’, ‘ 501’, ‘ 3.0’]
[‘0683’, ‘”06-Jun-24″‘, ‘”15:12″‘, ‘ 503’, ‘ 493’, ‘ 504’, ‘ 509’, ‘ 395’, ‘ 305’, ‘ 359’, ‘ 3.0’]
[‘0683’, ‘”06-Jun-24″‘, ‘”15:13″‘, ‘ 326’, ‘ 366’, ‘ 259’, ‘ 153’, ‘ 173’, ‘ 132’, ‘ 148’, ‘ 3.0’]
[‘0683’, ‘”06-Jun-24″‘, ‘”15:14″‘, ‘ 746’, ‘ 705’, ‘ 753’, ‘ 673’, ‘ 538’, ‘ 594’, ‘ 591’, ‘ 3.0’]
[‘0683’, ‘”06-Jun-24″‘, ‘”15:15″‘, ‘ 759’, ‘ 859’, ‘ 673’, ‘ 756’, ‘ 599’, ‘ 643’, ‘ 566’, ‘ 3.0’]
[‘0683’, ‘”06-Jun-24″‘, ‘”15:16″‘, ‘ 1247’, ‘ 1236’, ‘ 1163’, ‘ 1019’, ‘ 1059’, ‘ 955’, ‘ 1025’, ‘ 3.0’]
[‘0683’, ‘”06-Jun-24″‘, ‘”15:17″‘, ‘ 1650’, ‘ 1438’, ‘ 1438’, ‘ 1441’, ‘ 1331’, ‘ 1391’, ‘ 1420’, ‘ 3.0’]
[‘0683’, ‘”06-Jun-24″‘, ‘”15:18″‘, ‘ 1021’, ‘ 980’, ‘ 919’, ‘ 942’, ‘ 801’, ‘ 896’, ‘ 773’, ‘ 3.0’]
[‘0683’, ‘”06-Jun-24″‘, ‘”15:19″‘, ‘ 816’, ‘ 863’, ‘ 930’, ‘ 749’, ‘ 687’, ‘ 629’, ‘ 688’, ‘ 3.0’]
enter image description here
Please help me to solve this issue
Thank you
Vishnu Kumar Dhaker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.