Announcement

Collapse
No announcement yet.

Need Some help with VB Dll to PB

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

  • #21
    This code doesn't make much sense:

    Code:
    '  --- Initializes Camera -----
    FUNCTION LC1SetInitialize (camcommandstring$, CamTIMEOUT#, LC1Handle???) AS LONG
        CamTIMEOUT# = 4000
        DIM x10 AS INTEGER PTR  'camcommandstring$
        camcommandstring$ = "USB0::0x1313::0x0110::S/N M00226832::RAW"
        x10% = STRPTR(camcommandstring$)     '"USB0::0x1313::0x0110::S/N M00226832::RAW"
        'Message$ = camcommandstring$    ' returns vaiable string$
        'Message$ = @x$    ' returns variable string$  as the target of x
        x1$ = camcommandstring$
        x2# = camTIMEOUT#   'time out ms
        LC1_init (BYVAL x1$, BYVAL x2#, x3???) TO result_var# 'as long
        LC1Handle??? = x3???
        result_var# = x4#
    END FUNCTION
    Try instead:

    Code:
    DIM lStatus AS LONG
    DIM LC1Handle AS DWORD
    lStatus = LC1_init ("USB0::0x1313::0x0110::S/N M00226832::RAW", 4000, LC1Handle)
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #22
      Mike
      Sorry I can't be of more help it is now 3:30am for me so I need some sleep. I have done many VB to PB declare conversions (not a C man) and have found them simple so am surprised. Only final suggestion I can make is to put a message box after every DLL call something like
      ? "call to xyz succeded"
      so you can find which one is failing.
      Good luck

      Comment


      • #23
        Jose, - cvidef.h,

        I can not find this file. Could it be the sample.h as the C++ executable is named sample.exe. I did add the other file you requested in the attachment.

        I will try the code sent in your last post now and get back.
        Mike
        Attached Files

        Comment


        • #24
          Thanks John and good night

          You keep my hours as well. I work until I drop also. It seems apparent that we scientific types are all the same. Thanks again,
          Mike

          Originally posted by John Petty View Post
          Mike
          Sorry I can't be of more help it is now 3:30am for me so I need some sleep. I have done many VB to PB declare conversions (not a C man) and have found them simple so am surprised. Only final suggestion I can make is to put a message box after every DLL call something like
          ? "call to xyz succeded"
          so you can find which one is failing.
          Good luck

          Comment


          • #25
            Jose, Michael, John

            It will take me a couple of hours to implement all of your ideas and get the code to compile without error, so let me play with all of it and I will give an update when I have implemented all of your suggestions.
            Thanks so much to all.
            Mike Gorden

            Comment


            • #26
              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.
              Mike, you don't say whether you are converting to PBWin (9.x) or PBCC. Converting to PBWin first time out will likely prove to be a daunting challenge. Far less so to PBCC. (Presuming Liberty Basic is DOS based.)

              If to PBWin, likely your best bet is to convert from LB to PBCC (a likely relatively easy transition), then from PBCC to PBWin.

              ======================================
              Politics, n.
              Interests masquerading as principles.
              Ambrose Bierce (1842-1914)
              ======================================
              Last edited by Gösta H. Lovgren-2; 15 Nov 2009, 08:43 PM.
              It's a pretty day. I hope you enjoy it.

              Gösta

              JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
              LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

              Comment


              • #27
                for Gosta Lovgren

                Gosta,
                Liberty basic is a very easy to use 32 bit windows only program. There are still some fuzzy dos items remaining in it if you declare to use this option but not many people use that any longer and the next release will drop the remaining dos features. It is a tokenized interpreted compliler (they deny this claim) but requires a runtime engine and a .tkn compiled code file to run and several .dll files. It is extreamly slow for my current application, however, I have never found anything it could not do as it is very easy to access all of the windows API as well as private DLL. I would expect a 100 times increase in speed with this PBwin software.
                I purchased POWER BASIC PBWIN 9 compiler last week as well as the graphics and forms package. The forms designer for PB is virtually the same as LB and very easy to use. And really PBWIN doesn't seem too difficult except for the variable declarations. Writing in event driven programming is also a little different compared to the mostly procedural code I used by choice with the libery basic. Overall though I wish I had started years ago with Power basic as I think the Approch is much better.
                So to answer your question; yes, I have been writing code for the last five years in 32 bit windows software but with software that figures everything out for you, so I havn't learned some things about prograamming that this software will force me to learn. After a long learning curve, and expected fustration, I am sure that I will be glad I didn't throw the laptop out the window into trafic... Optimistically looking forward to the challenge.
                Mike Gorden

                Comment


                • #28
                  variable declaration question

                  Here is the declaration: (by Jose Roca)
                  DECLARE FUNCTION LC1_init LIB "LC1_Drv_32.dll" ALIAS "LC1_init" (BYREF rsc AS ASCIIZ * 40, BYVAL tmo AS LONG, BYREF instrp AS DWORD) AS LONG

                  Here is function delare that calls the above funtion in it:
                  DECLARE FUNCTION LC1SetInitialize (camcommandstring$, CamTIMEOUT&, LC1Handle???) AS LONG

                  The following is called from the PBMAIN()

                  Here is the routine:
                  ' --- Initializes Camera -----
                  FUNCTION LC1SetInitialize (camcommandstring$, CamTIMEOUT&, LC1Handle???) AS LONG
                  CamTIMEOUT& = 4000
                  tmo& = CamTIMEOUT&
                  camcommandstring$ = "USB0::0x1313::0x0110::S/N M00226832::RAW"
                  DIM comstrg AS STRING
                  DIM rsc AS ASCIIZ * 40
                  comstrg = CHR$(camcommandstring$,0)
                  rsc = comstrg

                  'rsc = "USB0::0x1313::0x0110::S/N M00226832::RAW"
                  LC1_init (BYREF rsc AS ASCIIZ * 40 , BYVAL tmo&, BYREF instrp???) TO LONG
                  LC1Handle??? = VARPTR(instrp???)
                  'result_var# = x4#
                  END FUNCTION

                  It appears that if I declare var as AS ASCIIZ * 40 int declare, I can't use AS ASCIIZ * 40 as a type when calling the function.
                  Like wise if I declare a var as integer than it doesn't like var% later on or
                  var??? is not the same as var as dword elswhere in the program.
                  I seem to be getting a lot of these type of errors with no way to make the compiler happy. For instance, If I declare var as string and then later as var$, the compiler gives a mismatch.
                  I would guess I'm not seeing the logic here. Can anyone give me some insight. I'm sure at this point I just don't get it yet.
                  Mike Gorden

                  Comment


                  • #29
                    Keep my declare (without the added * 40) and use:

                    Code:
                    FUNCTION LC1SetInitialize (camcommandstring$, CamTIMEOUT&, LC1Handle???) AS LONG
                       CamTIMEOUT& = 4000
                       camcommandstring$ = "USB0::0x1313::0x0110::S/N M00226832::RAW"
                       FUNCTION = LC1_init (BYCOPY camcommandstring$, CamTIMEOUT&, LC1Handle???)
                    END FUNCTION
                    Forum: http://www.jose.it-berater.org/smfforum/index.php

                    Comment


                    • #30
                      Hose - That worked

                      That worked great. now I will try to figure out how to get the actual instrument handle back from the LC1Handle??? variable as I believe this is just a pointer at this point - Thanks

                      I guess the bycopy simplifies the whole thing quite a bit.
                      question?? why didn't we need the " * n" on the ASCIIZ command?
                      How did the function know how many bytes to allocate for the string ?
                      Thanks,
                      Mike

                      Comment


                      • #31
                        Sorry - I mispelled your name Jose

                        Jose - Sorry I mispelled your name. One would think I should be able to recall it correctly in my sleep by now.
                        Mike

                        Comment


                        • #32
                          question?? why didn't we need the " * n" on the ASCIIZ command?
                          How did the function know how many bytes to allocate for the string ?
                          You need it when you DIM a variable AS ASCIIZ, but not in the parameters of a DECLARE.
                          Forum: http://www.jose.it-berater.org/smfforum/index.php

                          Comment


                          • #33
                            That worked great. now I will try to figure out how to get the actual instrument handle back from the LC1Handle??? variable as I believe this is just a pointer at this point - Thanks
                            You don't have to retrieve anything. The function returns it in LC1Handle???.
                            Forum: http://www.jose.it-berater.org/smfforum/index.php

                            Comment


                            • #34
                              You need [ ' * stringlength' ] when you DIM a variable AS ASCIIZ, but not in the parameters of a DECLARE.
                              Also not needed when specifying parameters in procedure headers. Of course when you don't, YOU are responsible for not overruning the buffer! (reading or writing!)
                              Michael Mattias
                              Tal Systems (retired)
                              Port Washington WI USA
                              [email protected]
                              http://www.talsystems.com

                              Comment


                              • #35
                                Jose and Michael - thanks

                                Guys,
                                Thanks and that makes sense and may give me some insite towards some other declaration problems I may have been experiencing. There are alot of details to keep track of at this point. This old brain is looking for some spare shelf space at this point. I need to throw out some old stuff and make room for more I guess. When I finaly get it all in there, I may forget where I put it.
                                Thanks,
                                Mike

                                Comment


                                • #36
                                  I still have one routine not working

                                  I tried both of these calls below to retrieve data. Both routines give the same error, "Memory access violation"
                                  "Program tried to read or write an invalid memory address"

                                  DECLARE FUNCTION LC1_getScanData LIB "LC1_Drv_32.dll" ALIAS "LC1_getScanData" (BYVAL INSTR AS DWORD, BYREF scanDataArray AS DOUBLE) AS LONG

                                  'DECLARE FUNCTION LC1_getScanData LIB "LC1_Drv_32.dll" ALIAS "LC1_getScanData" (BYVAL instr AS DWORD, BYval Arrayptr as INTEGER POINTER) AS LONG

                                  this is the function
                                  FUNCTION LC1_getScanDatacam1 (LC1Handle???, Arraycam1#(), elementcount%) AS LONG
                                  DIM ARRAYcam1(3000) AS DOUBLE
                                  DIM Arrayptr AS INTEGER POINTER
                                  'Program crashes on the fuction below
                                  FUNCTION = LC1_getScanData (LC1Handle???,scanDataArray#) 'Arrayptr%) used with other declare
                                  Arrayptr% = VARPTR(ARRAYcam1#(0))
                                  'I% = (0 to 3000)
                                  FOR I% = 1 TO 3000
                                  Arraycam1#(I%) = @Arrayptr%[I%]
                                  NEXT I%
                                  END FUNCTION

                                  I don't know if this is useful but I will include working code from Liberty Basic here for this routine:

                                  [LC1getscandata2]
                                  'fill the array by the call
                                  calldll #cam1dll, "LC1_getScanData",_
                                  instrmnthndl as ulong,_
                                  pBuffer as ulong,_ ' this should be a 3000 element array
                                  result as long
                                  BufferPointer = pBuffer
                                  'copy each double value to the struct to receive it
                                  for count = 0 to ElementCount - 1
                                  calldll #kernel32, "RtlMoveMemory", _
                                  Element as struct,_
                                  BufferPointer as ulong, _
                                  ElementLen as ulong, _
                                  result as void
                                  BufferPointer = BufferPointer + ElementLen
                                  'fill the LB array with the value
                                  Array(count + 1) = Element.value.struct
                                  next

                                  Comment


                                  • #37
                                    INSTR is a reserved PowerBasic word. Does not the compiler give an error about this, because you try to use it as a variable?

                                    Kind regards
                                    Eddy

                                    Comment


                                    • #38
                                      must have hit something as it posted before I finished.

                                      Anyway I'm not sure why it is not returning the data but I am very happy it is the last one. Unfortunately, It is an Important one.
                                      So once again, I am begging for help... But with and end in sight... I hope.
                                      6:00 am --- Up all night & I need a nap.
                                      Mike

                                      Comment


                                      • #39
                                        INSTR vs instrp - thanks

                                        Originally posted by Eddy Van Esch View Post
                                        INSTR is a reserved PowerBasic word. Does not the compiler give an error about this, because you try to use it as a variable?

                                        Kind regards
                                        No, it did not but I have replaced it with "instrp"
                                        Thanks

                                        Comment


                                        • #40
                                          For some reason, you try to do things in a convoluted way

                                          Use:

                                          Code:
                                          DECLARE FUNCTION LC1_getScanData LIB "LC1_Drv_32.dll" ALIAS "LC1_getScanData" (BYVAL INSTR AS DWORD, BYREF scanDataArray AS DOUBLE) AS LONG
                                          
                                          DIM Arraycam1(1 TO 3000) AS DOUBLE
                                          FUNCTION = LC1_getScanData (LC1Handle???, Arraycam1(1))
                                          and the array should be filled with the values. Forget all these pointers and VARPTRs.

                                          INSTR is a reserved PowerBasic word. Does not the compiler give an error about this, because you try to use it as a variable?
                                          With the latest compilers, all the reserved words excepting end, can be used as parameter names in the declares to external functions.
                                          Forum: http://www.jose.it-berater.org/smfforum/index.php

                                          Comment

                                          Working...
                                          X