# Strange Behaviour When Saving Cubes (Spectral)

**URL:** <https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293>\
**Category:** Programming Questions\
**Tags:** csharp\
**Created:** [December 9, 2020, 12:24pm UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293 "2020-12-09T12:24:39Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![MathieuVDC](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@MathieuVDC](https://forum.commonvisionblox.com/u/MathieuVDC)\
**Post date:** [December 9, 2020, 12:24pm UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/1 "2020-12-09T12:24:39Z")

</div>

Hello,

I’m encountering strange behaviour when trying to save cubes from the spectral package (in .NET)

I have two cameras that get data from two different framegrabbers. They both are defined by the same class.

To start capturing I use the following:

```
_stream.RingBuffer.ChangeCount(ApproxNumLines, DeviceUpdateMode.NewDeviceImage);
_stream.RingBuffer.LockMode = RingBufferLockMode.On;
 new Thread(() => CaptureThread()).Start();

The capturing thread:

_stream.Start();
         StreamImage imgstream;
         while (_isCapturing)
         {
              WaitStatus res;
              imgstream = _stream.WaitFor(new 
                        Stemmer.Cvb.Utilities.UsTimeSpan(1000000), out res);
              if (res == WaitStatus.Timeout)
              {
                     HandleError($"Camera Timeout");
                     return;
              }
              _data.Add(imgstream);
       }
_stream.Stop();

```

Where \_data is a list:  
` private List<StreamImage> _data;`

The cube is created after capturing was stopped:

```
_cube = Stemmer.Cvb.Spectral.Cube.FromImages(_data, Stemmer.Cvb.Spectral.CubeEncoding.BandInterleavedByLine);
Stemmer.Cvb.Spectral.MetaData metaData = _cube.MetaData;
metaData.Wavelengths = _settings.wavelength;

```

And finally saved:  
`_cube.Save(filepath + '\\' + filename + ".hdr", filepath + '\\' + filename + ".bin");`

after saving, the data is disposed:  
`_data.Clear(); _cube.Dispose(); _stream.RingBuffer.Dispose();`

This works without problem if only a single camera is used, and thus only one instance of the class exists (this has been tested for both cameras). When using two cameras the cube from the first one will be saved succesfully but the `_cube.Save()` call of the second class instance will throw a `"Error Writing Cube"` Exception.

I am using cvb version 13.02.004 but use the CVSpectral dll mentioned in this post: ["Error getting DataType" when creating StackedCube from Image array](https://forum.commonvisionblox.com/t/error-getting-datatype-when-creating-stackedcube-from-image-array/922) (as I was having the same issues)

As both cameras are defined by a different instance of the class and thus share no resources, this looks like weird behaviour to me. Is there any cause or explanation of this behaviour? Is there any way to have more information about the exception, maybe more info is logged somewhere?

Thanks!

---

<div class="post-metadata">

**Author:** ![usernv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/usernv/32/637_2.png) [@usernv](https://forum.commonvisionblox.com/u/usernv)\
**Post date:** [December 10, 2020, 7:54am UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/2 "2020-12-10T07:54:43Z")

</div>

Hi @MathieuVDC,

Did you actually run into the out-of-range exception/“Error getting DataType” and had to replace the DLL or did you update it on reading the post beforehand?

You can see more logging in the LogGUI which comes with your CVB installation. Please configure the logging first (View-\>Configure) by adding the modules to log (Spectral, maybe CVB, DriverDLO). Also set the module logging to “debug”, save configuration, start logging and (re-)start your application. If you can get more information to post here that would be great.

Else I would suggest to set the default logging to debug and send the saved json log to our support [de.support@stemmer-imaging.com](mailto:de.support@stemmer-imaging.com) referencing this thread.

---

<div class="post-metadata">

**Author:** ![MathieuVDC](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@MathieuVDC](https://forum.commonvisionblox.com/u/MathieuVDC)\
**Post date:** [December 10, 2020, 9:14am UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/3 "2020-12-10T09:14:55Z")

</div>

Hi @usernv,

I got the “Error getting Datatype” which is why I replaced the DLL.

I’ve made the log file:

[silogsvc.zip](https://forum.commonvisionblox.com/uploads/short-url/dsAqOrMC5rwK5KVAapjDvHHshoy.zip) (642.7 KB)

There seems to be no error messages in the log, even though my application throws “Errror Writing Cube” exception?

The first cube is created at 09:59:53.443571 and saved at 09:59:53.45539 (succesfully)

The second cube is created at 09:59:55.711536 and saved at 09:59:55.715526 (unsuccesfully)

---

<div class="post-metadata">

**Author:** ![MathieuVDC](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@MathieuVDC](https://forum.commonvisionblox.com/u/MathieuVDC)\
**Post date:** [December 10, 2020, 11:50am UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/4 "2020-12-10T11:50:22Z")

</div>

@usernv,

Any further info on this?

---

<div class="post-metadata">

**Author:** ![usernv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/usernv/32/637_2.png) [@usernv](https://forum.commonvisionblox.com/u/usernv)\
**Post date:** [December 10, 2020, 11:53am UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/5 "2020-12-10T11:53:32Z")

</div>

Yes, it is a bug/a problem with licensing. When the second camera is opened, it has no license and thus cannot save the cube. I need to get some feedback and will send you the updated driver later today.

---

<div class="post-metadata">

**Author:** ![MathieuVDC](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@MathieuVDC](https://forum.commonvisionblox.com/u/MathieuVDC)\
**Post date:** [December 10, 2020, 11:55am UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/6 "2020-12-10T11:55:37Z")

</div>

Okay. Thanks for the help!

---

<div class="post-metadata">

**Author:** ![usernv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/usernv/32/637_2.png) [@usernv](https://forum.commonvisionblox.com/u/usernv)\
**Post date:** [December 10, 2020, 12:10pm UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/7 "2020-12-10T12:10:03Z")

</div>

Can you please check if you have a license for the Spectral tool? It is a independent license from the camera suite. A full trial license would also suffice.

---

<div class="post-metadata">

**Author:** ![MathieuVDC](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@MathieuVDC](https://forum.commonvisionblox.com/u/MathieuVDC)\
**Post date:** [December 10, 2020, 12:24pm UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/8 "2020-12-10T12:24:12Z")

</div>

How can I check this? I’m currently licensed using a USB dongle. On the cvb License Manager I can see this:  
 ![Knipsel](https://canada1.discourse-cdn.com/flex027/uploads/commonvisionblox/original/1X/77c73cb7ee48e9e06d92f269869c7be70acb720a.png)

---

<div class="post-metadata">

**Author:** ![usernv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/usernv/32/637_2.png) [@usernv](https://forum.commonvisionblox.com/u/usernv)\
**Post date:** [December 10, 2020, 12:32pm UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/9 "2020-12-10T12:32:28Z")

</div>

I am sorry to tell you this, but you are missing the needed license for CVSpectral. It would be separately listed in the license manager. CVSpectral is neither part of the image manager nor the foundation. You can check for available licenses here:

> **[CVB Spectral](https://www.stemmer-imaging.com/en/products/series/cvb-spectral/)**
>
> Software to create and for handling of hyperspectral cubes: CVB Spectral is a tool for the acquisition and basic processing of hyperspectral data. CVB Spectral allows users to acquire the spatial and wavelength information direct from a hyperspectral...

---

<div class="post-metadata">

**Author:** ![MathieuVDC](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@MathieuVDC](https://forum.commonvisionblox.com/u/MathieuVDC)\
**Post date:** [December 10, 2020, 12:38pm UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/10 "2020-12-10T12:38:29Z")

</div>

Weird. The Stemmer sales people were aware of our need for the Spectral software and yet offered us only the Foundation. We will look into ordering the Spectral License. However this does not explain why I am able to save the data once?

---

<div class="post-metadata">

**Author:** ![usernv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/usernv/32/637_2.png) [@usernv](https://forum.commonvisionblox.com/u/usernv)\
**Post date:** [December 10, 2020, 12:59pm UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/11 "2020-12-10T12:59:29Z")

</div>

We have some slack in the licensing process. For instance if you use a license dongle on a running production PC and someone removes the dongle by accident, the system continues running for a while before embedding the watermark. In you case the call to the license probably comes fast enough so that no license could have been detected yet. In this case we allow the call so you won’t have any trouble for now. The second cube save then correctly detects the missing license and returns an error.

---

<div class="post-metadata">

**Author:** ![MathieuVDC](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@MathieuVDC](https://forum.commonvisionblox.com/u/MathieuVDC)\
**Post date:** [December 10, 2020, 1:27pm UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/12 "2020-12-10T13:27:45Z")

</div>

If I look on the Magic Numbers page there seems to be a Spectral license

 ![afbeelding](https://canada1.discourse-cdn.com/flex027/uploads/commonvisionblox/original/1X/a9e76645abd18c38d737ad1e49edb99964ebe8cd.png)

Or is a Magic Number not a license?

---

<div class="post-metadata">

**Author:** ![usernv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/usernv/32/637_2.png) [@usernv](https://forum.commonvisionblox.com/u/usernv)\
**Post date:** [December 10, 2020, 2:03pm UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/13 "2020-12-10T14:03:43Z")

</div>

The serial 999 is the standard value for developer dongles which unlock all tools. You should have gotten a magic number which fits your dongle number (not 999). You would enter the tool name and magic number and then the dongle unlocks the tool.  
The other option is a dongle which comes with the magic number preset. This would then add the unlocked tool to the bottom after all 999 tools with your dongle number.

---

<div class="post-metadata">

**Author:** ![MathieuVDC](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@MathieuVDC](https://forum.commonvisionblox.com/u/MathieuVDC)\
**Post date:** [December 10, 2020, 2:29pm UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/14 "2020-12-10T14:29:25Z")

</div>

My dongle is plugged into the PC. The spectral tool stays at 999. But so does everything else, what exactly does that mean? That nothing is licensed? Even so, everything right now is being licensed by a trial license because of the 999? So the failure of my code is not a licensing error?

---

<div class="post-metadata">

**Author:** ![usernv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/usernv/32/637_2.png) [@usernv](https://forum.commonvisionblox.com/u/usernv)\
**Post date:** [December 10, 2020, 2:53pm UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/15 "2020-12-10T14:53:22Z")

</div>

When you open the camera or cvmock.vin with the CVB Viewer you should see a watermark embedded. All 999 Serials are always displayed. Do you have a trial license activated simultaneously to the dongle? If so it is possible that the trial overrides the dongle. Maybe remove the trial license and try with the dongle again.  
But if you do not have purchased the Spectral tool, you will not have the license for it.  
You can also check for a faulty dongle with the watermark embedded. Adding the dongle should remove the watermark after a few seconds.

---

<div class="post-metadata">

**Author:** ![MathieuVDC](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@MathieuVDC](https://forum.commonvisionblox.com/u/MathieuVDC)\
**Post date:** [December 10, 2020, 3:20pm UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/16 "2020-12-10T15:20:00Z")

</div>

When the dongle is disconnected I see the watermark, it then disappears after inserting the dongle. So it seems a trial version is blocking me from seeing which Tools are licensed. How can I remove the trial license?

---

<div class="post-metadata">

**Author:** ![usernv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/usernv/32/637_2.png) [@usernv](https://forum.commonvisionblox.com/u/usernv)\
**Post date:** [December 11, 2020, 7:08am UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/17 "2020-12-11T07:08:36Z")

</div>

No, this is normal behaviour. If you would remove the dongle but still get no watermark the trial license would be active. I checked with your orders and could not find one for the CVSpectral license. I also informed sales so they can get in contact with you.  
Sorry that this was somehow overlooked and I hope we can find a suitable solution soon.

---

<div class="post-metadata">

**Author:** ![MathieuVDC](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@MathieuVDC](https://forum.commonvisionblox.com/u/MathieuVDC)\
**Post date:** [December 14, 2020, 11:00am UTC](https://forum.commonvisionblox.com/t/strange-behaviour-when-saving-cubes-spectral/1293/18 "2020-12-14T11:00:42Z")

</div>

Hello @usernv,

I’ve got a trial license for now and the Spectral License has been ordered. Everything seems to be working now. Thank you for your help.
