Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using Python pyserial
#3
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)
Reply


Messages In This Thread
using Python pyserial - by ajitnayak87 - Feb-03-2022, 04:58 PM
RE: using Python pyserial - by ajitnayak87 - Feb-03-2022, 05:18 PM
RE: using Python pyserial - by Jeff_t - Feb-03-2022, 06:14 PM
RE: using Python pyserial - by ajitnayak87 - Feb-03-2022, 08:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Can't transmit serial fast Python to Arduino pyserial mRKlean 0 2,422 Mar-29-2020, 08:12 PM
Last Post: mRKlean

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020