Using the Scanner SDK for windows with Delphi

T Tim Mills 2 years 5 months ago
165 1 0

I have been attempting to use the Motorola Scanner SDK to upgrade our POS software. We have LS9203 barcode scanners attached to our POS terminals via RS232. We are upgrading this software to allow the integration of a merchant terminal (for credit/debit card) on each POS. These merchant terminals require an RS232 connection and since our hardware only has one port available we would like to move the barcode scanner to a USB port. We have purchased the appropriate cable and the scanner appear to test properly with the Motorola utilities.
I downloaded and installed the SDK have tested some of the code samples in Microsoft Visual Studio and I do get the expected results.

Our POS software is written in Delphi. I appear to be able to make a connection with the scanner driver but when I issue the GetScanners command I get returned the following:

I assume that I have made a successful connection with the Open command. The Status code returns as 0. I am passing 1 in the scannerTypes to look for any type of scanner. The numberOfScanners is returning as 0 so it doesn't look like it has found any. My only guess at this point is that even though it looks like I am sending a 1 in scannerTypes, the GetScanners function is actually receiving a different value thereby not actually looking for any type of scanner. This is possibly due to bit order or position in the Delphi type SmallInt versus the C Type Short.
Does anyone have any sample code for Delphi? Any assistance would be appreciated.

Please register or login to post a reply

1 Replies

T Tim Mills

Here is working code for anyone else who is stumped. Make sure you have installed the correct driver (32bit vs 64bit) and your compiler is generating the executable for the same platform (32bit vs 64bit).

Warning... this is really crumby code but it does work.

I imported the C:\Program Files\Motorola Scanner\CoreScanner.exe (CoreScanner.exe is part of the SDK) into Delphi as a COM object and dropped the resulting component onto my form. The component is named CCoreScanner1

uses CoreScanner_TLB;

CCoreScanner1: TCCoreScanner;

procedure TFrm_BarcodeScannerTest.Button1Click(Sender: TObject);
  ErrorCodeStr : String;

  arraybounds : array [0..0] of TSafeArrayBound;
  arraybounds2 : array [0..0] of TSafeArrayBound;

  scannerTypes : PSafeArray;
  conectedScannerIDList : PSafeArray;

  status : integer;
  numberOfScannerTypes : SmallInt;
  ind : integer;
  oValue : SmallInt;

  numberOfScanners : SmallInt;
  outXML : WideString;

  opres : HResult;
  ArrayBounds[0].lLbound := 0;
  ArrayBounds[0].cElements := 1;

  scannerTypes := SafeArrayCreate(VT_I2,1,@ArrayBounds);

  ind := 0;
  oValue := 1;
  opres := SafeArrayPutElement(scannerTypes,ind,OValue);

  if opres S_OK
    then ShowMessage('Opres Failure');

  numberOfScannerTypes := 1;


    CCoreScanner1.Open(0,scannerTypes, numberofScannerTypes, status);
    if status=0
          ShowMessage('CoreScanner API: Open successful');
          ShowMessage('CoreScanner API Error:'+IntToStr(status));

  ArrayBounds2[0].lLbound := 0;
  ArrayBounds2[0].cElements := 255;

  conectedScannerIDList := SafeArrayCreate(VT_I4,1,@ArrayBounds2);


    if Status0
          ShowMessage('CoreScanner API Error:'+IntToStr(status));

  ShowMessage('Number of Scanners '+IntToStr(numberOfScanners));


I hope this helps other developers out there.

Can’t find what you’re looking for?