Announcement

Collapse
No announcement yet.

Need Some help with VB Dll to PB

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need Some help with VB Dll to PB

    Would someone out there be kind enough to lend some help translating some VB funtions to PB. I'm brand new to PB and am having a little difficulty with some functions to comunicate with a line scan camera.

    When I run my attached LC1Cam.bas fle I get a Windows message "cannot find entry point" in the "LC1_DRV_32.DLL". I believe this is caused from not recieving the serial number correctly.
    The camera runs with a supplied C++ program (I do have the source codeif needed) and also runs fine with a program I wrote in Liberty Basic. I have been fighting this problem all week (since I purchase PB) so if someone could take some time to help me, I would be very appreciative.


    The only functions I need are as follows:
    1) Declare Function LC1_init& Lib "LC1_Drv_32.dll" ( ByVal x1$, ByVal x2&, x3&)
    This sends a ID string Serial Number to the camera as x1$, a timeout variable x2# between 1000 to 6000 ms, and retrives a unique insrument handle for the session. This handle is used in all other funtions.
    ID string$ = "USB0::0x1313::0x0110::S/N M00226832::RAW"

    2) Declare Function LC1_close& Lib "LC1_Drv_32.dll" ( ByVal x1&)
    Sends the instrument handle above and closes out camera.

    3) Declare Function LC1_setIntTime& Lib "LC1_Drv_32.dll" ( ByVal x1&, ByVal x2#)
    This sends instrument handle , and then the exposure time between 0.001 to 0.200 seconds.

    3) Declare Function LC1_getIntTime& Lib "LC1_Drv_32.dll" ( ByVal x1&, x2#)
    This sends instrument handle , and gets the exposure time back from the camera as 0.001 to 0.2 seconds

    4) Declare Function LC1_startScan& Lib "LC1_Drv_32.dll" ( ByVal x1&)
    This sends instrument handle and when recieved starts a camera line scan

    5) Declare Function LC1_getScanData& Lib "LC1_Drv_32.dll" ( ByVal x1&, x2#)
    This sends instrument handle, then (I'm not sure how but) I believe sends back the address of an array with (3000) pixels of data.

    The LC1Cam.bas file is my feeble attemp.
    The next 2 are manufacture supplied VB information files
    Finally, the .zip file contain the .dll and a win32 type .hlp file which gives a detailed description of each command.

    Thanks so much in advance,
    Mike
    Attached Files

  • #2
    Mike,

    Just some ideas:

    Dll "LC1_DRV_32.DLL" seems to depend on (among a few others) on a dll called "INSTRSUP.DLL". It is not on my pc. Is it located somewhere on your pc where your application can find it? Don't know if that is the reason of your problem though.

    Code:
    DECLARE FUNCTION LC1_getIntTime& LIB "LC1_Drv_32.dll" (BYVAL x3???, x2#) AS LONG
    Kind regards
    Last edited by Eddy Van Esch; 15 Nov 2009, 08:14 AM.
    Eddy

    Comment


    • #3
      to answer Eddy back on the VB calls

      Eddy,
      Yes, the "INSTRSUP.DLL" was in my windows/system32 folder so I have attached it in the zip. I tried placed, in the zip, a copy of the Thorlabs installation setup software but it was to large. So I will place the link to this software at the bottom of the reply if needed.This setup also runs off of National Instruments NVisa engine which installs with the Thorlabs driver.
      The setup for Thorlabs contains a working C++ example with source code.
      All of this should uninstall easilly when not needed any longer.
      Thanks, I hope this helps.
      Mike
      Thorlabs and NI visa engine. No keys are required. and the software should function up to the point where the software will advise you to plug in a camera.
      http://www.thorlabs.com/software_pag...m?Code=LC1-USB
      Attached Files

      Comment


      • #4
        When I run my attached LC1Cam.bas fle I get a Windows message "cannot find entry point" in the "LC1_DRV_32.DLL". I believe this is caused from not recieving the serial number correctly.
        No. Your problem is that these declares may be appropriate for VB but not for PB. In the first place, they lack the ALIAS clause; and for correctly ascertain how to translate the parameters, it would be much better if you posted the original C header instead of that messy VB translation.
        Forum: http://www.jose.it-berater.org/smfforum/index.php

        Comment


        • #5
          Just looking at the function LC1_init you have x2 defined as a double when the VB prototype is a long
          x3 you define as a dword instead of a long but this should be OK
          More importantly you have to understand passing strings from VB to C or PB. Strings in VB are Unicode and BYVAL String is a kludge that actually sends a BYREF ASCIIZ to the driver DLL
          So LC1_init should look like this in PB
          DECLARE FUNCTION LC1_init LIB "LC1_Drv_32.dll" (x1 as ASCIIZ, BYVAL x2 as LONG, x3???) AS LONG
          OOPs slight error there that is what the receiving end expects, the sending end in PB should be
          DECLARE FUNCTION LC1_init LIB "LC1_Drv_32.dll" (BYVAL x1 as String BYVAL x2 as LONG, x3???) AS LONG
          Last edited by John Petty; 15 Nov 2009, 11:01 AM.

          Comment


          • #6
            Originally posted by José Roca View Post
            No. Your problem is that these declares may be appropriate for VB but not for PB. In the first place, they lack the ALIAS clause; and for correctly ascertain how to translate the parameters, it would be much better if you posted the original C header instead of that messy VB translation.
            OP doesnt say at what stage he gets that error. I checked the case of the LC1_init with dependacy walker so an ALIAS should not be needed.

            Comment


            • #7
              now posting the C++ files as requested

              Guys,
              I tried the revised declares and it still compiles fine but I'm still getting the "entry point not found" windows error. I am now posting the C++ code as requested by Jose. The zip has the souce, headers etc.
              Thanks again,
              Mike
              Attached Files

              Comment


              • #8
                You have posted the code for a C++ example, but it doesn't contain the header of the DLL, LC1_Drv.h.
                Forum: http://www.jose.it-berater.org/smfforum/index.php

                Comment


                • #9
                  John,
                  I recieve the error message after the compiler finishes and before the debbuger really has a chance to start up. It is a pop-up generated by windows and not PB I think. I reads as follows Caption = "LC1cam.exe - Entry point not found"
                  Then the notice body says "The procedure Entry point LC1_INIT could not be located in the dynamic link library LC1_DRV_32.DLL."
                  The LC1_DRV_32.DLL is up to date and does work with the C++ code in this attachment and does work with the code I wrote in Liberty Basic which is a simpler basic language. The Liberty basic compiler is too slow to run this project which is why I'm trying to rewrite in PB.
                  Thanks again,
                  Mike Gorden

                  Comment


                  • #10
                    The ALIAS clause is needed with PB. Otherwise, the program will look for "LC1_INIT" (capitalized) instead of "LC1_init", and will not find it.

                    Code:
                    DECLARE FUNCTION LC1_init LIB "LC1_Drv_32.dll" ALIAS "LC1_init" (BYREF x1 AS ASCIIZ, BYVAL x2 AS LONG, BYREF x3 AS LONG) AS LONG
                    Last edited by José Roca; 15 Nov 2009, 11:48 AM.
                    Forum: http://www.jose.it-berater.org/smfforum/index.php

                    Comment


                    • #11
                      A possibly stupid question but where is LC1_DRV_32.DLL located on your hard disk. You are not doing a specific load, so is it in the normal serach path?

                      Comment


                      • #12
                        WinAPI SearchPath()

                        But if you can get it running using VB, I think this could be really handy...
                        Show Loaded Modules Source and Executable package for PB and VB
                        Visual Basic include files/demo code by Balthasar Indermuehle. (PB code by YT.)
                        Michael Mattias
                        Tal Systems Inc. (retired)
                        Racine WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          From PB's help file:

                          The ALIAS clause is very important when importing or exporting Subs and Functions from DLLs. Omitting the ALIAS clause or incorrectly capitalizing the alias name are common causes of DLL load failure problems. Please refer to the SUB and FUNCTION sections for more information.
                          Forum: http://www.jose.it-berater.org/smfforum/index.php

                          Comment


                          • #14
                            Originally posted by José Roca View Post
                            The ALIAS clause is needed with PB. Otherwise, the program will look for "LC1_INIT" (capitalized) instead of "LC1_init", and will not find it.

                            Code:
                            DECLARE FUNCTION LC1_init LIB "LC1_Drv_32.dll" ALIAS "LC1_init" (BYREF x1 AS ASCIIZ, BYVAL x2 AS LONG, BYREF x3 AS LONG) AS LONG
                            Apologies I knew PB automatically capitilised an exported function but was not aware that it did the same when it was calling a function which I find strange as you can add an alias to the exported function in mixed case.

                            Comment


                            • #15
                              LC1_Drv.h file as requested

                              Jose John and Michael,
                              I added the file above into the zip.
                              I added Johns code line and then compiled... still get the windows message "could not find entry point"
                              I added jose's code line and got it to compile, still the same WINDOWS error "could not find entry point" &HC0000139
                              The supplier "Thorlabs" did not supply any VB code other than the declare function file.
                              Mike
                              Attached Files

                              Comment


                              • #16
                                I added jose's code line and got it to compile, still the same WINDOWS error "could not find entry point" &HC0000139
                                Of course. It is not enough to translate just one function, but all of them. Give me some time to look at the C++ header.
                                Forum: http://www.jose.it-berater.org/smfforum/index.php

                                Comment


                                • #17
                                  To John Petty

                                  The Library is in Windows\system32\ however I did try placing them into the PBWIN90 dir which currently is located in the PB sample dir. All with same error message.
                                  Mike

                                  Comment


                                  • #18
                                    Can you check if the DLL is being found?
                                    In PBMAIN put
                                    er& = Loadlibrary("LC1_Drv_32.dll")
                                    if er& = 0 then
                                    ?"DLL not found"
                                    exit function
                                    end if

                                    Comment


                                    • #19
                                      There are still at least two C++ headers missing in your post, vpptype.h and cvidef.h, so I have needed to make some guesses in this quick translation:

                                      Code:
                                      ' // Init - Close
                                      'ViStatus _VI_FUNC LC1_init (ViRsrc rsc, ViInt32 tmo, ViPSession instrp);
                                      DECLARE FUNCTION LC1_init LIB "LC1_Drv_32.dll" ALIAS "LC1_init" (BYREF rsc AS ASCIIZ, BYVAL tmo AS LONG, BYREF instrp AS DWORD) AS LONG
                                      
                                      'ViStatus _VI_FUNC LC1_close (ViSession instrument);
                                      DECLARE FUNCTION LC1_close LIB "LC1_Drv_32.dll" ALIAS "LC1_close" (BYVAL instrument AS DWORD) AS LONG
                                      
                                      '// Configuration functions
                                      'ViStatus _VI_FUNC LC1_setIntTime (ViSession instr, ViReal64 time);
                                      DECLARE FUNCTION LC1_setIntTime LIB "LC1_Drv_32.dll" ALIAS "LC1_setIntTime" (BYVAL instr AS DWORD, BYVAL time AS DOUBLE) AS LONG
                                      
                                      'ViStatus _VI_FUNC LC1_getIntTime (ViSession instr, ViPReal64 time);
                                      DECLARE FUNCTION LC1_getIntTime LIB "LC1_Drv_32.dll" ALIAS "LC1_getIntTime" (BYVAL instr AS DWORD, BYREF time AS DOUBLE) AS LONG
                                      
                                      '// Action/Status functions
                                      'ViStatus _VI_FUNC LC1_startScan (ViSession instr);
                                      DECLARE FUNCTION LC1_startScan LIB "LC1_Drv_32.dll" ALIAS "LC1_startScan" (BYVAL instr AS DWORD) AS LONG
                                      
                                      'ViStatus _VI_FUNC LC1_startScanExtTrg (ViSession instr);
                                      DECLARE FUNCTION LC1_startScanExtTrg LIB "LC1_Drv_32.dll" ALIAS "LC1_startScanExtTrg" (BYVAL instr AS DWORD) AS LONG
                                      
                                      'ViStatus _VI_FUNC LC1_startScanCont (ViSession instr);
                                      DECLARE FUNCTION LC1_startScanCont LIB "LC1_Drv_32.dll" ALIAS "LC1_startScanCont" (BYVAL instr AS DWORD) AS LONG
                                      
                                      'ViStatus _VI_FUNC LC1_startScanContExtTrg (ViSession instr);
                                      DECLARE FUNCTION LC1_startScanContExtTrg LIB "LC1_Drv_32.dll" ALIAS "LC1_startScanContExtTrg" (BYVAL instr AS DWORD) AS LONG
                                      
                                      'ViStatus _VI_FUNC LC1_getDeviceStatus (ViSession instr, ViPUInt8 deviceStatusByte);
                                      DECLARE FUNCTION LC1_getDeviceStatus LIB "LC1_Drv_32.dll" ALIAS "LC1_getDeviceStatus" (BYVAL instr AS DWORD, BYREF deviceStatusByte AS BYTE) AS LONG
                                      
                                      '// Data functions
                                      'ViStatus _VI_FUNC LC1_getScanData (ViSession instr, ViReal64 _VI_FAR scanDataArray[]);
                                      DECLARE FUNCTION LC1_getScanData LIB "LC1_Drv_32.dll" ALIAS "LC1_getScanData" (BYVAL instr AS DWORD, BYREF scanDataArray AS DOUBLE) AS LONG
                                      
                                      'ViStatus _VI_FUNC LC1_getRawScanData (ViSession instr, ViUInt16 _VI_FAR scanDataRawArray[]);
                                      DECLARE FUNCTION LC1_getRawScanData LIB "LC1_Drv_32.dll" ALIAS "LC1_getRawScanData" (BYVAL instr AS DWORD, BYREF scanDataRawArray AS WORD) AS LONG
                                      
                                      '// Utility functions
                                      'ViStatus _VI_FUNC LC1_reset (ViSession instr);
                                      DECLARE FUNCTION LC1_reset LIB "LC1_Drv_32.dll" ALIAS "LC1_reset" (BYVAL instr AS DWORD) AS LONG
                                      
                                      'ViStatus _VI_FUNC LC1_errorMessage (ViSession instr, ViStatus status, ViChar _VI_FAR message[]);
                                      DECLARE FUNCTION LC1_errorMessage LIB "LC1_Drv_32.dll" ALIAS "LC1_errorMessage" (BYVAL instr AS DWORD, BYVAL status AS LONG, BYREF message AS ASCIIZ) AS LONG
                                      
                                      'ViStatus _VI_FUNC LC1_identificationQuery (ViSession instr, ViChar _VI_FAR manufacturerName[], ViChar _VI_FAR instrumentName[], ViChar _VI_FAR instrumentSerialNumber[], ViChar _VI_FAR firmwareRevision[]);
                                      DECLARE FUNCTION LC1_identificationQuery LIB "LC1_Drv_32.dll" ALIAS "LC1_identificationQuery" (BYVAL instr AS DWORD, BYREF manufacturerName AS ASCIIZ, _
                                         BYREF instrumentName AS ASCIIZ, BYREF instrumentSerialNumber AS ASCIIZ, BYREF firmwareRevision AS ASCIIZ) AS LONG
                                      
                                      'ViStatus _VI_FUNC LC1_revisionQuery (ViSession instr, ViChar _VI_FAR instrumentDriverRevision[], _VI_FAR ViChar firmwareRevision[]);
                                      DECLARE FUNCTION LC1_revisionQuery LIB "LC1_Drv_32.dll" ALIAS "LC1_revisionQuery" (BYVAL instr AS DWORD, BYREF instrumentDriverRevision AS ASCIIZ, BYREF firmwareRevision AS ASCIIZ) AS LONG
                                      
                                      'ViStatus _VI_FUNC LC1_setUserText (ViSession instr, ViChar _VI_FAR userText[]);
                                      DECLARE FUNCTION LC1_setUserText LIB "LC1_Drv_32.dll" ALIAS "LC1_setUserText" (BYVAL instr AS DWORD, BYREF userText AS ASCIIZ) AS LONG
                                      
                                      'ViStatus _VI_FUNC LC1_getUserText (ViSession instr, ViChar _VI_FAR userText[]);
                                      DECLARE FUNCTION LC1_getUserText LIB "LC1_Drv_32.dll" ALIAS "LC1_getUserText" (BYVAL instr AS DWORD, BYREF userText AS ASCIIZ) AS LONG
                                      Forum: http://www.jose.it-berater.org/smfforum/index.php

                                      Comment


                                      • #20
                                        To Jose, John and Michael

                                        Thanks,
                                        For all of your effort, I will keep pluging away at it here too.
                                        I wish I knew more about PB. It is far more complicated then the languages I have been involved with so far. Back when I graduated in Chemistry, about a hundred years ago, I never figured I would be into this stuff. And I have to get through it to get to where I need to go. I'm glad you guys are here to help. The current product is 100,000 lines of code and works well. But this new product, which adds on to the old product, will be about 20,000 lines when finished as a separate executable. I have 3 units sold and I do have it written and working in Liberty Basic but I only get one scan every 3 seconds. I need about 25 to 60 scans per second so that's why I'm switching to PB. The Liberty Basic compiler is an interperted, tokenized type and is very much slower than VB by about 200 times... so they say. Also the code is written as procedural and not event driven, so quite a challenge ahead.
                                        So thanks again for all of your help.

                                        Mike

                                        Comment

                                        Working...
                                        X