anyone test the read and write flash USB code from Digi?

Hi all,

Does anyone ever test/run the code in the link I try to run the “append data to the file” part. However, it reports “File does not exist”. I am confused on how to run it.



I have not tested the code you are mentioning, but it seems like that it shows the class. But I had tested the following code at the wiki link.

Hi Shahrj,

Since I use Connectport X5 and this device does not have a usb port, I cannot test the USB drive code. I really want to know what is the exact address for the internal flash of Digi Connectport device.

The main FLASH appears as the directory “WEB/python”. Creating a file as “WEB/python/data.csv” puts the file into Main Flash.

This has worked succesfully for me on a ConnectPort X4.

I tried to create a file and upload under the Applications
->Python. Then I tried to open the file by using “fh = open(“WEB/python/tmp.txt”, ‘w’)”. But it still reports no file exist…

Since I worte that Wiki page, I know that the code works.

“fh = open(“WEB/python/tmp.txt”, ‘w’)” would delete an existing file. So if you uploaded tmp.txt via the web interface, then tried to ‘open’ it for writing, it would be truncated. Did you mean you wish to open it for reading?

The “WEB/python” prefix is true on all Digi gateways - X2, X3, X4, X5 and X8. It is case senstive and cannot start with a /, so “/WEB/python” and “WEB/Python” are both wrong.

Have you tried working with files on a PC?

“fh = open(“WEB/python/ddd.txt”, ‘r’)
print (”
I tried this two line code right now. However, still report no file exists. I am sure I upload a ddd.txt file in both the Python and file management… Also I want to know how to run/test the code here:

To test that code, you need to be compenetnt in Python so that you can create your own database object, then add those functions as methods under it. The routines shown are cut from an actual data-point logger for a tank monitoring system. The full module/file is not mine to publish; it is not public domain.

Make sure you are not issuing an os.chdir, as that will screw up the paths (if your X5 firmware is new, older firmware didn’t support chdir()).

You are better off working with the sample on the page, which when adjust to use the internal flash path would be:

fh = open(“WEB/python/tmp.file”, ‘w’)
fh = open(“WEB/python/tmp.file”, ‘r’)
print (

I am really new to python. You mean I need to make this code as a method and then call the method. Why do I need to create a database object?

And I think my problem is I cannot locate the file system when I use directory “WEB/python”. Everytime I try to open a file it will report “File does not exist”.