f.write

Hi,
I wrote and ran a script several months ago that writes data to a file on the SD card. After running the script, I reset the MV Cam using IDE tools. The file then presents on the K-Drive of the PC. I then open the file on Notebook and look at it.

I ran the script today, but the file does not present on the PC K drive.
The SD card appears to be empty.
I updated to the 8a version.

I attached my script.
copygrayvgatofile.py (1.21 KB)

I get the file on my SD card. But, I changed:

f=open('testtest.txt','w')

to

f=open('/testtest.txt','w')

…

That said, I don’t get a file on the drive when not using an SD card.

Please submit a bug with your script to github.

I just tested your script, and it’s working on flash and SD card I see the file with pixel values.

I tried adding the /.
It worked the first time I ran the script. I could read the file on the K drive.
However, it did not work the second time I ran the script.
I reinstalled the CAM firmware and it ran properly again the first time but not the second.
It would appear the firmware is getting corrupted. Is this possible?
Jim

Was this using an SD card for the flash FS?

I had the SD card attached to the camera. I thought the file was automatically opened on the SD card. How do I know if the file is being written to the SD card or the Flash?

Hi,
Now I have another problem. When I plug the camera into the PC USB port, the PC will not accept it. It says the device not recognized. Also, the camera light blinks like crazy.
Jim

Where did you buy the camera from? Sounds bad. That issue is the firmware halting because of a hardware error.

I bought from the openmv website. --openm3 r2 us-mf-002 ov7725-m7 05/20/2017–

When I put the SD card in the camera the PC recognizes the USB port and the CAM7 works as usual.

This morning I got the following results for my file problem.

  1. I started the openmv ide. The previously attached file "copygrayvgatofile.py was in the script window. I connected the camera, ran the script, and lo and behold the file “testtest.txt” showed up on the K drive. I opened the file and the values expected were there. I deleted the file from the k drive.

  2. I changed nothing in the script. I reconnected to the CAM. I ran the script. THE FILE DID NOT SHOW UP ON THE K DRIVE.

  3. I tried 3 more times and the file never showed on the k drive.

4.I closed the IDE, and unplugged the cam from the USB port. I Opened the IDE, plugged in the cam, ran the script. Still no file on k drive.

5.I closed the IDE, unplugged the cam. I plugged in the cam back in, opened the IDE, and ran the script. No file on K.

6.I pulled the SD card, ran the script and I got the following “errorOSError: [Errno 5] EIO” when the script tried to open the file.

7.Restarted the IDE (SD card still Out). The camera started blinking and I could not connect.

Jim

Sounds like a bug in us. We’ll look into how to fix it. Ibrahim is busy doing the H7 port so I’m not sure if he can help. I will try to debug this weekend.

I don’t have a work around for this in the meantime. Question, is there a way to avoid the disk activity? Also, please post your script for debugging. Thanks.

How do I post the script for debugging? And, how can they debug it without my camera?
Jim

How do I post the script for debugging? And, how can they debug it without my camera?
Jim

Hi, you can zip the .py file up and post it or post the code via

 tags.

Me again,
Whats (tag.) how do i use it?
Sorry for being such an ignoramus.
Jim

Um, haha. The system converted my text into code.

Um, just attach the zip file of the code.

You won’t believe this.

Every morning when I start openmv ide and run my script, the file magically appears on the k drive. But the rest of the day it does not. Maybe the problem is in Windows and it gets repaired at night over the internet.

Jim

blksearch.py zipped file attached
blksearch.zip (1000 Bytes)

Once again the file appeared on the K drive this morning after running the script. I deleted the file from the K drive; ran the script; and the file did not appear on the K drive.

What it is Bro.

Jim

Hi, I can’t debug this until the weekend. I really don’t know what is wrong. But, it’s definitely a serious bug that needs to be fixed.

Okay, I found the bug.

It’s really subtle.

So, basically, the issue is that the OpenMV Cam and your PC are both writing to the file system at the same time and not noticing each other changes. When you click the reset button on OpenMV IDE it causes a file system flush on the PC side which deletes whatever files the OpenMV Cam wrong to the disk.

So, I will fix this issue in OpenMV IDE not to flush the filesystem when you hit the reset button but only on file save. That said, this issue can still happen if you edit any files on the camera via another program.

In the mean time, the quickest way to get around this issue is just to unplug your OpenMV Cam from the PC and plug it back in if you want to see the file. This prevents any writes from happening to the disk. Do not use the “Reset OpenMV Cam Button”.

…

Can this be fixed in a better way? Unfortunately no. Windows/Mac/Linux all assume they are the sole masters of USB drives and do not scan for changes after loading a drive block disk (they see USB drives as byte storage devices). So, if the camera makes any changes to the files on the drive the PC ignores this. There’s no way to get the PC to rescan the drive too. A rescan only happens when the camera is plugged in. So, for you to see files on the OpenMV Cam you have to create the files and then disconnect from the PC before it does any more writes.

Note: This behavior affects the internal and SD card flash drives. The file disappears because the root directly gets updated by OpenMV IDE trying to flush pending writes to the disk. This erases the new file you created on the camera by deleting it’s file pointer. That said, this also orphans any FAT sectors the file was using too.