FileTransfer to Device

Thomas233
2016-08-26
2016-09-02
  • Thomas233 - 2016-08-26

    Hello,

    i want to write a script that can transfer a file (in my case a symbolconfiguration xml) to the storage of the connected device.
    FTP is not a possibility because my device is only accessible via the Gateway.

    I can't find no possibility in the Script Engine API.
    But i see two interesting entries in system.commands:
    guid="ede62c94-9e06-4d0e-b713-01c9c66351eb" name="Datei von Steuerung laden"
    guid="b099ed07-d6d3-4e2b-aed2-bf15b59c2f35" name="Datei auf Steuerung schreiben"
    (sorry for german names)

    I tried to execute them and found out that they both take two str attributes. My guesses unfortunately didnt work (eg. src, dest filenames).
    Maybe someone know what exactly attributes are required.
    Or is there another way to do a file transfer?

    Best Regards
    Thomas

     
  • mkeller - 2016-08-30

    Hi Thomas233.

    Thomas233 hat geschrieben:
    Hello,
    i want to write a script that can transfer a file (in my case a symbolconfiguration xml) to the storage of the connected device.
    FTP is not a possibility because my device is only accessible via the Gateway.
    I can't find no possibility in the Script Engine API.

    With CODESYS V3.5 SP9 we added the API to the online device object of the ScriptEngine. See IScriptOnlineDevice4 in the ScriptEngine API documentation.

    The following example code was used with our WinV3 PLC so the file paths uses the MS Windows syntax. If the PLC uses any other operating system you have to use the corresponding syntax.

    onlineDev = online.create_online_device()
    myDir = "TF_Test"
    myFile = "/temp.txt"
    myDir2 = "TF_Test2"
    myFile2 = "/temp2.txt"
    print("dir *")
    infos = onlineDev.get_file_list_of_directory("")
    for info in infos:
    Β  Β if info.is_directory:
    Β  Β Β  Β print("D " + info.name)
    Β  Β elif info.is_file:
    Β  Β Β  Β print("F {} ctime:{} atime:{} mtime:{}, size:{}".format(info.name, info.creation_time, info.last_access_time, info.last_modification_time, info.size))
    print("create dir")
    onlineDev.create_directory(myDir)
    print("download file")
    onlineDev.download_file(r"e:\test\temp.txt", myDir + myFile, True)
    print("rename file")
    onlineDev.rename_file(myDir + myFile, myDir + myFile2)
    print("rename directory")
    onlineDev.rename_directory(myDir, myDir2)
    print("upload file")
    onlineDev.upload_file(myDir2 + myFile2, r"e:\test\temp2.txt", True)
    print("delete file")
    onlineDev.delete_file(myDir2 + myFile2)
    print("delete dir")
    onlineDev.delete_directory(myDir2)
    

    BR
    Martin

     
  • Thomas233 - 2016-09-02

    Thank You Martin, know i also found it in the API of SP9. That is what i was looking for.
    Unfortunately i can't use this, because the branded codesys from Lenze have not updated yet to SP9.

     

Log in to post a comment.