C# VM116 and K8062D library problems

Hello,
We’re doing a schoolproject with some projectors and the support of the VM116 controller.
we wanted to create our own animation by using C# and the K8062D library.
everything was working fine untill we tried to use a for loop, I’ll explain better:

If we use SetData(channel,data) a single time, then it works great without problems,

if we use a loop or a cycle for, everything stops working correctly, for example:

for (index = 0; index <= 255; index++) { SetData(1,index); Delay(1.0); }
this should loop the function 255 times with 1 second delay and move the projector mirror from left to right, anyway some an unknown reason, the variable “index” after 7 cycles (more or less, depends from i don’t know what) this variable assumes a value around 50000 which is obviously higher than 255 and the cycle stops.

We’re sure it’s a problem related to the library because if we comment out SetData and put a simple message popup telling the index it’s currently on cycle, it works perfectly till 255.

The library and the DLL are the latest ones.

Any wonder why it doesn’t work correctly?

Greetings,
Niko.

No, the loop should iterate 256 times.

What is the data type used for index?

index is an int but i guess that doesn’t matter because if I put it in an infinite loop same thing happens, for example:

int test= 0; while (1) { SetData(channel,data); Delay(1.0); test++; SetCtrlVal(gui,PANEL_TEST,test); //shows on a panel how many times the while loop repeated }

after around 7 cycles the variable test assumes an high value.
I tried using int, long int, double but they all behaved the same.

E: It doesn’t matter what kind of data is written, it’s enough that SetData() is present to make this problem appear.

I’m curious. What might happen if you comment the line SetData(channel,data);.

int test= 0; while (1) { //SetData(channel,data); Delay(1.0); test++; SetCtrlVal(gui,PANEL_TEST,test); //shows on a panel how many times the while loop repeated }

This seems to work:
int index; for (index = 0; index <= 255; index++) { SetData(1, index); Thread.Sleep(1000); //pauses the currently running thread by 1000ms }

You need to add “using System.Threading;”

sorry for the delay,
I was in vacation and didn’t check the forum anymore.
anyway by commenting it out it works just fine,
now i’ll try including system threading.

E: excuse me did you notice i’m using C# and not C++?

because Delay() is a valid function in C# already, without using the system threading namespace and it does the job already.

[quote=“nikooo777”]E: excuse me did you notice i’m using C# and not C++?
because Delay() is a valid function in C# already, without using the system threading namespace and it does the job already.[/quote]

Sleep is a static method of the Thread class in the System.Threading namespace (.NET)
msdn.microsoft.com/en-us/library … hread.aspx

There is no such thing in C++