Re: ActiveX.exe more problems




"Galen Somerville" <galen@xxxxxxxxxxxx> schrieb im Newsbeitrag
news:u1z7yPmhGHA.896@xxxxxxxxxxxxxxxxxxxxxxx

I have a simple 24 byte array and the third party call
requires "VarPtr(DatAry(0))" in Cthread. I can only test
in full blown app because of USB device.

Question.
Does Cmain and Cthread share the data in SharedData.bas?
Yes, the whole communication between CMain and CThread is
done over this mechanism.

If so then I don't need to set up a SharedAry, etc and could
use DatAry directly.
I would recommend, using the setup as it comes with the demo.
I mean, adapt it to your real stuff, but don't change the principle -
and the usage of the SharedArr (and especially the RingBuffer)
is one of the most important pieces in the Demo-scenario.

Regarding the adaption to your DatAry()-Array:
In your original Code you probably have something like this:

Private DatAry(0 to 23) as Byte
'and somewhere inside a loop:
USBDll_GetNewDataFromDeviceInto VarPtr(DatAry(0)), ...
assuming all the 24 Bytes are filled in a single call.

You should change the following type inside SharedData.bas:
Public Type TBurstData
SixSamples(0 To 5) As Long
End Type
into:
Public Type TBurstData
DatAry(0 To 23) As Byte
End Type

Change the MainLoop inside CThread into something like this:
With SharedArr(0)
InitSuccess = InitDevice()
If InitSuccess Then
'tell the MainThread, that we've initialized our Device
.DeviceInitialized = True

Do Until .CancelProcessing 'loop, until the Main-Thread sets the flag
If .CallbackHwnd Then PostMessage .CallbackHwnd, &H100, 0, 0
Dim pDatAry As Long
pDatAry = VarPtr(.RingBuffer(CurRingIndex).DatAry(0))
USBDll_GetNewDataFromDeviceInto pDatAry,...
.RingIndex = CurRingIndex 'signalize, up to wich slot we are
'now let's switch our internal RingIndex again one step ahead
CurRingIndex = (CurRingIndex + 1) Mod (UBound(.RingBuffer) + 1)
Loop
....

And finally redefine in CMain:
Public Event BurstEvent(DatAry() As Byte)
....
inside
Private Sub CallbackForm_CheckRingBufferQueue
...
RaiseEvent BurstEvent(DataChunk.DatAry)


That's all.

Don't let out the already builtin RingBuffer-Support, wich gives
you much greater "freedom", regarding the decoupling of the
"streaming realtime-data" inside CThread and their (possible
much later) Handling inside CMain.
The RingBuffer currently has 64 slots, to fill independent 'DatArys' in.
If the capturing of one single DatAry inside CThread needs around
15msec, then this RingBuffer-Cache gives you a "React-TimeFrame"
of about one second (64*15) inside CMain.
Remember, CMain is running inside the Visualizer-App, wich can
block for all the wellknown good reasons, so having a cache of this
type, you are able to keep up from the last processed index up to
the current one without loosing any DatAry-Buffers, during a larger
"User-Interface-Blocking-TimeOut".
If the one second reserve is not enough, you can simply enhance
the Cache-Depth to 128 (2seconds) or 256 (4seconds).

Olaf


.



Relevant Pages

  • Re: ActiveX.exe more problems
    ... , then let the thread simply in its loop, until you set a flag ... over the shared-array, to signalize the next round of sampling. ... As said above - there's absolutely no problem, to signalize from CThread ... is also no problem for CMain, to tell CThread ...
    (microsoft.public.vb.general.discussion)
  • Re: ActiveX.exe more problems
    ... The real-time in my App is controlled by a USB ... that the MainThread (CMain) is checking ... for new data, that you just filled in (inside CThread), then simply ... CMain (over the Helperforms-KeyDown -> triggering an Event inside ...
    (microsoft.public.vb.general.discussion)
  • Re: ActiveX.exe more problems
    ... Does Cmain and Cthread share the data in SharedData.bas? ... Both the App and the USB device know exactly what is happening. ...
    (microsoft.public.vb.general.discussion)

Loading