Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CSScript/Threading question..
#1
Hi -

I'm trying to listen in QM for events from a Dictaphone PowerMicII-NS microphone. This microphone has several buttons on it and I'd like to capture events on a subset of the buttons. I have a working C# program that can read the events but I don't know the best way to hook this into QM.

If I create the event like this:
Function PowerScribeListener
Code:
Copy      Help
#opt nowarnings 1 ;;disable warning "Most COM objects cannot be global"
IDispatch+ ps360MicrophoneListener
#opt nowarnings 0

In another function I can set the LEDs on the microphone to various colors and through Console.WriteLine() statements in C# it appears that everything is working. In general - all synchronous commands appear to be working from the IDispatch object.

However - with async callbacks I'm stumped. Keeping a reference to the IDispatch object in QM does not appear to keep the callbacks working. So - I launched a separate thread in C#:

Code:
Copy      Help
public int aSyncInitMicrophone(int msec)
        {
            Thread t = new Thread(new ThreadStart(ThreadProc));
            continueLoop = 1;
            t.Start();
            t.Join();
            return 0;
        }
where ThreadProc does the initialization. If I do this - the callbacks from button presses appear in the console. The good part is that this appears to work; the bad part is that it feels awkward and that there is probably a much cleaner way to do this. The thread needs to run for hours in a clinical application so I want this to be solid.

Thanks for any advice.
#2
Try

Code:
Copy      Help
CsScript x
;x.SetOptions("references=...")
x.AddCode("")
IDispatch ps360MicrophoneListener=x.CreateObject("...")
ps360MicrophoneListener.Func(...)
...

opt waitmsg 1
wait -1


#ret
//C# code
using System;
...
#3
Thanks. Works perfectly.


Forum Jump:


Users browsing this thread: 1 Guest(s)