PC SDK – Handling pen data

This section will cover some of the basics in developing your own application using the PC SDK. Most of the code can be found elsewhere in the documentation but some sections are new and will give examples of how to implement interesting features.

In this example, we will build a simple application that subscribes to pen data collected from a specific page and save it to file. This application is written in C# but any other language from .NET can be used.

  1. Start by creating a new project (Class library) with an empty class; name your class “NotifyClass”
  2. Add references to the Anoto API in our project:
    Anoto Notification (used to get the pen data and register for different paper categories)
    Anoto Service (used to initialize and get different parts of the pen data file)
    Anoto Util (used for pen data open/save disk operation)

    The project code should now look like this:
    <span class="wysiwyg-font-size-small">namespace PCSDKStart { public class NotifyClass { } }</span>
  3. Register this application for COM Interop (in Visual Studio 2005: Project properties -> Build -> Register for COM Interop)
    To be able to receive PGC data, your application must fulfil 2 conditions:
      a)  Implement the IDataReceiver interface in the Anoto Notification library
      b)  Be registered with the PLS for PC via the Registration API
  4. Implementation of the IDataReceiver interface
    The IDataReceiver interface has one method (Notify) and one property (Category) that needs to be implemented. The Category property is used to register the application to subscribe to different form types. When designing your form type, the same paper category is set as an attribute and it makes it possible to link a specific form type with an application. See updated code below where Category returns the example category “MyApp::PaperCategory”:

    <span class="wysiwyg-font-size-small">using System; namespace PCSDKStart { public class NotifyClass : Anoto.Notification.IDataReceiver { public string Category { get { return "MyApp::PaperCategory"; } } } }</span>

    The Notify method is called during the data synchronization (the operation when pen data is transferred to the application).
    Next step we specify our Notify method. This method is the “entrance” to our application. The parameters in this method are Category (“string cat” - the reason this application was called) and the pen data itself (object inData). Unless you are using your application for handling different paper categories, the string “cat” is not interesting for now. The transferred data is handled as follow:
    -> Create a pen request
    -> Initialize the transferred data
    -> Save pen data for later use

    The code below is defining the Notify method:

    <span class="wysiwyg-font-size-small">public void Notify(string cat, object inData) { //create a pen request Anoto.Service.IPenRequest2 request = new Anoto.Service.PenRequestClass(); request.Initialize(inData); //create a file handler and save the pen data to disk (file name: date + time) Anoto.Util.FileClass fileHandler = new Anoto.Util.FileClass(); string date = DateTime.Now.ToString("dd-MM-yyyy_"); string time = DateTime.Now.ToString("hh.mm.ss.ffff"); fileHandler.Write(BASE_PATH + date + time + ".pgc", inData); }</span>

    This is the minimum we need to do to obtain the pen data and save it to disk. No further processing should be made here in a more complex application. The reason for this is that we do not want our application to be tied up in complex operations. Further processing (like image rendering) should be placed in a separate application (which can be started from our Notify method passing the PGC file path as an argument for example or can be an application polling for files in a folder).
  5. Register your application for the PLS for PC
    This application must be registered using the Anoto Registration Manager in order to be able to receive notifications from the PLS. The Category property declared earlier is used by the Registration API when querying our application for what paper categories it wants to subscribe to. When the application is installed on a machine, we need to register the paper categories that are to be handled by our application. This is done either by the installer itself or manually. Below is a registration script (VB) that can be used to register an application named “PCSDKStart” using a PAD file from a paper with address

    <span class="wysiwyg-font-size-small">Dim registrationManager, fso, path ' Create needed objects: Set registrationManager = CreateObject("Anoto.SDK.RegistrationManager2") Set fso = CreateObject("scripting.filesystemobject") ' Get path to current folder: path = Mid(WScript.ScriptFullName, 1, Len(WScript.ScriptFullName) - Len(WScript.ScriptName)) ' Register paper: registrationManager.RegisterPaper path & "" ' Register vbExample application: registrationManager.RegisterApplication "PCSDKStart.NotifyClass"</span>

    A copy of this script can be found in the project root (file name: Register.vbs). Double-click it to register your paper category with your application.
    NOTE: this script assumes that the PAD file is in the same folder as the script file. Moreover, the project must be compiled (needs to be built in order to be tested)
  6. Test your application
    Write on a copy of the paper, based on pattern address Dock the pen to your computer and download the pen data. If the synchronization was successful, a PGC file <pendata.pgc> is created in the default folder (C:\development\).

    This is the proper way to handle the pen data. It is not recommended to build complex operations (like image rendering) in the Notify method. The Notify method should do the bare minimum (i.e. save the pen data), avoid locking your local pen service by doing complex processing operations.

Click here to download a ZIP file containing source code, etc. for this example.

Was this article useful? Thanks for the feedback There was a problem submitting your feedback. Please try again later.