Running a microscope camera through pvcam32.dll

VISA; TCP/IP, CAN and similar protocols
mmckinnon6
interested
interested
Сообщения: 7
Зарегистрирован: 01 мар 2011, 20:11
Версия LabVIEW: 2009
Контактная информация:

Running a microscope camera through pvcam32.dll

Сообщение mmckinnon6 »

I am currently trying to import images from a Photometrics Cascade camera, built by Roper Scientific. It operates via the pvcam32.dll. I have attempted using Call Library Function Nodes directly on the .dll, but I'm not familiar with the calling sequence. I have attached the pvcam.h header file. It contains function prototypes, but it seems to me that all parameters are set as inputs, and the only outputs are error messages. I am not familiar with the C programming language, so perhaps I'm missing something. Does anyone have a sample vi that calls a dll directly? Perhaps even the pvcam dll? Any and all help would be greatly appreciated. Thank you!
Вложения
pvcam.h
(54.13 КБ) 537 скачиваний
Аватара пользователя
mzu2006

Professionalism Tutorials Black
doctor
doctor
Сообщения: 2456
Зарегистрирован: 16 авг 2008, 02:12
Награды: 3
Версия LabVIEW: 7.1 10 11 12
Откуда: St-Petersburg (RU), Phila, Boston, Washington DC
Контактная информация:

Re: Running a microscope camera through pvcam32.dll

Сообщение mzu2006 »

mmckinnon6 писал(а):It contains function prototypes, but it seems to me that all parameters are set as inputs, and the only outputs are error messages.
The ones that are pointers (types ending with "ptr") are actually pointers to the place data should be placed to.

I would start with something really simple: class 0 and 1 functions. They use the least amount of parameters.
pvcam_init
pvcam_uninit
pl_error_code
and pl_error_message
and make sure everything works (You are able to succesfully init, uninit and read/display an error code).
mmckinnon6
interested
interested
Сообщения: 7
Зарегистрирован: 01 мар 2011, 20:11
Версия LabVIEW: 2009
Контактная информация:

Re: Running a microscope camera through pvcam32.dll

Сообщение mmckinnon6 »

Ok, I got pvcam_init working and the error reporting works as well. I was able to get the camera name, open the camera, and report any errors. Very simple stuff. The next problem is communicating with pl_get/set_param. It asks for enum data, but I don't know how to set up an enum constant with the appropriate values. Where would I find the documentation and how do I use it? I also have a function called pl_get_enum_param, but didn't have much luck using it either.

PS. I used a built in function in LabVIEW that allows you to automatically create VI's from a .dll file. It's not perfect, but it gets the job done for the most part.
Аватара пользователя
mzu2006

Professionalism Tutorials Black
doctor
doctor
Сообщения: 2456
Зарегистрирован: 16 авг 2008, 02:12
Награды: 3
Версия LabVIEW: 7.1 10 11 12
Откуда: St-Petersburg (RU), Phila, Boston, Washington DC
Контактная информация:

Re: Running a microscope camera through pvcam32.dll

Сообщение mzu2006 »

mmckinnon6 писал(а):I don't know how to set up an enum constant with the appropriate values.
Chose RING, instead of ENUM since it allows you to have missing values. Than you have to convert constants like:

Код: Выделить всё

#define PARAM_SKIP_AT_ONCE_BLK      ((CLASS2<<16) + (TYPE_INT32<<24)     + 536)
(where CLASS2 is 2 and TYPE_INT32 is 2) to their real value:
(2<<16)+(2<<24)+536=131072+33554432+536=33686040=0x2020218
and so on for every parameter defined ...
mmckinnon6 писал(а):I used a built in function in LabVIEW that allows you to automatically create VI's from a .dll file. It's not perfect, but it gets the job done for the most part.
The main trouble with this particular function is that sometimes it does not recognize the additional include files which heavily redefine basic "C" datatypes.
mmckinnon6
interested
interested
Сообщения: 7
Зарегистрирован: 01 мар 2011, 20:11
Версия LabVIEW: 2009
Контактная информация:

Re: Running a microscope camera through pvcam32.dll

Сообщение mmckinnon6 »

The ring constant works great! Thanks so much. Ok, I figured out how to calculate the actual parameter value, and it works on some functions (pl_get_enum_param) so I know the value is right, but for some reason when I try to call pl_get_param it errors out. I'm using the same param_id. I'm not sure what I'm doing wrong. I have attached the pv_get_param vi so maybe you can take a look at it.

I attach hcam (I16) to the first input, param_id (U32) to the second, the number 2 (I16) for ATTR_TYPE (it errors out no matter what number I use), param_value_out indicator (U32) is attached to the appropriate output, and I use error chaining to control execution.
Вложения
pl get param.vi
(11.22 КБ) 473 скачивания
Аватара пользователя
mzu2006

Professionalism Tutorials Black
doctor
doctor
Сообщения: 2456
Зарегистрирован: 16 авг 2008, 02:12
Награды: 3
Версия LabVIEW: 7.1 10 11 12
Откуда: St-Petersburg (RU), Phila, Boston, Washington DC
Контактная информация:

Re: Running a microscope camera through pvcam32.dll

Сообщение mzu2006 »

The last parameter (param_value) has to be a pointer to data. Data can be of variuos types, not only of U32. In CLFN you should correct the handling of the last parameter.
Вложения
pl get param.vi
(9.71 КБ) 453 скачивания
mmckinnon6
interested
interested
Сообщения: 7
Зарегистрирован: 01 мар 2011, 20:11
Версия LabVIEW: 2009
Контактная информация:

Re: Running a microscope camera through pvcam32.dll

Сообщение mmckinnon6 »

Thank you, it works well for the most part. Still has trouble with strings but I'm not too worried about that for now. My current problem is with pl_exp_setup_seq. The vi contains several inputs all feeding into a CLFN, only one output. The CLFN is setup as follows:
inputs: all are U16 unless otherwise indicated.
hcam (I16), exp_total, rgn_total, s1, s2, sbin, p1, p2, pbin, exp_mode (I16), exposure_time, exp_bytes (U32 PTR)
I used 1 for exp_total
1 for rgn_total
1 for s1
652 for s2 (there are 653 pixels in the serial direction)
1 for sbin
1 for p1
491 for s2 (there are 492 pixels in the serial direction)
1 for sbin
0 for exp_mode (TIMED_MODE)
50 for exposure_time
and I attached the output of exp_bytes to a numeric indicator.

I keep getting the error message that "An exception occurred within the external code called by the Call Library Function Node. The exception might have corrupted the LabVIEW memory. Save any work..."

Not sure what to do from here. I called the pl_exp_init function before calling this one, so I don't think that's the problem. Any idea as to where I'm going wrong? Thanks in advance!
mmckinnon6
interested
interested
Сообщения: 7
Зарегистрирован: 01 мар 2011, 20:11
Версия LabVIEW: 2009
Контактная информация:

Re: Running a microscope camera through pvcam32.dll

Сообщение mmckinnon6 »

Just figured it out. I replaced the 6 inputs(s1,s2,sbin,p1,p2,pbin) with a single cluster (to represent the struct), and changed the parameters to Adapt to Type and Handles by Value. It seems to be working and exposing. The problem is I don't know where the image goes and how to access it. Everything just works with pointers and buffers and I don't know how to expose that low level functionality in LabVIEW. Any tips? Thanks!
Аватара пользователя
mzu2006

Professionalism Tutorials Black
doctor
doctor
Сообщения: 2456
Зарегистрирован: 16 авг 2008, 02:12
Награды: 3
Версия LabVIEW: 7.1 10 11 12
Откуда: St-Petersburg (RU), Phila, Boston, Washington DC
Контактная информация:

Re: Running a microscope camera through pvcam32.dll

Сообщение mzu2006 »

Everything just works with pointers and buffers and I don't know how to expose that low level functionality in LabVIEW. Any tips? Thanks!
This is primarily why the wrapper DLLs are developed. But do not despair:

there are two ways:
1. easy: Create a string of as many characters as you need. Pass it to the CLFN as "C string pointer". During the execution of this function it will use this string as a storage.
However, it does not work between function calls, or if there is some background processing (e.g., image acquisition) going on - the address of this string may be changed by the LV memory manager.

2. advanced: use Labview memory manager functiond from within LabVIEW. See following example:
MemoryAllocation.png
Вложения
MemoryAllocation.vi
(9.63 КБ) 435 скачиваний
mmckinnon6
interested
interested
Сообщения: 7
Зарегистрирован: 01 мар 2011, 20:11
Версия LabVIEW: 2009
Контактная информация:

Re: Running a microscope camera through pvcam32.dll

Сообщение mmckinnon6 »

Ok, I need help again. I have everything more or less working (it doesn't give me errors until the end). All I need is to be able to get the array of data into LabVIEW. But I have no idea what to do. I tried pl_exp_unravel, pl_exp_get_latest_frame, and some other things but it doesn't seem to work. I haven't bothered with buffers because in the documentation it says that for single image single frame buffers aren't necessary. Basically, my question is how can I get the image data into LabVIEW? I attached my vi as well as a picture of the back panel. I'll also attach the .llb file with all my sub vi's if I can.

Thanks so much for your help! You have been instrumental in getting this project to work!
Вложения
pvcam32.zip
(975.1 КБ) 486 скачиваний
vi.JPG
mmckinnon6
interested
interested
Сообщения: 7
Зарегистрирован: 01 мар 2011, 20:11
Версия LabVIEW: 2009
Контактная информация:

Re: Running a microscope camera through pvcam32.dll

Сообщение mmckinnon6 »

I just realized I forgot to attach the main vi... here it is
Вложения
Cascade.vi
(22.18 КБ) 475 скачиваний
Аватара пользователя
mzu2006

Professionalism Tutorials Black
doctor
doctor
Сообщения: 2456
Зарегистрирован: 16 авг 2008, 02:12
Награды: 3
Версия LabVIEW: 7.1 10 11 12
Откуда: St-Petersburg (RU), Phila, Boston, Washington DC
Контактная информация:

Re: Running a microscope camera through pvcam32.dll

Сообщение mzu2006 »

Sorry for some delay in answering. pl_exp_get_latest frame has nothing whatsoever to do with the frame readout at the end of exposure.
The problem is that at this point you are not allocating any memory for your frames. Inisde pl_exp_startseq.vi you might want to allocate some memory (like I did in the example above via DSNewPtr). Then, using MoveBlock you should get your data to an array. (And not forget to deallocate the memory by calling DSDisposePtr).

Otherwise, good job. :super:
mechknoll
beginner
beginner
Сообщения: 11
Зарегистрирован: 08 июн 2011, 22:16
Версия LabVIEW: 2009
Контактная информация:

Re: Running a microscope camera through pvcam32.dll

Сообщение mechknoll »

Hi All, I am tryin to create a labview vi to operate a Cascade ll 512. And it also runs using pvcam32.dll. I am new to this sort of project in Labview. I have been reading over the previous posts and have created a list of VI's from the pvcam32.dll using Import Shared Library, selecting pvcam32.dll and my temp.h which is a composition of master.h and pvcam.h.

@mzu2006, your comment about replacing

"(where CLASS2 is 2 and TYPE_INT32 is 2) to their real value:
(2<<16)+(2<<24)+536=131072+33554432+536=33686040=0x2020218
and so on for every parameter defined ..."

Does this mean I need to go through my entire temp.h file and do this for all occurrences of identifiers and replace them with the appropriate numerical value, specified at the #define line?

Thank you
Аватара пользователя
mzu2006

Professionalism Tutorials Black
doctor
doctor
Сообщения: 2456
Зарегистрирован: 16 авг 2008, 02:12
Награды: 3
Версия LabVIEW: 7.1 10 11 12
Откуда: St-Petersburg (RU), Phila, Boston, Washington DC
Контактная информация:

Re: Running a microscope camera through pvcam32.dll

Сообщение mzu2006 »

mechknoll писал(а):I ... have created a list of VI's from the pvcam32.dll using Import Shared Library, selecting pvcam32.dll and my temp.h which is a composition of master.h and pvcam.h.
You can just reuse what has been done already in previuos posts.
mechknoll писал(а): (where CLASS2 is 2 and TYPE_INT32 is 2) to their real value:
(2<<16)+(2<<24)+536=131072+33554432+536=33686040=0x2020218
and so on for every parameter defined ...

Does this mean I need to go through my entire temp.h file and do this for all occurrences of identifiers and replace them with the appropriate numerical value, specified at the #define line?

Thank you
Yes. Unfortunately National Instruments DLL importer does poor job on that.
My impression was that mmckinnon6 already did most of it.
mechknoll
beginner
beginner
Сообщения: 11
Зарегистрирован: 08 июн 2011, 22:16
Версия LabVIEW: 2009
Контактная информация:

Re: Running a microscope camera through pvcam32.dll

Сообщение mechknoll »

I have managed to use the DLL importer, but from here on I am just going to stick with the work mmckinnon6 has done. when i attempt to run Cascade.vi I receive the error message C0_INVALID_HANDLE This is not the handle of an open camera .... i have stepped through the vi and tracked its progress... It seems to be able to call for its name in the pl cam get name step, and everything else appears to be working.... until the pl error message.

I have not been able to get the memory allocation to work. I am using lv 2009, the memory allocation.vi is not compatible. I would like to be able to build this for myself, again to better understand the program. Did you create DSnewptr, MoveBlock, DSdisposeptr from lvrt.dll and a .h file you created? or are these functions hidden somewhere in lv?

One last thing. Is there anything out there that explains the correct sequence of vi operation to get the desired result? or is this information I need to trial and error or look through the pvcam.h file for?

Thanks for all your help
Ответить
  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Communcation with devices»