Using Python for manufacturing question

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Using Python for manufacturing question

Postby fly135 » Wed Mar 20, 2019 7:36 pm

I'm tasked to come up with a manufacturing system for our ESP32 based modules. I'm an old school C programmer and new to Python programming, but figured that Python would be ideal for scripting a build system since the tools are based on Python. My initial manufacturing script is going to start off with erasing the flash and creating an NVS partition file to write to flash along with the factory partition. I've got the NVS defined in a CSV file and now trying to run the NVS partition generation utility, but hit a snag.

I'm trying to run $IDF_PATH/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py, but it fails to find the file. Since the IDF_PATH doesn't get expanded, I used os.environ['IDF_PATH'] to get the string to prepend to the rest of the file path. Unfortunately it doesn't find the file. At first I thought that because I'm running in MSYS that the "E:" at the beginning was the problem, so I tried manually changing it to... "/e/esp-idf-v3.1.1", but that didn't work either.

Also just trying to run esptool.py --help for simplicity gets the same problem.

Neither....

$ python make_sag2.py
python: can't open file 'E:/esp-idf-v3.1.1/components/esptool_py/esptool/esptool.py --help': [Errno 2] No such file or directory

nor...

$ python make_sag2.py
python: can't open file '/e/esp-idf-v3.1.1/components/esptool_py/esptool/esptool.py --help': [Errno 2] No such file or directory

But this works....

$ python /e/esp-idf-v3.1.1/components/esptool_py/esptool/esptool.py --help

My Python looks like this....

esp_tool = "/components/esptool_py/esptool/esptool.py"
nvs_tool = "/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py"
idf_path = "/e/esp-idf-v3.1.1"
subprocess.call(['python', idf_path + esp_tool + ' ' + '--help'])

Any advice for this Python handicapped coder?

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Using Python for manufacturing question

Postby fly135 » Wed Mar 20, 2019 8:17 pm

OK, it looks like I can't pass command line parameters.

i.e. this works...

esp_tool = "/components/esptool_py/esptool/esptool.py"
idf_path = os.environ['IDF_PATH']

subprocess.call(['python', idf_path + esp_tool])

but this doesn't...

subprocess.call(['python', idf_path + esp_tool + ' --help'])

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Using Python for manufacturing question

Postby fly135 » Wed Mar 20, 2019 8:25 pm

Might have figured it out. This works....

subprocess.call(['python', idf_path + esp_tool,'--help'])

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Using Python for manufacturing question

Postby fly135 » Wed Mar 20, 2019 9:10 pm

Getting weird now. If I run it from the command line it works. But if I run it from my python script it thinks the csv file had no field names, and hence no rows.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Using Python for manufacturing question

Postby fly135 » Wed Mar 20, 2019 9:19 pm

OK, it only sees an empty CSV file. I'm creating the file right before calling the nvs generation script.


f = open("nvs.csv", "w")
f.write("key,type,encoding,value\n")
f.write(nspace + "," + "namespace" + ",,\n")
f.write("SERNUM" + "," + "data" + "," + "string" + "," + serial_device + "\n")
subprocess.call(['python', idf_path + nvs_tool,'nvs.csv','nvs.bin'])


The result is that the file has nothing in it. But after the python script exits it does.


SOLUTION: Putting a f.flush before the subprocess.call fixes the problem.

Who is online

Users browsing this forum: Google [Bot], KaosESP32 and 166 guests