Happy New Year Bob
Further to our previous discussions I have tailored your code to match the connected Pico port as follows and then created a script as main.py on the Pico to test the process.
The Pico (csv file) is showing no signs of receiving the output stream from JMRI and I'm wondering what I'm missing. Are you able to help?
The scripts are:
# main.py
csv_filename = "data.csv"
def save_to_csv(data):
? ? with open(csv_filename,"a") as f:
? ? ? ? f.write(data +"\n")
while True:
? ? select_result = uselect.select([stdin], [], [], 0)
? ? buffer = ''
? ? while select_result[0]:
? ? ? ? input_character = stdin.read(1)
? ? ? ? if input_character != ',':
? ? ? ? ? ? buffer += input_character
? ? ? ? else:
? ? ? ? ? ? save_to_csv(buffer)
? ? ? ? ? ? buffer=''
? ? select_result = uselect.select([stdin], [], [], 0)
and, with print statements added to ensure that the script runs completely:
# testserialport.py
import jmri
import purejavacomm
print "purejavacomm started"
# find the port info and open the port
portname = "/dev/ttyACM2"
print "portname = " , portname
portID = purejavacomm.CommPortIdentifier.getPortIdentifier(portname)
print "portID = ", portID
port = portID.open("JMRI",50)
#set options on port
print "setting port options"
baudrate = 9600
print "baudrate = ",baudrate
port.setSerialPortParams(baudrate,purejavacomm.SerialPort.DATABITS_8, purejavacomm.SerialPort.STOPBITS_1, purejavacomm.SerialPort.PARITY_NONE)
print "port options set"
#get I/O connection for later
outputStream = port.getOutputStream()
print "port opened OK"
#to write some characters
outputStream.write('A')
outputStream.write('B')
outputStream.write('C')
outputStream.write('\n')
outputStream.flush()
#close the port
time.sleep(2)
port.close()
print "port closed"
?
Many thanks
Toni
?