Click or drag to resize

.NET ProScript Examples

The ScripTouch .NET Assembly (proscript-csharp.dll) is used to interface the ScripTouch Series of digitizers to applications.

This topic contains the following sections:

Finding ScripTouch Devices

To find all of the devices attached to the system call the DeviceManager.GetAttachedDevices method.

 1// Enumerate all of the devices attached to the system.
 2List<Device> devices = DeviceManager.GetAttachedDevices();
 3
 4// If we have at least one device.
 5if (devices.Count > 0)
 6{
 7    // Open the first device.
 8    Device device = devices[0];
 9    device.Open();
10
11    // Do whatever application specific things you'd like to do here.
12
13    // Close the device when you're done.
14    device.Close();
15}
Handling Events

Events are used to notify the program that an action has occurred on the device. Events can be setup to indicate pen-up or pen-down on the screen or on a button; when the device is unplugged; and when the firmware is downloaded.

The example below shows how to register for button and coordinate events. By implementing the IInputListener interface, an object can then register itself for device events by calling RegisterInputListener on the device object. In order to receive any events, a new thread must be created to continuously call Read() on the Device object. At some point the client object should unregister itself by calling UnregisterInputListener on the Device object and the reading thread should be terminated.

  1// <copyright file="ConsoleExample.cs" company="Scriptel Corporation">
  2//      Copyright 2015 - Scriptel Corporation
  3// </copyright>
  4namespace ConsoleExample
  5{
  6    using System;
  7    using System.Collections.Generic;
  8    using ProScript;
  9
 10    /// <summary>
 11    /// This class shows a very simple example of how to open and read from a
 12    /// ScripTouch device.
 13    /// </summary>
 14    class ConsoleExample : IDeviceNotificationListener, IInputListener
 15    {
 16        //Reference to the open device.
 17        private Device device;
 18
 19        static void Main(string[] args)
 20        {
 21            //Create a new instance of this class so we can pass the references
 22            //to the ProScript library.
 23            ConsoleExample example = new ConsoleExample();
 24
 25            //Register ourselves for hotplug notifications.
 26            DeviceManager.RegisterDeviceListener(example);
 27
 28            //List the devices currently attached to the system.
 29            List<Device> devices = DeviceManager.GetAttachedDevices();
 30
 31            //Print out the devices we found.
 32            Console.WriteLine("Found " + devices.Count + " device(s): ");
 33            foreach(Device d in devices) {
 34                Console.WriteLine("   " + d.GetModel());
 35            }
 36            Console.WriteLine();
 37
 38            //Test to make sure we have at least one device.
 39            if (devices.Count > 0)
 40            {
 41                //Open the first device.
 42                Device device = devices[0];
 43                //Give a reference to our example instance.
 44                example.device = device;
 45                //Write out our intention to open the device.
 46                Console.WriteLine("Opening " + device.GetModel() + " (Sign / Swipe now)");
 47                //Register for input events.
 48                device.RegisterInputListener(example);
 49                //Open the device.
 50                device.Open();
 51                //While the device is open
 52                while (device.IsOpen())
 53                {
 54                    //Read from the device.
 55                    //This can be done from a separate thread if you don't
 56                    //want to block the main thread. See the FormExample for an
 57                    //example of this.
 58                    device.Read();
 59                }
 60            }
 61            else
 62            {
 63                //If not, we'll just exit.
 64                Console.WriteLine("No devices found, exiting.");
 65            }
 66        }
 67
 68        /// <summary>
 69        /// This method gets called when a new device is attached to the system.
 70        /// </summary>
 71        /// <param name="path">Path of the added device.</param>
 72        /// <param name="device">Reference to the added device.</param>
 73        public void ReceiveDeviceAttachedNotification(string path, Device device)
 74        {
 75            Console.WriteLine("Device added to the system: " + path);
 76        }
 77
 78        /// <summary>
 79        /// This method gets called when a device gets removed from the system.
 80        /// </summary>
 81        /// <param name="path">Path of the removed device.</param>
 82        /// <param name="device">Reference to the removed device.</param>
 83        public void ReceiveDeviceDetachedNotification(string path, Device device)
 84        {
 85            Console.WriteLine("Device removed from the system: " + path);
 86        }
 87
 88        /// <summary>
 89        /// This method gets called any time there is a button event, there are four types
 90        /// of button events.
 91        ///    ButtonDown  - Pen is now against the glass on a button.
 92        ///    ButtonMove  - The pen has been down, and is moving on the surface of a button.
 93        ///    ButtonPress - The button has been pressed.
 94        ///    ButtonUp    - The button is no longer up, but has not been pressed.
 95        /// </summary>
 96        /// <param name="c">Button event</param>
 97        public void ReceiveButtonEvent(ButtonEvent c)
 98        {
 99            Console.WriteLine("ButtonEvent: type=" + c.GetType() + ", x=" + c.GetX() + ", y=" + c.GetY() + ", region=" + c.GetRegion());
100
101            if (c is ButtonPress && c.GetRegion() == 3)
102            {
103                //Ok was pressed, lets close.
104                device.Close();
105            }
106        }
107
108        /// <summary>
109        /// This method gets called when a coordinate is received from the device.
110        /// </summary>
111        /// <param name="c">Coordinate from the device.</param>
112        public void ReceiveCoordinateEvent(Coordinate c)
113        {
114            Console.WriteLine("Coordinate: x=" + c.GetX() + ", y=" + c.GetY() + ", penDown=" + c.IsPenDown());
115        }
116
117        /// <summary>
118        /// This method gets called when a magnetic card swipe is detected from the device.
119        /// </summary>
120        /// <param name="c">Card swipe from the device.</param>
121        public void ReceiveMagneticStripEvent(MagneticCardSwipe c)
122        {
123            //Print out the card swipe data.
124            Console.WriteLine(c);
125        }
126
127        /// <summary>
128        /// This is used for diagnostics, this isn't useful for most applications.
129        /// </summary>
130        /// <param name="c">Diagnostic value from the device.</param>
131        public void ReceiveADCChannelValues(ADCChannelValues c)
132        {
133            //We don't care about this event.
134        }
135
136        /// <summary>
137        /// This is used for diagnostics, this isn't useful for most applications.
138        /// </summary>
139        /// <param name="c">Diagnostic value from the device.</param>
140        public void ReceiveADCScanValues(ADCScanValues c)
141        {
142            //We don't care about this event.
143        }
144
145        /// <summary>
146        /// This is used for diagnostics, this isn't useful for most applications.
147        /// </summary>
148        /// <param name="c">Diagnostic value from the device.</param>
149        public void ReceiveDebugCoordinateEvent(DebugCoordinate c)
150        {
151            //We don't care about this event.
152        }
153    }
154}