Home > Language Reference > Classes
BarCode Class
+ Object
+ BarCode
Description
The BarCode class encapsulates methods and necessary properties for piloting the barcode scanners of Symbols® SPT-1500 to SPT-1800 device. This class is instanciable, but can neither be derived nor duplicated.
Initializing the scanner
The scanner initializes with the first instanciation of a BarCode object. Inversely, the scanner is turned off with the destruction of last BarCode object by the garbage collector. If your application has only one form, then it is sufficient to just declare an instance of the object on this form, as shown in the following example:
Private Scan As New BarCode Private Sub Form_Load() Scan.DefaultParams Scan.Enabled = True End Sub Private Scan_Decode(ByVal sData As String, ByVal eType As HbBarType) If eType<>0 Then MsgBox "BarCode: " & sData End Sub
On the other hand, if your application has many forms, this behaviour is problematic: when switching from one form to the other, it is possible that the first form in which the BarCode object has been declared may be destroyed before the next form in which a new instance of the BarCode object is loaded - this will result into the turning off and untimely restart of the beam. To avoid this, just declare an additional instance of a BarCode object that will remain active throughout the life of the application. For example, you can write in your main application class:
Private Scan As BarCode
Private Function InitScanner() As Boolean
On Error Goto ERR
Set Scan = New BarCode
Scan.DefaultParams
Scan.Enabled = True
InitScanner = True
Exit Function
ERR:
MsgBox "Error initializing scanner"
InitScaner = False
End Function
Private Sub Application_NormalLaunch()
Dim f as frmMain
If InitScanner Then
Set f = New frmMain
f.Show hbFormModeless+hbFormGoto
End If
End SubThen, you can declare a new member variable of BarCode type, on each form where the scanner is required, as shown in the example below:
Private Scan As New BarCode Private Scan_Decode(ByVal sData As String, ByVal eType As HbBarType) If eType<>0 Then MsgBox "BarCode: " & sData End Sub
The initialization code that was previously written in Load event manager is no longer necessary, having already initialized and configured the scanner when the application was launched by calling the function InitScanner.
Note: if you declare a global variable of type BarCode or member of the Application class, as given above, it is important to omit the keyword New. In fact, these variables are initialized as soon as the application starts, with no regards to the launching code. This could initialize the scanner even in case it is not necessary, as for example when your application is activated for infrared data transfer, or when the user performs a global search.
Scanner configuration
The scanner configuration is global to all the applications. As a previous application may have left the scanner in any state, you should always configure it when your application starts.
For this, you can use the DefaultParams method that reinitializes all parameters of the device to their default values. If required, you can then override recognition of bar codes by assigning False value to the BarCode property, and specifying triggering mode of a reading cycle by setting the value of the TriggeringMode property. Finally, you must activate the device by assigning the True value to the Enabled property.
The following example shows a typical initialization and configuration routine of the scanner. After having created an instance of the BarCode object, we reinitialize all the parameters at their default values, we authorise recognition of only EAN type bar codes, we set the triggering mode of the scanner and then we activate it:
Private Scan As BarCode Private Function InitScanner() As Boolean On Error Goto ERR Set Scan = New BarCode Scan.DefaultParams Scan.BarCode(hbBarTypeEAN13) = True Scan.BarCode(hbBarTypeEAN8) = True Scan.BarCode(hbBarTypeEAN128) = True Scan.BarCode(hbBarTypeBOOKLAND_EAN) = True Scan.BarCode(hbBarTypeCODE39) = False Scan.BarCode(hbBarTypeUPCA) = False Scan.BarCode(hbBarTypeUPCE0) = False Scan.BarCode(hbBarTypeI2OF5) = False Scan.BarCode(hbBarTypeCODABAR) = False Scan.BarCode(hbBarTypeCODE128) = False Scan.BarCode(hbBarTypeCODE93) = False Scan.BarCode(hbBarTypeTRIOPTIC39) = False Scan.BarCode(hbBarTypeMSI_PLESSEY) = False Scan.BarCode(hbBarTypeUPCE1) = False Scan.BarCode(hbBarTypeISBT128) = False Scan.BarCode(hbBarTypeCOUPON) = False Scan.BarCode(hbBarTypePDF417) = False Scan.TriggeringMode = hbScanHost Scan.SendParams Scan.Enabled = True InitScanner = True Exit Function ERR: MsgBox "Error initializing scanner" InitScaner = False End Function
The system always maintains a copy of hardware configuration in memory. The BarCode and TriggeringMode properties act only on this copy. To activate the configuration, it is necessary to call the SendParams method which sends the configuration to the scanner.
Reading a Bar Code
Reading is activated either by calling the DecodeStart method, or by a push on the device trigger. In both cases, a Trigger event is thus sent immediately by the object. Following the value of the TriggeringMode property, reading stops either with a successful recognition of a bar code or with a release of device trigger by the user, or when the DecodeStop method is called. In all cases, a Decode is sent.
The following example shows how to use these events to place recognized bar code value in a text field (the initialization code of the scanner is omitted):
Private Scan As New BarCode
Private Scan_Trigger()
Field1.Text = "Scanning..."
End Sub
Private Scan_Decode(ByVal sData As String, ByVal eType As HbBarType)
If eType<>0 Then
Field1.Text = sData
Else
Field1.Text = "No data"
End If
End SubYou can refer to the CashRegister sample for a full example of using this object and its methods.
Members
| Members | Description |
| Aim | Indicates whether the scanner is in 'pointer' mode. |
| BarCode | Indicates types of bar codes recognized by the scanner. |
| BatteryError | Event sent when battery charge becomes insufficient. |
| Beep | Prompts emission of a beep by the bar code scanner. |
| Decode | Event sent when the scanner has finished the reading of a bar code. |
| DecodeStart | Starts the reading of a bar code. |
| DecodeStop | Interrupts reading of a bar code. |
| DefaultParams | Reinitializes all the scanner parameters to their default values. |
| Enabled | Indicates whether or not the scanner is active. |
| I2of5CheckDigitVerification | Determines whether to use a check digit algorithm when scanning an I2of5 symbol. |
| LED | Indicator state of the scanner of bar codes. |
| SendParams | Sends the configuration parameters to the scanner. |
| SetBarcodeLengths | Sets the number of digits for each format that are to be decoded. |
| Trigger | Event sent at the start of the reading of a bar code. |
| TriggeringMode | Defines the triggering mode of the scanner. |
| UpcEanRedundancy | Indicates the number of time a symbol is decoded. |
| UpcEanSupplementals | Indicates how UPC/EAN codes that include supplemental characters are to be decoded. |
| WideAngle | Scanner's field of view. |
| Inherited from Object | Description |
| ClassID | Returns the type identifier corresponding to the actual class of the object. |
| Implements | Determines whether the object implements the features of a given class. |
| Iterate | Event raised to iterate over the elements of a container object. |
| Recipient | Recipient of events sent by the object. |
| Serialize | Event raised to serialize the object content into a stream. |
System requirements
| System | Minimal version | Remarks |
| Palm OS | Palm OS 3.0 | Only Symbol Technologies scanners are supported. |