Python, Read CSV file

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.

Best reply by CodeShepherd

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()

 

 

IDE textual editor script launch setting

View original
2021-09-16_12h25_23.png
40.25KB
2021-09-20_16h55_04.png
88.08KB
7 replies