FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
09-20-2021 10:58 PM
Trying to open and read a csv file from Python. Program works fine when run locally. However, when run from controller (execute python file via PLC) looks like the path for the csv file is wrong. Any suggestions? I also tried absolute path and also added activeconfiguration to the relative path. no luck.
Solved! Go to Solution.
09-21-2021 04:34 PM - edited 10-04-2021 08:38 AM
EDIT: For the general path on the control:
Could you please have a look to this topic.
09-28-2021 05:00 PM
@Usalas, Is this from a snap of the IDE?
10-01-2021 04:24 PM
It is from the IDE itself. Both files, py and csv are in the active configuration
10-04-2021 08:39 AM
How does your PLC code look like? Please have a look to this thread to see how to run python script from PLC.
10-04-2021 03:28 PM
The PLC side is fine. I can execute any python file. The issue is when the python file tries to read or write another file. in this case csv file.
10-04-2021 04:51 PM - edited 10-05-2021 08:40 AM
When using the play button you mentioned the script is only run locally in the IDE. So your path is not known by the script instance when run on the ctrlX CORE.
You can also start the script in an interpreter instance by using the debugger (e.g. for testing before using the PLC for starting). See my working example for reading and writing:
FileName1 = "/var/snap/rexroth-solutions/common/solutions/activeConfiguration/tiger/projects/CsvReadWrite/csvdata1.csv"
FileName2 = "/var/snap/rexroth-solutions/common/solutions/activeConfiguration/tiger/projects/CsvReadWrite/csvdata2.csv"
file1 = open(FileName1,"r")
file2 = open(FileName2,"w")
for x in file1:
data = x.split(",")
for y in data:
print(y)
file2.write(y + ",")
file1.close()
file2.close()
10-04-2021 08:58 PM
Thanks.
it was the file path that was wrong.