It is currently Tue Apr 23, 2019 6:47 am



Reply to topic  [ 3 posts ] 
 FreePIE Crashes When Using serialPort.ReadLine() 
Author Message
One Eyed Hopeful

Joined: Mon Apr 30, 2018 5:10 pm
Posts: 1
Reply with quote
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.


Wed May 16, 2018 5:00 pm
Profile
One Eyed Hopeful

Joined: Mon Jan 14, 2019 9:05 am
Posts: 4
Reply with quote
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.


Thu Feb 07, 2019 1:29 pm
Profile
One Eyed Hopeful

Joined: Mon Jan 14, 2019 9:05 am
Posts: 4
Reply with quote
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()


Thu Feb 07, 2019 2:42 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: Google [Bot] and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by STSoftware.