/usr/bin/env python3 import serial import csv import sys #excel stuff #from time import gmtime, strftime #resultFile=open('MyData.csv','wb') #end excel stuff def scan : 'scan for available ports. Return a list of tuples (num, name)' available = for i in range ( 256 ): try: s = serial. Serial ( i ) available. Append ( ( i, s. Portstr )) s. Close # explicit close 'cause of delayed GC in java except serial.
PySerial: how to understand that the timeout occured while reading from serial port? 0 How to send a command to RS232 Serial Port PBX Harris 20-20 using pySerial? For Handle to give a positive result, the TeraTerm program would need to currently have the serial port open. If you haven't started a terminal session.
SerialException: pass return available if name 'main': print ( 'Found ports:' ) for n, s in scan : print ( '(%d )%s '% ( n, s )) selection = input ( 'Enter port number:' ) try: ser = serial. Serial ( eval ( selection ), 9600, timeout = 1 ) print ( 'connected to: ' + ser.
Portstr ) except serial. SerialException: pass while True: # Read a line and convert it from b'xxx r n' to xxx line = ser. Decode ( 'utf-8' ): - 1 if line: # If it isn't a blank line f = open ( 'out.txt', 'w' ) print f. Close #print(line) #with open('test.csv', 'w') as csvfile: # writer = csv.DictWriter(csvfile, fieldnames='header1', lineterminator=' n') ser. Close I tried to output it, but it just creates a blank file called test.csv.
I would also like it to automatically end the script on a particular set of text. Example serial port output: 71.6, 71.7, 71.7, 71.8, 71.8, The ending output I want the script to finish on is: Any help would be greatly appreciated! Edited Jun 24, 2015 at 22:06 UTC. /usr/bin/env python3 import serial import csv import sys import io def scan : 'scan for available ports. Return a list of tuples (num, name)' available = for i in range ( 256 ): try: s = serial.
Serial ( i ) available. Append ( ( i, s. Portstr )) s. Close # explicit close 'cause of delayed GC in java except serial. SerialException: pass return available if name 'main': print ( 'Found ports:' ) for n, s in scan : print ( '(%d )%s '% ( n, s )) selection = input ( 'Enter port number:' ) try: ser = serial. Serial ( eval ( selection ), 9600, timeout = 1 ) print ( 'connected to: ' + ser. Portstr ) except serial.
SerialException: pass while True: # Read a line and convert it from b'xxx r n' to xxx line = ser. Decode ( 'utf-8' ): - 1 if line: # If it isn't a blank line sys. Stdout = open ( 'output.csv', 'w+' ) print ( line ) f.
Close #print(line) #with open('test.csv', 'w') as csvfile: # writer = csv.DictWriter(csvfile, fieldnames='header1', lineterminator=' n') ser.
/usr/bin/env python3 import serial import csv import sys #excel stuff #from time import gmtime, strftime #resultFile=open('MyData.csv','wb') #end excel stuff def scan : 'scan for available ports. Return a list of tuples (num, name)' available = for i in range ( 256 ): try: s = serial. Serial ( i ) available. Append ( ( i, s. Portstr )) s. Close # explicit close 'cause of delayed GC in java except serial. SerialException: pass return available if name 'main': print ( 'Found ports:' ) for n, s in scan : print ( '(%d )%s '% ( n, s )) selection = input ( 'Enter port number:' ) try: ser = serial.
Serial ( eval ( selection ), 9600, timeout = 1 ) print ( 'connected to: ' + ser. Portstr ) except serial. SerialException: pass while True: # Read a line and convert it from b'xxx r n' to xxx line = ser. Decode ( 'utf-8' ): - 1 if line: # If it isn't a blank line f = open ( 'out.txt', 'w' ) print f. Close #print(line) #with open('test.csv', 'w') as csvfile: # writer = csv.DictWriter(csvfile, fieldnames='header1', lineterminator=' n') ser. Close I tried to output it, but it just creates a blank file called test.csv.
I would also like it to automatically end the script on a particular set of text. Example serial port output: 71.6, 71.7, 71.7, 71.8, 71.8, The ending output I want the script to finish on is: Any help would be greatly appreciated! Edited Jun 24, 2015 at 22:06 UTC. /usr/bin/env python3 import serial import csv import sys import io def scan : 'scan for available ports. Return a list of tuples (num, name)' available = for i in range ( 256 ): try: s = serial. Serial ( i ) available.
Append ( ( i, s. Portstr )) s. Close # explicit close 'cause of delayed GC in java except serial. SerialException: pass return available if name 'main': print ( 'Found ports:' ) for n, s in scan : print ( '(%d )%s '% ( n, s )) selection = input ( 'Enter port number:' ) try: ser = serial. Serial ( eval ( selection ), 9600, timeout = 1 ) print ( 'connected to: ' + ser.
Portstr ) except serial. SerialException: pass while True: # Read a line and convert it from b'xxx r n' to xxx line = ser. Decode ( 'utf-8' ): - 1 if line: # If it isn't a blank line sys. Stdout = open ( 'output.csv', 'w+' ) print ( line ) f.
Close #print(line) #with open('test.csv', 'w') as csvfile: # writer = csv.DictWriter(csvfile, fieldnames='header1', lineterminator=' n') ser.