FreePIE Crashes When Using serialPort.ReadLine()

Official forum for open source FreePIE discussion and development.
Post Reply
kbigdelysh
One Eyed Hopeful
Posts: 1
Joined: Mon Apr 30, 2018 5:10 pm

FreePIE Crashes When Using serialPort.ReadLine()

Post by kbigdelysh »

The following script works (it outputs the expected values) but when I stop stop the script (using Script>Stop script menu command), it shows the following error message and then crashes:
Had to forcibly shut down script - try removing infinite loops from the script
at ...

Code: Select all

import clr
clr.AddReference('System')
from System import *
global serialPort

def update():
  global serialPort
  line = serialPort.ReadLine()
  diagnostics.watch(line)  

if starting:
  global serialPort
  serialPort = IO.Ports.SerialPort("COM10")
  serialPort.BaudRate = 921600
  serialPort.DataBits = 8
  serialPort.Open()

update()

I guess the issue is in the line

Code: Select all

line = serialPort.ReadLine()
but I'm not sure how to resolve it.
Leshchuk
One Eyed Hopeful
Posts: 4
Joined: Mon Jan 14, 2019 9:05 am

Re: FreePIE Crashes When Using serialPort.ReadLine()

Post by Leshchuk »

That is probably due to lack of serialPort.Close() call before script termination. I'm currently looking for a way to automatically close the port on script stop, but haven't really found anything useful.
Leshchuk
One Eyed Hopeful
Posts: 4
Joined: Mon Jan 14, 2019 9:05 am

Re: FreePIE Crashes When Using serialPort.ReadLine()

Post by Leshchuk »

Apparently there is a way to execute functions before stop, provided by FreePie itself - a "stopping" variable. Should've read documentation more thorougly :D .

You just need to append something like this to your code:

Code: Select all

if stopping:
    serialPort.Close()
Post Reply

Return to “FreePIE”