Meant to be Seen
https://www.mtbs3d.com/phpbb/

FreePIE Crashes When Using serialPort.ReadLine()
https://www.mtbs3d.com/phpbb/viewtopic.php?f=139&t=22813
Page 1 of 1

Author:  kbigdelysh [ Wed May 16, 2018 5:00 pm ]
Post subject:  FreePIE Crashes When Using serialPort.ReadLine()

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:

Quote:
Had to forcibly shut down script - try removing infinite loops from the script
at ...



Code:
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:
line = serialPort.ReadLine()


but I'm not sure how to resolve it.

Author:  Leshchuk [ Thu Feb 07, 2019 1:29 pm ]
Post subject:  Re: FreePIE Crashes When Using serialPort.ReadLine()

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.

Author:  Leshchuk [ Thu Feb 07, 2019 2:42 pm ]
Post subject:  Re: FreePIE Crashes When Using serialPort.ReadLine()

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:
if stopping:
    serialPort.Close()

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/