by cdmmaui » Sun Sep 09, 2007 11:19 am
Hello,
I found the following code on this forum and got the scan button to work. However, the function is only returning the first character of the barcode. Can anyone help?
#include "FWCE.ch"
#include "hbclass.ch"
#include "Directry.ch"
//----------------------------------------------------------------------------//
function Main()
local oDlg , ;
aGet1, aGet2, aGet3 , ;
cTitle := 'CDM WinWMS - Receipts' , ;
cBuild := 'Build 20070909-0109' , ;
cWmsdata := '' , ;
cOwner := SPACE(10) , ;
cPo := SPACE(30) , ;
cSku := SPACE(50) , ;
nQty := 0 , ;
cUnitId := SerialNumber()
// Database init...
REQUEST DBFCDX
REQUEST DBFFPT
RddSetDefault ('DBFCDX')
// Check connection...
IF ! FILE( "client.dbf")
DbCreate( "client.dbf", { { "data", "C", 50, 0 } } )
ENDIF
pfad := '\'
cDb := 'client'
USE (pfad+cDb) NEW SHARED
IF NETERR()
MsgAlert( 'Unable to open ' + pfad + cDb, cTitle )
RETURN (.F.)
ENDIF
IF client->( reccount() ) < 1
APPEND BLANK
ENDIF
GO TOP
cWmsData := ALLTRIM( client->data )
client->( dbclosearea() )
// Data Folder...
DO WHILE (.T.)
IF FILE(cWmsdata + "wmsdet.dbf")
EXIT
ELSE
cTmp = LEFT( cWmsdata + SPACE(50), 50)
// Window Get...
lPass := MsgGet( cTitle, "Folder Name", @cTmp )
IF ! lPass
RETURN (.F.)
ENDIF
// Init...
cWmsdata = ALLTRIM(cTmp)
IF RIGHT(cWmsdata,1)<>"\"
cWmsdata += "\"
ENDIF
// Update...
pfad := '\'
cDb := 'client'
USE (pfad+cDb) NEW SHARED
IF NETERR()
MsgAlert( 'Unable to open ' + pfad + cDb, cTitle )
RETURN (.F.)
ENDIF
GO TOP
DO WHILE (.T.)
IF client->( dbrlock() )
client->data := ALLTRIM( cWmsdata )
client->( dbrunlock() )
EXIT
ENDIF
ENDDO
client->( dbclosearea() )
ENDIF
ENDDO
DEFINE DIALOG oDlg TITLE cTitle ;
SIZE 300, 300 COLOR "W/B+"
@ 0.7, 01 SAY "Owner" SIZE 20, 10
@ 1.0, 05 GET aGet1 VAR cOwner SIZE 50, 10 PICTURE "@!" VALID CheckScan( @aGet1, @cOwner )
@ 1.7, 01 SAY "P.O. No." SIZE 25, 10
@ 2.0, 05 GET aGet2 VAR cPo SIZE 99, 10 PICTURE "@!" VALID CheckScan( @aGet2, @cPo )
@ 2.5, 01 SAY "SKU" SIZE 15, 10
@ 3.0, 05 GET aGet3 VAR cSku SIZE 99, 10 PICTURE "@!" VALID CheckScan( @aGet3, @cSku )
@ 3.5, 01 SAY "Qty" SIZE 10, 10
@ 4.0, 05 GET nQty SIZE 25, 10 PICTURE "999999"
@ 6.0, 01 BUTTON "Save" ACTION oDlg:End() SIZE 30, 10
@ 6.0, 10 BUTTON "Cancel" ACTION oDlg:End() SIZE 30, 10
@ 6.0, 19 BUTTON "New" ACTION oDlg:End() SIZE 30, 10
@ 8.0, 01 SAY cBuild SIZE 99, 10
ACTIVATE DIALOG oDlg CENTERED ;
VALID MsgYesNo( "Exit", cTitle )
return nil
//-----------------------------------------------------------------------------
FUNCTION CheckScan( oGet, cData )
LOCAL cRet , lReturn := .f., nLen := LEN( cData )
IF oGet:nLastKey = 13
cRet := SCAN_OPEN()
MsgInfo( cRet )
IF VALTYPE( cRet ) = 'C'
cData := LEFT( cRet + SPACE(nLen), nLen )
lReturn := .T.
ENDIF
ENDIF
oGet:Refresh()
RETURN (.T.)
//-----------------------------------------------------------------------------
FUNCTION cesetmenu() ; RETURN NIL
FUNCTION getmenu() ; RETURN NIL
FUNCTION readbitmap() ; RETURN NIL
FUNCTION palbmpread() ; RETURN NIL
#pragma BEGINDUMP
#pragma comment (lib,"scnapi32")
#include <hbapi.h>
#include <windows.h>
#include "Scancapi.h"
LPSCAN_BUFFER lpScanBuffer = NULL;
BOOL bUseText = TRUE;
DWORD dwScanSize = 7095;
DWORD dwScanTimeout = 0;
#define BUFFER_SIZE 7095
#define DEFAULT_TIMEOUT 10000
HANDLE hScanner = NULL;
TCHAR szScannerName[MAX_PATH] = TEXT("SCN1:");
DWORD dwResult ;
CHAR Buffer ;
UINT uMsg ;
DWORD dwTimeout ;
HB_FUNC( SCAN_OPEN )
{
dwResult = SCAN_Open( szScannerName, &hScanner );
if ( dwResult == E_SCN_SUCCESS )
{
dwResult = SCAN_Enable( hScanner );
if ( dwResult == E_SCN_SUCCESS )
{
BOOL state = TRUE;
dwResult = SCAN_SetSoftTrigger(hScanner, &state);
if (dwResult == E_SCN_SUCCESS) {
// allocate a new scan buffer
lpScanBuffer = SCAN_AllocateBuffer(TRUE /* data as chars */, BUFFER_SIZE);
if (lpScanBuffer) {
dwResult = SCAN_ReadLabelWait(hScanner, lpScanBuffer, DEFAULT_TIMEOUT);
if (dwResult == E_SCN_SUCCESS)
{
hb_retclen( (char *)SCNBUF_GETDATA(lpScanBuffer),25);
}
}
SCAN_DeallocateBuffer(lpScanBuffer);
}
state = FALSE;
SCAN_SetSoftTrigger(hScanner, &state);
}
else
{
MessageBox( GetActiveWindow(), L"Error en SCAN_Enable", L"Ok", 0 );
}
}
else
{
MessageBox( GetActiveWindow(), L"Error en SCAN_Open", L"Ok", 0 );
}
}
#pragma ENDDUMP