1 2 Previous Next 18 Replies Latest reply on Jul 19, 2013 4:25 AM by jmw

    Calling a DLL from within a script



      Calling a DLL from within a script


           Hi all,

           I have Filemaker 12 Pro Advanced installed and need to port a MS Access invoicing application to Filemaker. When an invoice is printed, the application calls a DLL that opens a cash drawer and returns information about the status of the cash drawer (open/closed/error).

           How can this be achieved in Filemaker?

           When the DLL is called, a command is passed in a parameter and the DLL response is returned.

           Thank you for any help.

           Best regards


        • 1. Re: Calling a DLL from within a script


               I am not aware of any way to directly call a DLL from within FileMaker. What can be done however is create a FileMaker plugin that accesses the DLL.  The plugin creates additional script-functions (like possibly OpenDrawer and so on) which you can then simply include in your scripts getting the result also. I have done this a couple of times and have it incorporated in several solutions, works beautifully. 

               Creating a plugin requires programming experience however, preferably with interfacing DLLs. If you have that; there is FileMaker developer kit for plugins that should get you started. You would also need the DLL info, which you seem to have. 

               I seem to recall somebody mentioning that it can be done using Java code which was run in a ScriptMaster plugin to execute Java, but am not sure if this is even remotely correct.

               Have you contacted the drawer-manufacturer to see if there are alternative methods to the DLL?


               Jan Martin Wagenaar

          • 2. Re: Calling a DLL from within a script

                 Hi Jan Martin,


                 Thank you for your fast response. The manufacturer does not offer an alternative, unfortunately. What the DLL does, is a bit complicated I would guess, as it involves finding the correct port (the drawer is connected to a USB port and there is a "bridge' program, that emulates a serial port etc.) and communicating with that port.

                 The plugin idea looks promising. I need to dig into it a little deeper. However, it would have to handle the same stuff the DLL handles now, right?

                 I seem to remember, that there is a ascript step that calls an external program such as a C++ program, which then could call the DLL. Or was it an external function? I read this somewhere on the internet but can't find it.

                 It appears to me that the "Send Event" script step should do the trick and I wonder if anyone has ever used it and could give me some advice like whether and how results would be returned from the DLL and/or C++ program.

                 So the sequence would be: 

                 send event <C++ program>  --> 

                 C++ program calling DLL

                 DLL returning results to C++ program

                 C++ program returning results to FM

                 Thank you again very much for your input.

                 Best regards


            • 3. Re: Calling a DLL from within a script

                   Crikey, fumbling about to call a DLL which emulates a serial port over USB... smiley

                   What the plugin I was initially thinking about would do is just interface with the DLL, give it it's commands and get the result back. If the DLL takes care of finding the correct port, that remains identical. Otherwise you might need to give it the correct port through a command or something. How is this done in the current situation? 

                   Having said that, if you have the serial protocol (things like baud-rate, length, parity, commands and such) the Plugin could send these commands directly to the 'serial port'. This is what I do in interfacing a weighing-scale connected to a usb-to-serialport converter. I do not know but there might be standard plugins available to interface with a serial port. 

                   You can execute an external program using SendEvent (on both Mac and Windows). Getting results back from the program might be tricky though. Do you have an external program controlling the drawer, or are you thinking of writing one? 


                   Jan Martin

              • 4. Re: Calling a DLL from within a script
                Markus Schneider

                     depending on the hardware, it's possible to use the printer driver for the drawer. The current Epson's, Star's, can open the drawer using their printerdrivers

                • 5. Re: Calling a DLL from within a script


                       The cash drawer is a Jarltech device and it can't be operated other than the via the DLL (at least that's what the rather unresponsive support say). Would have been a nice solution though.

                       Jan Martin,

                       I know nothing about what the DLL intenally does and they don't tell me. But if I could get the plugin to pass the command to the DLL and get the result back, that would most probably do the trick. Currently a Powerbuilder solution calls the DLL and passes the "open/close/get status" commands to the DLL. It the retrieves the return code and acts accordingly. 

                       This sounds like a possibkle working solution and I now need to find out more about plugins and how to achieve the goal. Have you ever programmed a plugin?

                       Best regards



                       Here is the current PB scipt:


                                      Retunr-Codes: 0


                  long ll_rc
                                      integer li_rc, li_open=1, any la_rc


                  -1 = Connect Error
                                      -2 = Open port failed
                                      -3 = Open Cashdrawer failed -4 = Detect Cashdrawer failed -5 = Close failed

                  li_close=0, li_return_open, li_return_close

                  OleObject lole
                                      // Die Steuerbefehle für den CHOOSE CASE gi_cashdrawer

                  CASE 1 li_return_close = 40 li_return_open = 41 CASE 2 li_return_close = 50 li_return_open = 51

                  END CHOOSE

                  // Connect to OLE-Object and

                  Kassenmodul initialisieren

                  open Port

                  lole = Create OLEObject
                                      ll_rc = lole.ConnectToNewObject("My8005U.CMD") IF ll_rc < 0 THEN

                  li_rc = -1 // connect error GOTO exit_function

                  END IF
                                      //IF gb_cashdrawer_open THEN GOTO check_action

                  la_rc = lole.Close ll_rc = lole.OPEN_Auto IF ll_rc = 1111 THEN

                  li_rc = -2 // open port failed GOTO exit_destroy

                  END IF
                                      //gb_cashdrawer_open = TRUE //check_action:

                  CHOOSE CASE Lower(as_action) CASE 'open'

                                  GOTO open_cd
                          CASE 'status'

                  GOTO check_status CASE 'close'

                  GOTO close_port CASE ELSE

                  END CHOOSE

                  GOTO exit_function

                  ll_rc = lole.OPEN_CD(gi_cashdrawer) IF ll_rc = 1 THEN

                  END IF

                  li_rc = -3 // open cashdrawer failed GOTO close_port

                  Seite 1

                  GOTO close_port check_status:


                  la_rc = lole.DetectCD(gi_cashdrawer) ll_rc = Long(la_rc)
                                      IF ll_rc = 1 THEN

                  li_rc = -4 // detect cashdrawer failed ELSEIF ll_rc = li_return_open THEN

                  li_rc = li_open
                                      ELSEIF ll_rc = li_return_close THEN

                          li_rc = li_close

                  END IF
                                      GOTO close_port close_port:

                  la_rc = lole.Close
                                      //IF IsNull(la_rc) THEN la_rc = -5 //li_rc = integer(la_rc)

                  //gb_cashdrawer_open = FALSE exit_destroy:
                                      Destroy lole

                  RETURN li_rc 



                  • 6. Re: Calling a DLL from within a script


                         I had a look at the script and from that, am I correct in assuming that this is the Jarltech JP-8005U Cash Drawer Opener? I had a look at that one anyway and noticed that it seems to have both a DLL to control it (slightly different commands though then your script uses) but also seems to have a serial protocol with commands to send to the USB port. The documentation is somewhat vague on that. Anyway, if this is your device it seems you have several opions. Interfacing the DLL you have with the commands fom the script seems a logical choice, although I think I would play with the serial protocol as would eliminate the entire DLL route. 

                         Out of curiosity, is this a one time project? Commercial project? 

                         Yes, I have programmed several plugins, both on Mac and Windows platforms, also with interfaces to DLLs (which is why I am sure that it can be done, although there are pitfalls and no guarantees) as well as hardware interfaces like serial ports. 

                         Have you had a look at the FileMaker plugin stuff? If not, you can find it at http://www.filemaker.com/support/technologies/

                         It is a bit of a learning curve, but hey, no gain without pain as they say.... smiley


                         Jan Martin

                    • 7. Re: Calling a DLL from within a script

                           Jan Martin,

                           absolutely correct. Amazing.

                           Well, I have absolutely no clue, what that Dll does in terms of interfacing the USB or serial port. The documentation only states the commands to send for what purpose and the resutting response. That's why I thought the easiest option was to talk to the Dll in the same manner the PB application does.

                           Yes, it's a one time project. My son runs a tyre business and my brother has written the software for it in Powerbuilder. But I want to port it to FM, Hence the need to communicate with the Dll. 

                           On the PC where the PB application runs, I need to install a 'Prolific USB to Serial bridge' which creates a com port. Along with the hardware device they supplied the said Dll and a board, that is installed in the PC. From this board the 8005U device gets its 24V power to handle the drawer. 

                           Thanks for the link and for looking into the problem. I'll let you know how it goes. If I may I would come back to you if I have a question re. the plugin. And if you have any ideas I would very much appreciate your help.

                           Best Regards


                      • 8. Re: Calling a DLL from within a script

                             I have seen a rather expensive plugin offered by Troi Ametesring (sp?) that accesses a USB port...

                        • 9. Re: Calling a DLL from within a script

                               I seriously doubt that will be needed, especially at that price. The device uses a very simple protocol which can be easily achieved in a plugin. One of my own plugins does something similar for weighing scales on both Mac and Windows. 

                               So, having said that: Hans, the documentation (from the Jarltech supprt site: Ueser's guide for cash drawer opener) says that the drawer can be opened by sending any character other than 'escape' to the USB port. I'd say it is worth a try to see if that works by using a serial terminal to send a character to the USB virtual COM port (use the standard settings of 9600 baud, no parity, 8 bits, 1 stopbit). Just for fun. smiley

                               If that does work you can leave the DLL route and simply interface the serial port (like the Troi plugin does). It is not all that difficult and easier than inerfacing the DLL.

                               In any case; don't go spending money without contacting me privately, I can help you at substantial lower cost. 


                          • 10. Re: Calling a DLL from within a script

                                 Yes, I saw this plugin by Troi Ametesring, but it is way beyond my budget.  :-)

                                 Jan Martin,

                                 I looked at the plugin article yoiu proposed and downloaded all the components. However, looking into it scares me.It seems so complicated. 

                                 Actually they have a USB and a serial interface. So it may be worth considering the serial option. That would mean I don't need the Dll nor the Prolific interface. If I Knew how to send a character to the serial port in FM I would be prepared to invest in buying the corresponding interface.

                                 Plus, I need to get a response from the interface about 

                                 a) the success of an operation and 

                                 b) the status of the cash drawer

                                 What I need is a guide how to do the thing in FM.

                                 How would I contact you privately?

                                 Thanks to all so far for your kind contributions. I'll keep you posted about the (hopefully) success.  

                                 Best regards



                            • 11. Re: Calling a DLL from within a script

                                   Hans, you already have the software components installed, no need to do anything like that again. 

                                   I am a bit puzzled by you saying it has both a USB and a serial option... do you mean the cash drawer itself? The Jarltech has only USB as I understand... To control it, the Prolific interface creates a virtual COM port (which you should have on your system), so with a little luck sending a character using f.e. HyperTerminal to that COM port should open the drawer. The thing is that if that works we know you can access the device using a serial interface. Those are fairly standard programming techniques, including getting replies back from the COM port. All this can be done in a plugin (and has been done), giving you script commands to send data to the COM port and receive from it. If you are familiar with programming in C++ you can have a look at doing it yourself as I mentioned earlier (the Plugin SDK). If not, you should get a third-party plugin, or contact me. 

                                   For starters, see if you can send a character to the COM port, f.e. using HyperTerminal. 

                                   You can leave me a message on this board by clicking on my name, there you will find an option to leave a message. 


                              • 12. Re: Calling a DLL from within a script

                                     A different cash drawer company has software for it's USB drawer for Filemaker

                                FileMaker  -  maybe Mac only...

                                     The „FileMaker..." folder contains examples for FileMaker, which are based on AppleScript.

                                     „Service USB Filemaker single" contains simple examples for operating one Service USB.

                                     „Service USB Filemaker multiple" contains more complex examples, which are designed for the use of several Service USBs connected at the same time.


                                • 13. Re: Calling a DLL from within a script

                                       Jan Martin,

                                       what I meant was, that they sell an USB opener device 8005U and a serial port opener device 8005-1.

                                       I will give it a try with Hyperterminal and see what happens.


                                       I will read the documenatation you pointed me to and see whether it can be used in a Windows environment.

                                       Meanwhile I want to thank you all for your continued efforts.

                                       I'll keep you posted.

                                       Best regards


                                  • 14. Re: Calling a DLL from within a script

                                         just curious Hans, any news on the frontlines?


                                         Jan Martin

                                    1 2 Previous Next