DesktopSDK 0.7 - PenComm Library (C#) Documentation
ContentsIndexHome
User Time Example
Examples
    private void GetTime(Smartpen pen)
    {
        try
        {
            // Get the current time of the smartpen as the number of milliseconds since 1/1/1970
            ulong userTime = pen.UserTimeGet();

            // Create a DateTime object that represents 1/1/1970
            DateTime time_1_1_1970 = new DateTime(1970, 1, 1);

            // Create a DateTime object that represents current time of the pen
            DateTime currentPenTime = time_1_1_1970.AddMilliseconds(userTime);

            // Show the current DateTime value of the smartpen.
            MessageBox.Show(currentPenTime.ToString());
        }
        catch (Exception e)
        {
            HandleError(e);
        }
    }

    private void SetTime(Smartpen pen, DateTime penTime)
    {
        try
        {
            // Create a DateTime object that represents 1/1/1970
            DateTime time_1_1_1970 = new DateTime(1970, 1, 1);

            // Convert 1/1/1970 to number of milliseconds.
            double milliSeconds_1_1_1970 = new TimeSpan(time_1_1_1970.Ticks).TotalMilliseconds;

            // Convert penTime to number of milliseconds.
            double milliSeconds = new TimeSpan(penTime.Ticks).TotalMilliseconds;

            // Number of milliseconds since 1/1/1970
            double userTime = milliSeconds - milliSeconds_1_1_1970;

            // Set smartpen time
            pen.UserTimeSet((ulong)userTime);
        }
        catch (Exception e)
        {
            HandleError(e);
        }
    }
Created with a commercial version of Doc-O-Matic. In order to make this message disappear you need to register this software. If you have problems registering this software please contact us at support@toolsfactory.com.
Copyright © 2010 Livescribe, Inc. All rights reserved.