Using the Scanner SDK for windows with Delphi

T Tim Mills 3 years 7 months ago
449 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);
var
  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;
begin
  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;

  try

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

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

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

  try

    CCoreScanner1.GetScanners(numberOfScanners,conectedScannerIDList,outXML,status);
  finally
    if Status0
      then
        begin
          ShowMessage('CoreScanner API Error:'+IntToStr(status));
        end;
  end;

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

  CCoreScanner1.Close(0,status);
end;

I hope this helps other developers out there.

CONTACT
Can’t find what you’re looking for?