Encoder_simple vs Encoder_full, C#

Supporting Visual Studio on Windows
Bryan_sang
Phidgetsian
Posts: 13
Joined: Thu Apr 11, 2013 3:12 am
Location: Seoul, KOREA
Contact:

Encoder_simple vs Encoder_full, C#

Postby Bryan_sang » Wed Jan 06, 2016 11:01 pm

Hi,

In 2012, I've been running almost flawlessly HighSpeedEncoder by using Encoder_simple for monitoring on the console and saving the data as text format file.
In the meantime, I did not have a chance to run the program.

In December 2015, I have updated the phidgets c# program, since I am using the program for other purposes also. With Encoder-full, allowing form-based monitoring, I do not have any problem at all. However, when I run the Encoder_simple, almost always, the program issues error message, even if the console says it acknowledges my HighSpeedEncoder 1057_1.

ErrorType: clr20r3 P1: encoder-simple.exe P2: 1.0.0.0
p3: 4efd467e p4: phidget21.net P5: 2.1.8.227 P6 : 572e67d
p7: 473 P8: 1b P9: phidgets.phidgetexception

Exception Information
Code: 0xe0434f4d

System Information
Windows NT 5.1 Build: 2600

By the way, I have an old PC running WindowsXP, with a Pentium CPU.

--P.S.: I have almost the same symptom even with new PC's, running Windows7, i5, or Windows 8.1, i7 CPU.

Thanks in advance,

Bryan

User avatar
Patrick
Lead Developer
Posts: 3064
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Encoder_simple vs Encoder_full, C#

Postby Patrick » Thu Jan 07, 2016 10:51 am

Hi,

This is because the Time property from the position change event can throw an exception on the first event - when the time isn't yet known.

You can fix the example by putting a try-catch block around the accessor like so:

Code: Select all

        static void encoder_PositionChange(object sender, EncoderPositionChangeEventArgs e)
        {
            try
            {
                Console.WriteLine("Encoder {0} Change {1} Time {2} Position {3}", e.Index,
                                       e.PositionChange, e.Time, encoder.encoders[e.Index]);
            }
            catch { }
        }

The library really shouldn't be throwing an exception on an event property like this, so I'll remove that behaviour in the library.

-Patrick

Bryan_sang
Phidgetsian
Posts: 13
Joined: Thu Apr 11, 2013 3:12 am
Location: Seoul, KOREA
Contact:

Re: Encoder_simple vs Encoder_full, C#

Postby Bryan_sang » Sun Jan 17, 2016 6:22 pm

Dear Patrick,

Thanks for the kind reply to this problem.
I'll give it a try.


Bryan :D


Return to “C#.NET”

Who is online

Users browsing this forum: No registered users and 1 guest