Running Read in separate thread(Read 9396 times)
Running Read in separate thread on: February 13, 2018, 03:23:35 PM
During evaluating of the Serial Port ActiveX control faced with obstacle which I could not overcome even after a day desperately attempts. The machine runs under WIN7 and VS2015 IDE.
Namely, I could not run the Read() function in BlockMode in a separate thread like background worker.  The Read function always returns immediately. Running it from main thread or event function it woks but as expected block the program's UI.

Thank you for your efforts to help me in advance!

Georg



Re: Running Read in separate thread Reply #1 on: February 13, 2018, 03:30:05 PM
Can you provide us with the source code that you use?



Re: Running Read in separate thread Reply #2 on: February 13, 2018, 04:38:52 PM
Even though timeouts and BlockMode was properly set, the Read function returns immediately.

 private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            byte[] Buff = new byte[100];
            int count, retval;
            count = 10;

            while (backWorker.CancellationPending == false)
            {
                count = 10;
                retval = axSPortAx1.Read(out Buff[0], out count);                                 
            }
        }
« Last Edit: February 13, 2018, 05:11:42 PM by georg »



Re: Running Read in separate thread Reply #3 on: February 13, 2018, 05:52:55 PM
I could not to post a message with attachment.
The board refuse it. Does exist any other way to sent it to you?



Re: Running Read in separate thread - solved Reply #4 on: February 14, 2018, 11:41:26 AM
The working solution witch utilizes the Read() method blocking functionality consists from the following steps:

The separated thread was created for serial communication:
   Thread thread1 = new Thread(DoWork);
   thread1.SetApartmentState(ApartmentState.STA); // <- the most important step
   thread1.Start();



In the thread1 DoWork() function create an instance of Serial Port in the following way:       
   SPortLib.SPortAx axSPortAx2 = new SPortLib.SPortAx();



Re: Running Read in separate thread Reply #5 on: February 15, 2018, 03:18:59 PM
Please send us the whole project to support@eltima.com.

Also, right now, we don't have developers that know C# well. Our applications are written in C++ mostly.
So it is rather hard for us to understand what timeouts and BlockMode you use in your code:
"Even though timeouts and BlockMode was properly set".



 

Sitemap 1 2 3 4 5