f.write

Discussion related to "under the hood" OpenMV topics.
pcls1026
Posts: 72
Joined: Tue Aug 22, 2017 1:33 am

f.write

Postby pcls1026 » Sat Feb 24, 2018 3:23 pm

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.
Attachments
copygrayvgatofile.py
(1.21 KiB) Downloaded 130 times
User avatar
kwagyeman
Posts: 3264
Joined: Sun May 24, 2015 2:10 pm

Re: f.write

Postby kwagyeman » Sat Feb 24, 2018 3:35 pm

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

Code: Select all

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

Code: Select all

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.
Nyamekye,
User avatar
iabdalkader
Posts: 937
Joined: Sun May 24, 2015 3:53 pm

Re: f.write

Postby iabdalkader » Sat Feb 24, 2018 4:20 pm

I just tested your script, and it's working on flash and SD card I see the file with pixel values.
pcls1026
Posts: 72
Joined: Tue Aug 22, 2017 1:33 am

Re: f.write

Postby pcls1026 » Sat Feb 24, 2018 6:12 pm

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
User avatar
kwagyeman
Posts: 3264
Joined: Sun May 24, 2015 2:10 pm

Re: f.write

Postby kwagyeman » Sat Feb 24, 2018 6:36 pm

Was this using an SD card for the flash FS?
Nyamekye,
pcls1026
Posts: 72
Joined: Tue Aug 22, 2017 1:33 am

Re: f.write

Postby pcls1026 » Mon Feb 26, 2018 7:29 pm

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?
pcls1026
Posts: 72
Joined: Tue Aug 22, 2017 1:33 am

Re: f.write

Postby pcls1026 » Mon Feb 26, 2018 8:32 pm

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
User avatar
kwagyeman
Posts: 3264
Joined: Sun May 24, 2015 2:10 pm

Re: f.write

Postby kwagyeman » Mon Feb 26, 2018 10:17 pm

Where did you buy the camera from? Sounds bad. That issue is the firmware halting because of a hardware error.
Nyamekye,
pcls1026
Posts: 72
Joined: Tue Aug 22, 2017 1:33 am

Re: f.write

Postby pcls1026 » Tue Feb 27, 2018 2:08 pm

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
User avatar
kwagyeman
Posts: 3264
Joined: Sun May 24, 2015 2:10 pm

Re: f.write

Postby kwagyeman » Tue Feb 27, 2018 2:59 pm

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.
Nyamekye,
pcls1026
Posts: 72
Joined: Tue Aug 22, 2017 1:33 am

Re: f.write

Postby pcls1026 » Tue Feb 27, 2018 3:22 pm

How do I post the script for debugging? And, how can they debug it without my camera?
Jim
pcls1026
Posts: 72
Joined: Tue Aug 22, 2017 1:33 am

Re: f.write

Postby pcls1026 » Tue Feb 27, 2018 3:23 pm

How do I post the script for debugging? And, how can they debug it without my camera?
Jim
User avatar
kwagyeman
Posts: 3264
Joined: Sun May 24, 2015 2:10 pm

Re: f.write

Postby kwagyeman » Tue Feb 27, 2018 4:11 pm

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

Code: Select all

 tags.
Nyamekye,
pcls1026
Posts: 72
Joined: Tue Aug 22, 2017 1:33 am

Re: f.write

Postby pcls1026 » Tue Feb 27, 2018 6:15 pm

Me again,
Whats (tag.) how do i use it?
Sorry for being such an ignoramus.
Jim
User avatar
kwagyeman
Posts: 3264
Joined: Sun May 24, 2015 2:10 pm

Re: f.write

Postby kwagyeman » Tue Feb 27, 2018 6:23 pm

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

Um, just attach the zip file of the code.
Nyamekye,
pcls1026
Posts: 72
Joined: Tue Aug 22, 2017 1:33 am

Re: f.write

Postby pcls1026 » Wed Feb 28, 2018 2:29 pm

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
pcls1026
Posts: 72
Joined: Tue Aug 22, 2017 1:33 am

Re: f.write

Postby pcls1026 » Wed Feb 28, 2018 2:51 pm

blksearch.py zipped file attached
Attachments
blksearch.zip
(1000 Bytes) Downloaded 83 times
pcls1026
Posts: 72
Joined: Tue Aug 22, 2017 1:33 am

Re: f.write

Postby pcls1026 » Thu Mar 01, 2018 10:46 am

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
User avatar
kwagyeman
Posts: 3264
Joined: Sun May 24, 2015 2:10 pm

Re: f.write

Postby kwagyeman » Thu Mar 01, 2018 1:31 pm

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.
Nyamekye,
User avatar
kwagyeman
Posts: 3264
Joined: Sun May 24, 2015 2:10 pm

Re: f.write

Postby kwagyeman » Sun Mar 04, 2018 3:11 pm

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.
Nyamekye,
pcls1026
Posts: 72
Joined: Tue Aug 22, 2017 1:33 am

Re: f.write

Postby pcls1026 » Sat Mar 10, 2018 11:42 am

Thanks,
You guys are operating way above my meager capabilities. Do you get paid to do this or is it a passion?
Thanks Again,
Jim
User avatar
kwagyeman
Posts: 3264
Joined: Sun May 24, 2015 2:10 pm

Re: f.write

Postby kwagyeman » Sat Mar 10, 2018 12:18 pm

Passion right now, hopefully pay later. Once the system gets built up enough and we shrink it we plan to do lots of b2b sales. Right now it's just hobbyist mainly however. There's a hunger for easier to use devices on the market right now though. So, we hope to fill that gap.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests