|
Home > Archive > Programming with dBASE > December 2005 > Windows API
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Charles L. 2005-12-06, 1:23 pm |
| Hello,
I have a new cashdrawer that I have to make it work with my POS system.
The problem here is that I am weak programming Windows API. The vendor is providing the C language coding to control the cash drawer. Their coding is shown below. I've tried to figure out how to make this work under Dbase Plus, going into API tutorials
and all, but all I've managed to do was to make my head swim. I would be extremely appreciated if sombody can help me to make the following C coding work under DBASE plus. The thing is, I'm under a tight deadline, and I just don't have the time to grasp
the concept of using API. Thank you.
1) GetDrawerHandle - This function determines if the cash drawer has been added to the bus. If so it returns the valid handle to the controller, else it returns a 0.
ULONG GetDrawerHandle(BYTE
drawer_number)
example)
handle = GetDrawerHandle(0);
if (handle) drawer_online=TRUE;
else drawer_online = FALSE;
2) GetDrawerStatus - This function returns the state of the switch on the controller. You must give the function the handle to the cash drawer you are using. The function will return failure [0], drawer closed [1], or drawer open [2].
C Calling Structure;
int GetDrawerStatus(ULON
G device_handle);
example)
result = GetDrawerStatus(hand
le);
if (result==2) drawer_open = TRUE
else if(result==1) drawer_open = FALSE;
else drawer_online = FALSE;
3) OpenDrawer - This function opens the cash drawer. You must give the function the handle to the cash drawer you are using. The function will success drawer opened [2], drawer already opened [3], or failure [0].
C Calling Structure:
int OpenDrawer(ULONG device_handle);
example)
result = OpenDrawer(handle);
if (!result) drawer_online = 0
4) ReleaseHandle - This function will release the device handle. Call this function when your program is finished using the device.
C Calling Structure:
int ReleaseHandle(ULONG device_handle);
Example:
result = ReleaseHandle(handle
);
| |
| Marc VdB 2005-12-06, 8:24 pm |
| Hi Charles,
> I have a new cashdrawer that I have to make it work with my POS system.
I make the assumption, that you are using a 32bit Window version and dbase
7.xx or later...
If so, the functions you describe can all be used easily with dbase. None of
the parameters is of a problematic type.
First of all you have to externalize these functions : therefor it is
important to know where they are located. I suppose that you got a file that
contains these functions. Most of the time, this file has the dll ending,
but it could be anything else (exe,com or whatever)
If you are unsure about which file has to be used, you have to contact the
vendor.
As soon as you know the name of the file, you must make sure, that the file
is in scope (you could copy it to the windows folder or to the folder where
your programm is located) lets say, the name of the file is cashdraw.dll ,
then the next four lines should be inserted somewhere in your startup
procedure :
extern culong GetDrawerHandle(ccha
r) cashdraw // substitute the real
name of the file for cashdraw
extern cint GetDrawerStatus(chan
dle) cashdraw
extern cint OpenDrawer(chandle) cashdraw
extern cint ReleaseHandle(chandl
e) cashdraw
Note : - the names of the functions are case sensitive, so make sure to
spell them right
- i prefer the parameter-type chandle, which is nothing else than
an ulong, but makes the code more readable
From here you are set. You can use the functions as if they were dBase build
in functions f.i
form.cdh = getdrawerhandle(0) // note, outside the extern, the functions
are not case sensitive, the parameter can be a value from 0 to 255, lookup
the help, to find out the meaning....
local status
status = getdrawerstatus(form
.cdh)
if status = 2
? "Drawer is open"
endif
status = opendrawer(form.cdh)
if status = 0
? "Sorry could not open the drawer"
endif
Releasehandle(form.cdh) // this frees the handle
>The thing is, I'm under a tight deadline, and I just don't have the time to
grasp the concept of using API. Thank you.
Hope it helps,
Marc
| |
| Bowen Moursund [DataTech] 2005-12-06, 8:24 pm |
| > 1) GetDrawerHandle - This function determines if the cash drawer has been
> added to the bus. If so it returns the valid handle to the controller,
> else it returns a 0.
>
> ULONG GetDrawerHandle(BYTE
drawer_number)
>
> example)
>
> handle = GetDrawerHandle(0);
> if (handle) drawer_online=TRUE;
> else drawer_online = FALSE;
You use the EXTERN command to prototype the external function. See the OLH
for details.
For example, if your vendor has supplied a DLL named CashDrawer.Dll:
#define DRAW_FAILURE 0
#define DRAW_CLOSED 1
#define DRAW_OPEN 2
#define DRAW_ALREADY_OPEN 3
oDrawer = new Drawer()
oDrawer.Init()
if oDrawer.IsOnline
if not oDrawer.OpenDrawer() >= DRAW_OPEN
msgbox( "Whatever" )
endif
endif
class Drawer // untested, of course
extern CULONG GetDrawerHandle( CUCHAR ) " C:\Wherever\CashDraw
er.Dll"
extern CINT GetDrawerStatus( CULONG ) " C:\Wherever\CashDraw
er.Dll"
extern CINT OpenDrawer( CULONG ) " C:\Wherever\CashDraw
er.Dll"
extern CINT ReleaseHandle( ULONG ) " C:\Wherever\CashDraw
er.Dll"
this.Init()
function Init
this.Handle = GetDrawerHandle( 0 )
this.IsOnline = ( this.Handle > 0 )
function OpenDrawer
if this.IsOnline
return OpenDrawer( this.Handle )
else
return 0
endif
function Release
ReleaseHandle( this.Handle )
endclass
--
Bowen Moursund
DataTech
Consulting & Development
http://www.bmmnet.us
| |
| Rick Miller 2005-12-06, 8:24 pm |
|
Well U got lots of help,
but since already had
this put together, might
as well post it.
Untested !!
Here is a quick class.
replace 3rdparty.dll in the
initializeExterns method
with the correct filename.
Hope it helps.
Rick Miller
Example:
// assuming drawer number is 0 based.
oCash = new cashDrawer()
? oCash.isDrawerOpen(0)
? oCash.isDrawerClosed(0)
? oCash.openDrawer(0)
oCash.release()
oCash := null
class cashDrawer
class::initializeExt
erns()
this.hwnd = 0
//------------------------------------------//
function getDrawerHwnd(nDrawe
r)
return GetDrawerHandle(int(
val("" + nDrawer)))
//------------------------------------------//
function initializeExterns
if not type("GetDrawerHandle") == "FP"
extern CULONG GetDrawerHandle(CCHA
R) ;
3rdparty.dll from "GetDrawerHandle"
endif
if not type("GetDrawerStatus") == "FP"
extern CINT GetDrawerStatus(CULO
NG) ;
3rdparty.dll from "GetDrawerStatus"
endif
if not type("OpenDrawer") == "FP"
extern CINT OpenDrawer(CULONG) ;
3rdparty.dll from "OpenDrawer"
endif
if not type("ReleaseHandle") == "FP"
extern CINT ReleaseHandle(CULONG
) ;
3rdparty.dll from "ReleaseHandle"
endif
return
//------------------------------------------//
// nDrawer = the drawer number.
// bHwnd = assign nHwnd to this.hwnd ?
function isDrawerClosed(nDraw
er, bHwnd)
Local bRet, nHwnd
bRet = false
nHwnd = this. GetDrawerHwnd(nDrawe
r)
if not nHwnd == 0
bRet := iif( ;
GetDrawerStatus(nHwn
d) == 1,;
true, false)
if bHwnd
this.hwnd := int(nHwnd)
else
class::ReleaseHwnd(n
Hwnd)
endif
endif
return iif(bRet, true, false)
//------------------------------------------//
// nDrawer = the drawer number.
// bHwnd = assign nHwnd to this.hwnd ?
function isDrawerOpen(nDrawer
, bHwnd)
Local bRet, nHwnd
bRet = false
nHwnd = class::GetDrawerHwnd
(nDrawer)
if not nHwnd == 0
bRet := iif( ;
GetDrawerStatus(nHwn
d) == 2,;
true, false)
if bHwnd
this.hwnd := int(nHwnd)
else
class::ReleaseHwnd(n
Hwnd)
endif
endif
return iif(bRet, true, false)
//------------------------------------------//
// nDrawer = the drawer number.
function openDrawer(nDrawer)
Local bRet, nHwnd
bRet = false
if this. isDrawerOpen(nDrawer
, false)
// already open.
bRet := true
elseif this. isDrawerClosed(nDraw
er, true)
OpenDrawer(nHwnd)
bRet := iif( ;
GetDrawerStatus(nHwn
d) == 2,;
true, false)
class::ReleaseHwnd(t
his.hwnd)
endif
return iif(bRet, true, false)
//------------------------------------------//
function release
try
release object this
catch(exception e)
endtry
return
//------------------------------------------//
function releaseHwnd(nHwnd)
if not nHwnd == 0
ReleaseHandle(nHwnd)
endif
return
endclass
| |
| David Stone 2005-12-07, 8:24 pm |
| Bowen, thought mebbe you had moved to Bolivia or something. Nice to see you're
still around...or back.
David
| |
| Bowen Moursund [DataTech] 2005-12-08, 8:23 pm |
| > Bowen, thought mebbe you had moved to Bolivia or something. Nice to see
> you're
> still around...or back.
Thanks! Maybe I'll visit more often <smile>.
--
Bowen Moursund
DataTech
Consulting & Development
http://www.bmmnet.us
|
|
|
|
|