cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

The LV crashed when I call a dll to control my com port

The LV crashed when I call a dll to control my com port

I am controlling the com port with calling a dll(dwdio.dll--see the attachment). The VI I used is also attached below.
I just used four functions of this dwdio.dll, as followings:
1. bool DWD_set_comport(unsigned char com_port,int *handle)
Parameter config:return type--unsigned 8-bit int(value),com_port --unsigned 8-bit int(value),handle--signed 32-bit int(point to value)

bool DWD_set_baud_rate(int baud,int *handle)
Parameter config:return type--unsigned 8-bit int(value),baud--signed 32-bit int(value),handle--signed 32-bit int(value)

bool DWD_check_comm_link(int *handle)
Parameter config:return type--unsigned 8-bit int(value),handle--signed 32-bit int(value)

bool DWD_close_com_port(int *handle)
Parameter config:return type--unsigned 8-bit int(value),handle--signed 32-bit int(value)

I can run my vi successfully,but Labview will crashed when I close Labview application. I tried many ways to change the parameters and convention, but there is no effect.

Because this dll file need hardware dongle,so I can't upload the vi. I just attached the screen-shot of it.

Can anybody have some analysis on my vi to give me some valuable suggestion?
0 Kudos
Message 1 of 15
(2,206 Views)

Re: The LV crashed when I call a dll to control my com port

Yaoming,
I am curious as to whether the code in the dll is declared as external. I was experiencing the same problem when calling a C++ dll and it was solved by using 'extern' in my code and then building that code into the dll. However if this is not your code that you can alter and rebuild then this suggestion wont help you. I just figured I would mention it as it took me a while to find and solved the same problem you are experiencing.
Best of luck.
-Dave
0 Kudos
Message 2 of 15
(2,193 Views)

Re: The LV crashed when I call a dll to control my com port

NIDave,
Thanks for your reply.I can't do what you said using "extern" in the dll source code,because just like you said that is not my code and I can't alter anything.

To make my problem clearer, I would like to share more information on it:
1. I heard that the dll is compiled by Borland C++
2. In fact, there is already some LV program using the dwdio.dll and it works well, but I can't get the LV source code. So I think there is no problem to call this dll with LV.
3. Before the LV crash, you can see the following error message "The instruction 0x0c43a394 can't refer to the memory 0x0c43a394, which can't be read."

Could anybody help me? It's really very important and urgent to me. Thanks in advance.

To make things clear, I can upload the source code of my vi, but I am wondering if it can be open without hardware dongle license.
0 Kudos
Message 3 of 15
(2,183 Views)

Re: The LV crashed when I call a dll to control my com port

Hello –

Take a look at the following Knowledgebase. I think you might find it useful.

Hope this helps.

SVences
Applications Engineer
National Instruments
0 Kudos
Message 4 of 15
(2,172 Views)

Re: The LV crashed when I call a dll to control my com port

SVences,

Thanks for your reply. I studied the application note from the super-link you provided. I also studied the other two super-links in that notes. But I don't think that can help me to sort my problem.

Firstly, I paste the three super-links I read as following:
1. LabVIEW Application Error: "The instruction at [address] referenced memory at [some address="address"]. The memory could not be read."(http://digital.ni.com/public.nsf/websearch/E8C5C452F04EF7BE86256EF50068CAAF?OpenDocument)
2. When Using the Call Library Function Node, LabVIEW Crashes after the Function Executes(http://digital.ni.com/public.nsf/websearch/58596F5D41CE8EFB862562AF0074E04C?OpenDocument)
3. LabVIEW Crashes after a VI That Calls a DLL Exits(http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/91d4656b15b0dc7a86256ace0073ca90?OpenDocument)

You can see my vi that I attached. I never use any string or array, so I don't need to allocate any memory. What parameters I used in my vi are only some integers and interger pointers.

From my understanding, what I suspected most is the "handle" parameter which is a integer pointer data type. Does anybody has such experience on how to deal with pointers correctly?
0 Kudos
Message 5 of 15
(2,161 Views)

Re: The LV crashed when I call a dll to control my com port

Hello –

The first thing you have to make sure is that the return types and data types of arguments for functions in Call Library Function exactly match the data types your function uses. Erroneous data types assignments can cause crashes.

SVences
Applications Engineer
National Instruments
0 Kudos
Message 6 of 15
(2,134 Views)

Re: The LV crashed when I call a dll to control my com port

SVences,

I know that Erroneous data types assignments can cause crashes. I have checked all the data type with my experience and knowledge,but I didn't find anything should cause this crash problem.

After all,I am not very experienced in Call Library Function, so maybe my vi still have some erroneous data type assignments. Can any DLL expert help me to locate them?

For the original function description, I have posted as attachment in the first post. Therefore,anybody who want to check my data type error can have a check with that function description.

That issue is very urgent and important to me. Can anybody to help me sort this problem as soon as possible? Thanks in advance.
0 Kudos
Message 7 of 15
(2,128 Views)

Re: The LV crashed when I call a dll to control my com port

Yaoming wrote:
> SVences,<br><br>I know that Erroneous data types assignments can cause crashes.
> I have checked all the data type with my experience and knowledge,but I didn't
> find anything should cause this crash problem.<br><br>After all,I am not very
> experienced in Call Library Function, so maybe my vi still have some erroneous
> data type assignments. Can any DLL expert help me to locate them?
> For the original function description, I have posted as attachment in the first
> post. Therefore,anybody who want to check my data type error can have a check
> with that function description.
> That issue is very urgent and important to me. Can anybody to help me sort
> this problem as soon as possible? Thanks in advance.

A few remarks:

1) the Bool return value is probably an int. It doesn't look like a
standard Widnows datatype so you will have to look in the documentation.
However this is unlikely to crash your code.

2) The handle parameter for DWD_set_comport should be set as Pass:
Pointer to Value. All other parameters should be passed by Value only as
they are not pointers at all. Also please wire a 0 constant to the right
side of the CLN for that parameter to provide memory for the DLL to
write in.

3) The calling convention for the DLL functions is not obvious from your
documentation. You have the choice between C (cdecl) and WINAPI
(stdcall) on Windows. Since this DLL seems to be available for multiple
platforms (The remark for each function) it may be that the developer
decided to use cdecl calling convention (a smart choice I would say) but
Windows DLLs usually use stdcall instead.

Having the wrong one will absolutely crash LabVIEW but usually at the
moment you return from the functioncall and not later on.

So I would guess the most probable cause is number 2, but don't discount
the other ones completely.

Rolf Kalbermatter
Rolf Kalbermatter
Averna BV
LabVIEW ArchitectLabVIEW ChampionLabVIEW Instructor
0 Kudos
Message 8 of 15
(2,124 Views)

Re: The LV crashed when I call a dll to control my com port

Rolf Kalbermatter

Thanks for your detailed remarks.

For number 1),I am not sure if it is a windows data type or not but I really see "bool<->signed 32-bit int" relation in Labview's example code. You can get this example with searching "dll" in menu "Help/find examples...". So, I agree with you that the return type Bool will crash my code.

For number 2), which you suspected most and so did I, However, I really set the handle as your suggestion. The handle in DWD_set_comport is set as "pass pointer to value" and other Library Nodes are set as "pass value". You also said "wire a 0 constant to the RIGHT side of the CLN for that parameter to provide memory for the DLL to write in", but I think you were saying "the left" but not "the right". For this point, I do have already tried to wire a 0 constant to handle as input parameter in DWD_set_comport, but it seems have no impact on the crashing.

For number 3),I am sure the calling convention should be "C" but not "WINAPI". If you try to use "WINAPI" in my vi the Labview will crash imediately when you run this vi.

Any way, Thank you. Do you have any other suggestions for me to try? The trouble is really so boring,but I don't want to give up. Please help me. Smiley Sad

For the dll call example in Labview I mentioned in number 1), I can give out the path for your reference---C:\Program Files\National Instruments\LabVIEW 7.0\examples\dll\data passing\.
0 Kudos
Message 9 of 15
(2,112 Views)

Re: The LV crashed when I call a dll to control my com port

Does there nobody be able to help me to solve this problem? Smiley Sad
0 Kudos
Message 10 of 15
(2,087 Views)