Reading Arduino serial on PC

I am currently using a Mac, but for a project I will need to execute the following on a PC. I have a python script attached to read streaming data from the Arduino serial and write it to a text file. I am using Terminal to run that python script.

Now I need to be able to translate this to PC so I can do the exact same thing on a different computer. Can you help me with this, as I am fairly new to programming? Also, what is the Windows equivalent to Terminal to let me run this (potentially adjusted) python script?

Thanks!

import serial
import subprocess

ser = serial.Serial('/dev/cu.usbmodem145101')
ser.flushInput()
output_file = None
START = True
counter = 0

while True:
    try:
        ser_bytes = ser.readline()
        data = float(ser_bytes)
        if START == True:
            output_file = open("output.txt", "a+")
        output_file.write(str(data) + "\n")
        START = False
        if counter % 100 == 0:
            output_file.close()
            START = True
        counter += 1

    except:
        print("Keyboard Interrupt")
        break

With a suitable change to the description of the serial port I would expect Python code to work on your Windows PC - howeverI use Linux and it is a long time since I used Windows.

...R

So with some more work, I've got it writing to a text file (and also print to Arduino serial monitor for troubleshooting purposes) at the rate I'd like. I'm running the attached python script through Command Prompt while running data through Arduino serial.

My current issue is that it is writing b'' on repeat instead of a number for each line. I originally had
data = float(ser_bytes) but that would end the program, so I changed it to data = str(ser_bytes), which now writes but writes the wrong thing.

Has anyone seen this b'' thing before? Any ideas for how to remedy this problem and have it write my data to the text file?

import serial

ser = serial.Serial('COM5', 9600, timeout=0)
ser.flushInput()
output_file = None
START = True
write_counter = 0
close_counter = 0

while True:
	try:
		ser_bytes = ser.readline()
		data = str(ser_bytes)
		if START == True:
			output_file = open("output.txt", "a+")
		if write_counter % 40000 == 0:
			output_file.write(str(data) + "\n")
			print(data)
		START = False
		if close_counter % 100 == 0:
			output_file.close()
			START = True
		write_counter += 1
		close_counter += 1

	except:
		print("Keyboard Interrupt")
		break

That looks like a Python programming problem and this is the Arduino Forum, not the Python Forum.

Maybe this Simple Python - Arduino demo will give you some ideas.

…R