Yes - I agree completely
Mike
Announcement
Collapse
No announcement yet.
Need Some help with VB Dll to PB
Collapse
X
-
maybe a bit late, but levity has its place.
"Show me a good USB device, I will show you a LOUSY documentation or example code to interface that device"
usually so sad, but so true that it seems software is an after-thought compared to the hardware (but maybe its just my experience with such devices)
Leave a comment:
-
SUCCESS! Yea!
Imagine for a moment a weary old sole, bowing... humble... and gratefull. Thanks so much to all of you. IT Works!
With your permission, I would like to forward this to Thorlabs Inc. so they have a record of these translated routines in PB. I will publish credits for those who helped (they are certainly not mine). Hopefully, others will find relief as well. I viewed many posts on various blogs, from many lost souls during my quest for the truth. Good camera (LC1-USB)... lousy documentation.
Mike
Leave a comment:
-
Funny guy Jose
Jose,
I think you may have me pegged. I should probably rename my company to Convoluted Electronic Solutions Corp. One of the interesting side-effects of this DISORDER is that our product line takes industrial automation to an entirely different level. It can brew your coffee while it runs your factory. A propensity toward the absurd maybe... and yeah, (convoluted) ^ N#. A little Repugnant maybe but it seems to work for me.
I will try your code suggestions now... Thanks again for your help
Mike
Leave a comment:
-
Mike
Good to see you are getting fixes but I think some explanations might help.
Your question re ASCIIZ, it is actually in the name i.e. it is an ASCII group of characters followed by character Zero. The receiving program knows it has reached the end of the characters when it encounters chr$(0). I made a mistake in post #5 BYVAL x1 as STRING, should have been just x1 as STRING which implies the default BYREF, this normally works as well as the OLE engine always adds chr$(0) to the end of the BSTR string though BYCOPY is safer.
As for your array, the method Jose suggested is best but you have a misunderstanding about pointers. Your array is doubles so to work with it with pointers you need a DOUBLE POINTER not an INTEGER POINTER. In both cases your result is a DWORD with the difference being that as you index via the pointer say pointer[1], pointer[2] etc PB will automatically add the correct size of the variable.
For some extra speed change the the DIM and Function to
DIM Arraycam1(2999) AS DOUBLE
FUNCTION = LC1_getScanData (LC1Handle???, Arraycam1(0))
as PB is much faster with 0 based array and 0 to 2999 is 3000 values.
Leave a comment:
-
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))
INSTR is a reserved PowerBasic word. Does not the compiler give an error about this, because you try to use it as a variable?
Leave a comment:
-
INSTR vs instrp - thanks
Originally posted by Eddy Van Esch View PostINSTR 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
Thanks
Leave a comment:
-
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
Leave a comment:
-
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
Leave a comment:
-
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
Leave a comment:
-
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
Leave a comment:
-
You need [ ' * stringlength' ] when you DIM a variable AS ASCIIZ, but not in the parameters of a DECLARE.
Leave a comment:
-
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
Leave a comment:
-
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 ?
Leave a comment:
-
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
Leave a comment:
-
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
Leave a comment:
-
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
Leave a comment:
-
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
Leave a comment:
-
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
Leave a comment:
-
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.
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.
Leave a comment:
Leave a comment: