ProScript .NET Documentation
ProScript .NET Documentation
ProScript
Getting Started
.NET ProScript Examples

# .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
- Handling Events

Finding ScripTouch Devices

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

C#
VB
C++
F#
Copy

     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}

     1' Enumerate all of the devices attached to the system.
     2Dim devices As List(Of Device) = DeviceManager.GetAttachedDevices
     3Dim device As Device
     4
     5' If we have at least one device
     6If devices.Count > 0 Then
     7    device = devices.Item(0)
     8    device.Open()
     9
    10    ' Do whatever application specific things you'd like to do here.
    11
    12    ' Close the device when you're done.
    13    device.Close()
    14End If

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

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.

C#
VB
C++
F#
Copy

      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}

      1' <copyright file="VBConsoleExample.vb" company="Scriptel Corporation">
      2'      Copyright 2015 - Scriptel Corporation
      3' </copyright>
      4Imports ProScript
      5
      6''' <summary>
      7''' This module shows a very simple exmaple of how to open and read from a
      8''' ScripTouch device.
      9''' </summary>
     10Module VBConsoleExample
     11    ''' <summary>
     12    ''' Main subroutine for this program.
     13    ''' </summary>
     14    ''' <remarks></remarks>
     15    Sub Main()
     16        'A reference to our event handling class.
     17        Dim example As VBConsoleExample = New VBConsoleExample
     18        'The list of devices from the library.
     19        Dim devices As List(Of Device)
     20        'A reference to our device.
     21        Dim device As Device
     22
     23        'Regster our event handling class as interested in hotplug events.
     24        DeviceManager.RegisterDeviceListener(example)
     25
     26        'List the devices currently attached to the system.
     27        devices = DeviceManager.GetAttachedDevices
     28
     29        'Print out the devices we've found.
     30        Console.WriteLine("Found " & devices.Count & " device(s): ")
     31        For Each d As Device In devices
     32            Console.WriteLine("   " & d.GetModel())
     33        Next
     34
     35        'Test to make sure we have at least one device.
     36        If devices.Count > 0 Then
     37            'Get a reference to the first device.
     38            device = devices.Item(0)
     39            Console.WriteLine("Opening " & device.GetModel() & " (Sign / Swipe now)")
     40            'Sets the device property of our event handling class.
     41            example.Device = device
     42            'Register our event handling class as interested in device events.
     43            device.RegisterInputListener(example)
     44            'Open the device.
     45            device.Open()
     46
     47            'While the device is open
     48            While device.IsOpen
     49                'Read from the device.
     50                device.Read()
     51            End While
     52        Else
     53            Console.WriteLine("No devices found, exiting.")
     54        End If
     55    End Sub
     56
     57    ''' <summary>
     58    ''' This class is an event handler for ProScript library events.
     59    ''' </summary>
     60    Class VBConsoleExample
     61        Implements IDeviceNotificationListener
     62        Implements IInputListener
     63
     64        ''' <summary>
     65        ''' Reference to the open device.
     66        ''' </summary>
     67        ''' <value>Reference to the open device.</value>
     68        ''' <returns>Reference to the open device.</returns>
     69        Public Property Device As Device
     70
     71        ''' <summary>
     72        ''' This method gets called when a new device is plugged into the system.
     73        ''' </summary>
     74        ''' <param name="path">Path of the device.</param>
     75        ''' <param name="device">Reference to the device.</param>
     76        Public Sub ReceiveDeviceAttachedNotification(path As String, device As Device) Implements IDeviceNotificationListener.ReceiveDeviceAttachedNotification
     77            Console.WriteLine("Device added to the system: " & path)
     78        End Sub
     79
     80        ''' <summary>
     81        ''' This method gets called when a device is removed from the system.
     82        ''' </summary>
     83        ''' <param name="path">Path of the device.</param>
     84        ''' <param name="device">Reference to the device.</param>
     85        ''' <remarks></remarks>
     86        Public Sub ReceiveDeviceDetachedNotification(path As String, device As Device) Implements IDeviceNotificationListener.ReceiveDeviceDetachedNotification
     87            Console.WriteLine("Device removed from the system: " & path)
     88        End Sub
     89
     90        ''' <summary>
     91        ''' This method gets called when a button on the device is pressed.
     92        ''' </summary>
     93        ''' <param name="c">Button event from the device.</param>
     94        Public Sub ReceiveButtonEvent(c As ButtonEvent) Implements IInputListener.ReceiveButtonEvent
     95            Console.WriteLine("ButtonEvent: type=" & c.GetType().ToString() & ", x=" & c.GetX() & ", y=" & c.GetY() & ", region=" & c.GetRegion())
     96
     97            If TypeOf c Is ButtonPress And c.GetRegion() = 3 Then
     98                Device.Close()
     99            End If
    100        End Sub
    101
    102        ''' <summary>
    103        ''' This method gets called when a coordinate event is generated on the device.
    104        ''' </summary>
    105        ''' <param name="c">Coordinate event.</param>
    106        Public Sub ReceiveCoordinateEvent(c As Coordinate) Implements IInputListener.ReceiveCoordinateEvent
    107            Console.WriteLine("Coordinate: x=" & c.GetX() & ", y=" & c.GetY() & ", penDown=" & c.IsPenDown())
    108        End Sub
    109
    110        ''' <summary>
    111        ''' This method gets called when a magnetic card swipe event is generated on the device.
    112        ''' </summary>
    113        ''' <param name="c">Magnetic card swipe event.</param>
    114        Public Sub ReceiveMagneticStripEvent(c As MagneticCardSwipe) Implements IInputListener.ReceiveMagneticStripEvent
    115            Console.WriteLine(c)
    116        End Sub
    117
    118        ''' <summary>
    119        ''' This method gets called when a diagnostic event is generated.
    120        ''' </summary>
    121        ''' <param name="c">Diagnostic event</param>
    122        Public Sub ReceiveDebugCoordinateEvent(c As DebugCoordinate) Implements IInputListener.ReceiveDebugCoordinateEvent
    123            'We generally don't care about these events.
    124        End Sub
    125
    126        ''' <summary>
    127        ''' This method gets called when a diagnostic event is generated.
    128        ''' </summary>
    129        ''' <param name="c">Diagnostic event</param>
    130        Public Sub ReceiveADCChannelValues(c As ADCChannelValues) Implements IInputListener.ReceiveADCChannelValues
    131            'We generally don't care about these events.
    132        End Sub
    133
    134        ''' <summary>
    135        ''' This method gets called when a diagnostic event is generated.
    136        ''' </summary>
    137        ''' <param name="c">Diagnostic event</param>
    138        Public Sub ReceiveADCScanValues(c As ADCScanValues) Implements IInputListener.ReceiveADCScanValues
    139            'We generally don't care about these events.
    140        End Sub
    141    End Class
    142End Module

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

Copyright 2015 Scriptel Corporation. All Rights Reserved.