I have the following lines of code:
#include <Python.h>
#include <stdio.h>
int main(int argc, char *argv[]){
FILE * file;
Py_Initialize();
file = fopen("LIFT_Head_move_to_Max.py","r");
PyRun_SimpleFile(file,"LIFT_Head_move_to_Max.py");
Py_Finalize();
return 0;
}
When I run the application, the following is the output.
File "LIFT_Head_move_to_Max.py", line 1
▒v▒v@▒p
^
SyntaxError: invalid syntax
What seems to be the problem here? I have tried editing in Notepad++ and changed the Encoding but the same thing happens.
We have the same issue with this post.
Thanks!
UPDATE
Contents of the .py file:
#LIFT_Head_move_to_Max
import serial
import struct
ser = serial.Serial(
port='/dev/ttyS0',
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
print(ser.isOpen())
data="\x5A\x10\x10\x02\x40\x00"
ser.write(data)
ser.close()
<!-- language: lang-none -->on a line on its own with a blank line above and below it before the output. And the image doesn't show the text in the.pyfile.LIFT_Head_move_to_Max.pybefore we can begin to diagnose this.LIFT_Head_move_to_Max.pyfiles in different directories? If you open the file in a hex-editor, is it correct?.pyfile is not encoded unusually? One possible source of trouble could be RTF (rich text format) instead of plain text. Another might be UTF-16 instead of UTF-8 or 8859-15 or CP1252. One way to verify this is to do a hex dump of the first few bytes of the file (32 — 64 at most). Since you're using Notepad++, I suspect you may be on a Windows machine, in which case I'm not sure what the best hex dump tool is. On a Unix-like machine, I'd suggestod -corxxdor something similar (xxd -u -l 64 -g 1 LIFT_Head_move_to_Max.py, for example).