Example code |
STSeries.dll is a .NET assembly used to interface the ScripTouch Series of digitizers to applications. C# is a natural choice of languages for a new .NET application. For this reason, the C# example is the most complete of the example set. Example applications are provided within Visual Studio 12 projects, found in examples.zip. With a ScripTouch device attached, open one of the projects with Visual Studio 12, build and run the application. Experiment with the applications as a user, and modify the code to gain a better understanding of the API.
This topic contains the following sections:
To find all of the devices attached to the system, instantiate an STSeriesDevicesManager object. The number of devices attached is returned by GetNumberOfSTSeriesDevices and GetSTSeriesDevice(Int32) will return a the device requested.
1// get all of the digitizers plugged into the system 2ISTSeriesDevice selectedDevice; 3 4ISTSeriesDevicesManager devManager = new STSeriesDevicesManager(); 5 6if (devManager.GetNumberOfSTSeriesDevices() > 0) 7{ 8 // Use the first device in the list 9 selectedDevice = devManager.GetSTSeriesDevice(0); 10 11 // Open the device to prepare it for use 12 try 13 { 14 selectedDevice.Open(); 15 } 16 catch (STDeviceNotOpenedException dno) 17 { 18 System.Diagnostics.Debug.Assert(false, 19 "Can't open the first device found...this shouldn't happen " + 20 dno.Message)); 21 } 22} 23else 24{ 25 System.Diagnostics.Debug.Assert(false, "No devices found"); 26}
Once a device object is obtained, you must decide how you want to address it. You can address it through the generic interface ISTSeriesDevice or the specific device's interface, such as IST1500U. The advantage to the former is that your code can use this interface for any ScripTouch device. In most cases this is sufficient. If the device does not support paticular feature, calls to that feature are ignored. For example, clearing the display on an ST1400 does nothing because the screen is always clear. Some devices may have special features only available through its class/interface.
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 the pertinent part of a class that registers for a button event. RegisterButton causes any event on any button to call OnButtonSelected(). At some point the button should be unregistered as seen in UnregisterButton().
1namespace Scriptel.STSeries.Examples.Csharp 2{ 3 using System; 4 using Scriptel.STSeries; 5 6 public class STSeriesExample 7 { 8 private ISTSeriesDevice selectedDevice; 9 private STSeriesDevice.ButtonSelectedEventHandler buttonTarget; 10 private STSignature sig = new STSignature(); 11 12 ... 13 14 public void RegisterButton() 15 { 16 // this will register the buttons on the screen to fire an event to 17 // the OnButtonSelected() method whenever the pen goes down on a button or 18 // is lifted off the button 19 // this assumes that selectedDevice is assigned and opened prior to reaching this point 20 21 buttonTarget = new STSeriesDevice.ButtonSelectedEventHandler(OnButtonSelected); 22 selectedDevice.RegisterForButtonSelectedEvent(this, buttonTarget); 23 } 24 25 public void UnregisterButton() 26 { 27 // Unregisters for the ButtonSelectedEvent. This will stop you from receiving information when a button region is selected. 28 selectedDevice.UnregisterForButtonSelectedEvent(this, buttonTarget); 29 } 30 31 private void OnButtonSelected(Object sender, STSeriesDevice.RegionSelectedEventArgs e) 32 { 33 // e.SigPoint will tell whether the pen was down or lifted. If down, it will 34 // tell the XY coordinates. 35 // e.RegionNumber will tell us which button was selected 36 37 // Add the new signature point to the signature 38 // because this is in the button event handler, this is only going 39 // to happen when the stroke starts in a button...this maybe a 40 // silly thing to do, but it is for example only. 41 sig.AddPoint(e.SigPoint); // see below 42 } 43 } 44}
The STSignature class is a convenient way to store and process signatures captured from the device as individual points. In the example above, the last line of code added a point to an STSignature object. This class can be used to do very useful things such as Save the signature to a raster file, to save to the clipboard, to crop, and other useful things.