Feb-03-2022, 06:14 PM
With regard to the ports this should be a guide to listing available ports
import serial.tools.list_ports ports = list(serial.tools.list_ports.comports()) for p in ports: print(p) print("\n") for p in ports: print(p.name)If the serial data is separated with a colon and terminated with "\r\n" the following should receive/strip/decode and pack the data into a list of lists suitable for the csv module. This is pseudo code and although its fairly close it still needs work to make it useable in your project. Receiving in this example is done in a separate thread.
lst_cnt=0 Main_List=[] def serial_thread(): input_string="" while True: if ser.isOpen(): input_string=ser.readline().strip().decode("utf-8") create_listof_list(input_string) def create_listof_list(my_string): global lst_cnt global Main_List Main_List.append([]) Main_List[lst_cnt]=my_string.split(":") lst_cnt+=1 def save_results(): with open('My_CSV.csv', 'w', newline="") as file: csvwriter = csv.writer(file) csvwriter.writerows(Main_List)