Jump to content

Calling USBCR.dll to open a cash drawer


Recommended Posts

Hi,

A friend of my has purchased a second-hand cash drawer to use at point-of-sale. The till works fine, but at the moment he is unable to configure his POS software to open the till for a sale, after doing some searching on the Net we have found that there is a DLL that can be used for this purpose.

The DLL is part of an archive that can be downloaded here

The readme for the DLL

*********************************************************************

* *

* Posiflex USB CashDrawer Series USB CR DLL v1.03 Programming Guide *

* *

*********************************************************************

The driver required to control the Posiflex USB Cash Drawer

is called "USBCR.DLL". When the Posiflex USB Cash Drawer Test

Program is installed, this driver is stored in folder

"C:\Windows\System" if the default Windows folder is

"C:\Windows". Please preserve this file "USBCR.DLL" in the

system folder for your software to control the Posiflex USB

Cash Drawer even if you want to uninstall the Posiflex test

program.

The driver "USBCR.DLL" provides 7 function calls:

The 1--5 functions are for USB CashDrawer series to use.

The 6--7 functions are for USB CashDrawer series to use.

The examples of Visual Basic are list below.

1. Public Declare Function OpenUSBcr LIB "usbcr.dll" () As Long

=========

' must be called before calling other functions

' return 0 on success

2. Public Declare Function CloseUSBcr Lib "usbcr.dll" () As Long

==========

' call this function before exiting your program

' return 0 on success

3. Public Declare Function DrawerOpen Lib "usbcr.dll" (ByVal ID As Long) As Long

==========

' return 0 on sending commands successfully, -1 on error

' 'ID' is the drawer number from 0 to 7

4. Public Declare Function DrawerState Lib "usbcr.dll" (ByVal ID As Long) As Long

===========

' return the drawer status

' high nibble is the drawer ID, and

' low nibble is 0 if drawer is open, 1 if drawer is closed

' return -1 on error

5. Public Declare Function RetrieveStatistics Lib "usbcr.dll" (ByVal ID As Long, ByVal idx As Long, ByRef buf As Any, ByVal size As Long) As Long

==================

' return 0 on sending commands successfully, -1 on error

' 'size' is the number of bytes which can be held by 'buf'

' 'buf' will hold the value read from memory in cash drawer

' This function used to Retrieve the device statistics of Unified POS1.8.

6. Public Declare Function OpenUSB Lib "usbcr.dll" () As Long

=======

' must be called before calling other functions

' return 0 on success

' This function is for USB CashDrawer Series to use,

' and it can drive too.

7. Public Declare Function CloseUSB Lib "usbcr.dll" () As Long

========

' call this function before exiting your program

' return 0 on success

' This function is for USB CashDrawer Series to use.

' and it can drive USB CashDrawer too.

Note : For C++ programs: use __stdcall compiler option

Can someone convert a couple of these calls into DLLCall syntax so that I have a starting point to create a script that his POS program can call to open the cash drawer.

Thanks

VW

Link to comment
Share on other sites

Those definitions really didn't look very advanced. You should be able to implement them yourself easily just with the aid of the help file.

But since I'm such a nice guy I do the first one for ya'

$usbcr=DllOpen("usbcr.dll")
$call=DllCall($usbcr,"long","OpenUSBcr")
If @error Or $call[0]<>0 Then
  ConsoleWrite("Fail."&@CRLF)
Else
  ConsoleWrite("Success."&@CRLF)
Endif

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

@monoceres

Thanks for the direction.

$call[0]

Returns -2

Any idea why this might be?

VW

Since the small info you posted said 0 is success I assume it is some sort of error code. You have to check the documentation for the library to see what error it is.

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

I don't know, what -2 is. But you could try and use OpenUSB instead of OpenUSBcr. The "guide" is a bit confusing... no further information in it and this should be a programming guide...

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

I don't know, what -2 is. But you could try and use OpenUSB instead of OpenUSBcr. The "guide" is a bit confusing... no further information in it and this should be a programming guide...

I tried OpenUSB instead and no joy.

I agree that the available information is limited, which makes the task difficult. In searching on the Net I see that other people have grappled with the same issue in the past with limited success.

At this stage I've advised my mate to contact the manufacturer to see whether they can supply an exe that will eject the drawer, that really would seem to be the simplest solution and you would think such a program ought to exist.

Failing that, a contact whom I can ask questions, or obtain better documentation on the DLL

I have not programmed with DLL's before. There must be tools available that allow you to see what procedures/functions the DLL supports - and I guess there must also be ways of looking even "deeper" into DLL to see the code and thus ascertain what values can be returned ... but that would involve a fair bit of effort ... particularly when I have no experience with this level of programming. So at worst hopefully my mate can obtain some decent documentation to reference instead.

Having seen that at different times other people have been looking for a program to eject the drawer, I am hopeful that I might yet be able to post an AutoIt script which others in the future might find when searching for a solution.

Thanks

VW

Link to comment
Share on other sites

Just some stuff I thought of which may help...

I take it is a USB draw? Is it like a virtual COM port? Is it possible to use COM to make it open? I also know some are hooked up to printers and when the printer gets the right code it opens the draw. But I don't think you have that setup from what it sounds like.

Good luck with working this DLL out... They don't want to make it easy do they?

Also, what is your current code?

Cheers,

Brett

Edited by BrettF
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...