Reputation: 15
I have script which reading txt file (only numbers inside) and this script starting with system (before Raspbian Gui start). Everything's work fine, I can send text in byte:
def send_serial_stop(self):
self.serialport.write(b'stop')
When I try to run this action - reading txt file and send data over serial, my script crash. When I start script in Raspbian, everything works fine, and script not crashing. What's wrong with this code? I cannot read any errors because this app is in fullscreen mode. Have some tips? Please help me, because I should finish this project until end of this week :(
def send_serial(self):
file = open('testprog.txt').read()
self.serialport.write(file.encode())
EDIT When I use button with connected code (example above), script is terminated, and GUI application is closing. Application is based on PyQt5 framework and GUI also. Tere are around 150 lines of code in total. Txt file has 24 characters (only numbers) If I trying to run this script in Pycharm, everything works fine, when I start from terminal, situation is the same as during startup.
Upvotes: 1
Views: 220
Reputation: 517
Probably problem is that you use relative path when opening text file.
Change it to absolute path:
file = open('/absolute/path/to/your/file/testprog.txt').read()
Upvotes: 1