# Change RingBufferCount

**URL:** <https://forum.commonvisionblox.com/t/change-ringbuffercount/660>\
**Category:** Python API\
**Tags:** ringbuffer\
**Created:** [January 23, 2019, 2:38pm UTC](https://forum.commonvisionblox.com/t/change-ringbuffercount/660 "2019-01-23T14:38:33Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mucki](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Mucki](https://forum.commonvisionblox.com/u/Mucki)\
**Post date:** [January 23, 2019, 2:38pm UTC](https://forum.commonvisionblox.com/t/change-ringbuffercount/660/1 "2019-01-23T14:38:33Z")

</div>

Hi,  
i connected a device and before starting the stream i want to set the RingBufferCount.

```auto
device.stream.ring_buffer.change_count(10,0)

```

and i get this error : `failed to extract type - resource might be gone`  
This also happens when i start an Acquisition and want to get the bufferindex:

```auto
image, status = self.device.stream.wait()
print(image.buffer_index)

```

Greetings

---

<div class="post-metadata">

**Author:** ![Andreas](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/andreas/32/75_2.png) [@Andreas](https://forum.commonvisionblox.com/u/Andreas)\
**Post date:** [January 23, 2019, 8:50pm UTC](https://forum.commonvisionblox.com/t/change-ringbuffercount/660/2 "2019-01-23T20:50:01Z")

</div>

Hi,

can you provide some more code to reproduce the error?

Please note that this usually happen when accessing already closed device resources.  
E.g:

```python
import cvb

with cvb.DeviceFactory.open(os.path.join(cvb.install_path(), "Tutorial", "ClassicSwitch.emu")) as dev:
  # dev and all dependent resources like stream and ring buffer will only be available inside the with statement
  device = dev 
  # no error
  device.stream.start()
  device.stream.stop()

# this will produce the above error
device.stream.start()

```

---

<div class="post-metadata">

**Author:** ![Mucki](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Mucki](https://forum.commonvisionblox.com/u/Mucki)\
**Post date:** [January 24, 2019, 2:30pm UTC](https://forum.commonvisionblox.com/t/change-ringbuffercount/660/3 "2019-01-24T14:30:08Z")

</div>

Im using this right now:

```auto
class Cameracontrol():
    """
    The :class: Cameracontrol contains many functions to set up a camera in the genicam-standard via CVBpy.
    The functions can be divided into the following classes:
        1. setters for all used and useful nodes
        2. "useful" functions like starting/stopping Aquisition or acquiring images
    Before using this class u need to set the Ip-adress of your camera manually
    """

    def __init__ (self):
        self.device = None

    def _discover(self):
        """
        Thos Function discovers all devices which are connected to the computer and returns
        a list with all of them in it.
        :return: a list with all devices. You may print() it to see details about the camera like ip-adress or model
        """
        return cvb.DeviceFactory.discover_from_root(flags=cvb.DiscoverFlags.FindAll, time_span=300)

    def connect(self, ip: str):
        """
        This function discovers all devices and connects to the the device with the given ip as a String
        :param ip: String of the ip-adress
        :return: The connected device
        """
        disco = self._discover()
        for i in disco:
            if ip in i.access_token:
                return cvb.DeviceFactory.open(i.access_token)

def startacquisition(self):
    # starts the Aquistion via grabber
    self.device.stream.start()

def acquireimage(self):
    """
    Starts the stream, sends a softwaretrigger to get an image and save it. After that the acqusition stops
    :return:
    """
    nodemap = self.device.node_maps["Device"]
    triggernode = nodemap["TriggerSoftware"]
    self.startacquisition()
    for i in range(10):
        triggernode.execute()
        sleep(1)
        image, status = self.device.stream.wait()
        print(image)
        if (image.buffer_index==2):
            print ("hallo")
    self.stopacquisition()

```

With this class im running in my main:#

```auto
Camera = Cameracontrol()
Camera.device = Camera.connect('192.168.5.2')
Camera.acquireimage()

```

---

<div class="post-metadata">

**Author:** ![Mucki](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Mucki](https://forum.commonvisionblox.com/u/Mucki)\
**Post date:** [January 24, 2019, 2:35pm UTC](https://forum.commonvisionblox.com/t/change-ringbuffercount/660/4 "2019-01-24T14:35:11Z")

</div>

````auto
stream.start()

for i in range (0,10):
    triggersoftware_node.execute()
    image, status = stream.wait()
    print(image.buffer_index)
    if image.buffer_index == 1:
        image.save('image%d.png' %(i))
        print(image.buffer_index)```

this after connecting to the device works though in a separate program
````

---

<div class="post-metadata">

**Author:** ![Mucki](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Mucki](https://forum.commonvisionblox.com/u/Mucki)\
**Post date:** [January 30, 2019, 1:45pm UTC](https://forum.commonvisionblox.com/t/change-ringbuffercount/660/5 "2019-01-30T13:45:21Z")

</div>

I solved the problem myself. I needed to create varibales with a = device.stream to save the cahnges made.  
Is there another way to accomplish this?

---

<div class="post-metadata">

**Author:** ![Andreas](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/andreas/32/75_2.png) [@Andreas](https://forum.commonvisionblox.com/u/Andreas)\
**Post date:** [January 31, 2019, 7:35pm UTC](https://forum.commonvisionblox.com/t/change-ringbuffercount/660/6 "2019-01-31T19:35:00Z")

</div>

Thanks for the feedback.  
Can you please post some details about the difference between your working soulution and the error message above.  
I’m still quite puzzled about what you actually changed?

Thanks.

---

<div class="post-metadata">

**Author:** ![GTG](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@GTG](https://forum.commonvisionblox.com/u/GTG)\
**Post date:** [February 12, 2019, 3:48pm UTC](https://forum.commonvisionblox.com/t/change-ringbuffercount/660/7 "2019-02-12T15:48:36Z")

</div>

Hi there  
I have a similar problem with a 3d camera:  
3D Vendor: LMI  
3D Model: Gocator 2420  
3D Version: 5.2.18.11

I am using python and Pycharm and the latest CVb software. After setting the number of buffers to 3, or 10 or 100 or 1000 after the last buffer image (if buffer size = 3, at image 4) i get (i have removed a try catch to find the error):

```auto
Traceback (most recent call last):
  File "C:/Users/User/PycharmProjects/base-valve/base_valve_GUI.py", line 816, in run
    np_array3D = cvb.as_array(image3D)
  File "C:\Users\User\AppData\Local\conda\conda\envs\base-valve\lib\site-packages\cvb\ __init__.py", line 281, in as_array
    if not image.plane_data_types_identical:
RuntimeError: failed to extract type - resource might be gone

```

I am using two cameras (the other one a Jai GO-5000M-PGE, no problem with it at any buffer size).  
I have optimized the network card setting as per instructions to maximize performance on both cards. The 3D camera is using the GenTl protocol.

the relevant code snippet is:

```auto
image3D, status3D = self.stream3D.wait()     
 np_array3D = cvb.as_array(image3D, copy=False) 
np_array_3D = np_array3D[:, :, 0] # height map

```

The status3D is always good : 0

Thank you for your help,  
GTG

---

<div class="post-metadata">

**Author:** ![Andreas](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/andreas/32/75_2.png) [@Andreas](https://forum.commonvisionblox.com/u/Andreas)\
**Post date:** [February 13, 2019, 2:38pm UTC](https://forum.commonvisionblox.com/t/change-ringbuffercount/660/8 "2019-02-13T14:38:27Z")

</div>

Hi @GTG and @Mucki

I looked into it and found that there is bug in CVBpy. It is fixed in the current development branch.  
If you contact our support I can provide you with a patch.

Please keep in mind that the patch is development version that might contain other/new bugs.

Here is some code that should fail with your version but run with that patch.

```python
import os
import cvb

dev = cvb.DeviceFactory.open(os.path.join(cvb.install_path(), "drivers", "GenICam.vin"))

#asuming that the vin driver configures 3 buffers by default.
dev.stream.ring_buffer.change_count(5, cvb.DeviceUpdateMode.UpdateDeviceImage)

with dev:
    dev.stream.start()

    for i in range(10):
        print("Image: " + str(i))
        image, status = dev.stream.wait(10000)
        if status == cvb.WaitStatus.Ok:
            print("Buffer: " + str(image.buffer_index))

    dev.stream.abort()

print("test over")

```

---

<div class="post-metadata">

**Author:** ![GTG](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@GTG](https://forum.commonvisionblox.com/u/GTG)\
**Post date:** [February 14, 2019, 8:10am UTC](https://forum.commonvisionblox.com/t/change-ringbuffercount/660/9 "2019-02-14T08:10:52Z")

</div>

Hi Andreas

I have contacted support, no reply. Can I get a link for the patch download?  
Thank you.

GTG

---

<div class="post-metadata">

**Author:** ![piotrM](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@piotrM](https://forum.commonvisionblox.com/u/piotrM)\
**Post date:** [February 21, 2020, 8:00am UTC](https://forum.commonvisionblox.com/t/change-ringbuffercount/660/10 "2020-02-21T08:00:47Z")

</div>

@Andreas  
I am too working with buffers and I think I can’t achieve the results due to being unable to set the proper buffer count. Could you share the development version of the python library?

---

<div class="post-metadata">

**Author:** ![Andreas](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/andreas/32/75_2.png) [@Andreas](https://forum.commonvisionblox.com/u/Andreas)\
**Post date:** [February 21, 2020, 7:55pm UTC](https://forum.commonvisionblox.com/t/change-ringbuffercount/660/11 "2020-02-21T19:55:06Z")

</div>

Hi @piotrM

the above issue has been fixed. What is your CVB and CVBpy version?  
Do you have issues with the above spinet? You might have run int something different.

---

<div class="post-metadata">

**Author:** ![piotrM](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@piotrM](https://forum.commonvisionblox.com/u/piotrM)\
**Post date:** [February 24, 2020, 8:22am UTC](https://forum.commonvisionblox.com/t/change-ringbuffercount/660/12 "2020-02-24T08:22:58Z")

</div>

Oh sorry! I haven’t realized it was 2019. There are still some errors in py doc (I dont think RIngBufferImage has “unlock()”) so I thought its still under development. Or maybe I just don’t quite get how to access the RingBuffer. I have started a separate thread for the issue I am encountering. Thanks for the response!
