Question about a print()

Hi! I was getting 0.00% on the print that I highlighted and I was wondering why was that happening? For context, this is the call script of the RPC module.

def get_frame_buffer_call_back(pixformat_str, framesize_str, cutthrough, silent):

    if not silent:
        print("Getting Remote Frame...")

    result = interface.call("jpeg_image_snapshot", "%s,%s" %
                            (pixformat_str, framesize_str))
    if result is not None:

        size = struct.unpack("<I", result)[0]

        img = bytearray(size)

        print(1)

        if cutthrough:

            # Fast cutthrough data transfer with no error checking.

            # Before starting the cut through data transfer we need to sync both the master and the

            # slave device. On return both devices are in sync.

            result = interface.call("jpeg_image_read")

            if result is not None:

                # GET BYTES NEEDS TO EXECUTE NEXT IMMEDIATELY WITH LITTLE DELAY NEXT.

                # Read all the image data in one very large transfer.

                interface.get_bytes(img, 5000)  # timeout

        else:

            # Slower data transfer with error checking.

            # Transfer 32 KB chunks.

            chunk_size = (1 << 15)

            if not silent:
                print("Reading %d bytes..." % size)

            for i in range(0, size, chunk_size):

                ok = False

                for j in range(3):  # Try up to 3 times.

                    result = interface.call(
                        "jpeg_image_read", struct.pack("<II", i, chunk_size))

                    if result is not None:

                        img[i:i+chunk_size] = result  # Write the image data.

                        if not silent:

print("%.2f%%" % ((i * 100) / size))

ok = True

                        break

                    if not silent:
                        print("Retrying... %d/2" % (j + 1))

                if not ok:

                    if not silent:
                        print("Error!")
                    return None
        return img
    else:
        if not silent:
            print("Failed to get Remote Frame!")

    return None

Can you paste the log?

Sure!

Available Ports:

/dev/ttyACM0 : OpenMV Virtual Comm Port in FS Mode [USB VID:PID=1209:ABD1 SER=3839344B3137 LOCATION=1-1.1.2:1.0]
/dev/ttyAMA0 : ttyAMA0 [3f201000.serial]

Please enter a port name: /dev/ttyACM0

Getting Remote Frame…
Reading 21883 bytes…
0.00%
Getting Remote Frame…
Reading 24796 bytes…
0.00%
Getting Remote Frame…
Reading 27326 bytes…
0.00%
Getting Remote Frame…
Reading 28057 bytes…
0.00%
Getting Remote Frame…
Reading 29174 bytes…
0.00%
[INFO] stitching images…
[INFO] image stitching failed (1)

I tried viewing the image but it’s just pitch black

It’s failing to grab the frame. What’s the OpenMV Cam running? Is it running the script that is designed to pair with that script?

Yes, it is running the callback script.

So, this script is on the PC: openmv/rpc_image_transfer_jpg_as_the_controller_device.py at master · openmv/openmv · GitHub

And this is on the camera: openmv/image_transfer_jpg_as_the_remote_device_for_your_computer.py at master · openmv/openmv · GitHub

What operating system are you on? I can confirm it works fine on windows. The timeouts in the code are likely too short. Another forum user had an issue with this.

I’m running it on Raspbian on my Raspberry Pi 3B+. I also tried it on Windows and it worked fine. Seems weird to me.

Ah…

Mmm, I’ll have to debug that using a USB packet analyzer. Most likely the timing is off causing the library to not work. It’s really hard to debug via USB.

If you can switch to the UART master? That should work.

The issue is probably related to how pyserial buffers data on the pi. I’ll have to debug this manually and possibly make the library act different on the Pi.

To be clear, try editing this class:

The get_bytes method. You can add a print there. If you see that method timing out then just making the timeouts bigger should fix the issue.

Make the 0.01 on this line larger: openmv/rpc.py at master · openmv/openmv · GitHub

Got it! How big tho?

I tried making it bigger but it still did not work. I’ll try changing to UART, but wasn’t it unavailable yet for the Pi?

The timeout is per 1KB of data. So, making it 0.02 is 20 ms to move 1KB of data.

Mmm…

Okay, copy this whole script to the SD card, but, then change the timeout lines here: openmv/rpc.py at master · openmv/openmv · GitHub

timeout=timeout_ms → timeout=timeout_ms*10

Verify the library is saved and then restart the camera. This will make the camera VCP timeout 10X longer. This will negatively affect performance for short data transfers but not affect longer ones.

Sadly, I got the same result :frowning:

Please make a bug on github. I’ll debug this. Sorry this doesn’t work.

I will! No problem!

Is UART available for the Pi?

I just realized; this happened when I started running it on python 3.

Is the rpc library supposed to be ran on Python2?

It should work on both. The only variable is the PySerial library. That is what actually does the USB stuff. My python code is rather generic.

Understood!

This is interesting… I ran the test scripts for the RPC in python2 and it ran perfectly. It seems there is a problem with running it on python3. Maybe what you mentioned about the serial connection.

I’ll install it with pip3