LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Working with Library DLL

I recently bought a servo control card that I want to operate in LabVIEW 2020 (https://www.amazon.com/WITMOTION-Channel-Controller-Steering-Raspberry/dp/B07VMDFTVR/ref=sr_1_16?dch... )

It works great with the software provided with it (so, the hardware is connected OK).

It has a USB port, and at first, I thought it would run as a virtual COM port, because I've used a half-dozen other servo control devices that did.

But it's not a "serial" device. It shows up (in my 64 bit Windows 10) device manager as a "Human Interface Device" instead. It comes with a DLL and a .h file.

 

In LabVIEW, I tried to use the Tools/Import/Shared Library Wizard, but it keeps crashing. The wizard crashes during a "Parse Header" stage.

 

Since I can see the .h file, I tried to use a manual Call Library Function node.

Whatever I've tried won't run.

 

Here's the text of the .h file:

 

#ifndef _SYSFILE_H_
#define _SYSFILE_H_

#include <stdio.h>
#include <math.h>

#define ID 0

#define STEPMOTOR

#pragma used+
void SysInit(void);
void Delay(unsigned short t);
short ReadPos(uint8_t ucChannel);
unsigned int read_adc(uint8_t adc_input);
void WriteDO(uint8_t ucChanel,uint8_t ucData);
uint8_t ReadDI(uint8_t ucChanel);
void SetSteeringMotor(uint8_t ucChannel,signed short sPulsWidth,uint8_t ucIncriment);   /*ucChannel0~6,sPulsWidth500~2500*/
void SetMotorSpeed (uint8_t ucChannel,int8_t cTempSpeed,uint8_t ucIncriment);             /*ucChannel0~3,cSpeed-100~100*/
void SetStepMotor(uint8_t ucChannel,short sStep,uint8_t ucIncriment) ;        /*ucChannel0~1,iStep-3000~3000*/
void SetStepCurrent (uint8_t ucChannel,uint8_t ucCurrent);
void SetStepSpeed (uint8_t ucChannel,uint8_t ucSpeed);
#pragma used-
#pragma library sysfile.lib
#endif

In this file, each uint8_t was originally an unsigned char, and the int8_t in the SetMotorSpeed was originally just "char", but I changed them when trying to debug so that they would exactly match the way LabVIEW seemed to want them (see the image of the configure window posted below). I think they're the same thing, and it didn't make a difference either way. The software provided kept working either way, too.

 

An image of my "code" is below. I also attached the vi, DLL and .h files (the original and the edited).

If you look at the "original" .h file, you'll see that I deleted a bunch of chinese characters from some of the comment lines, because I found some other posts in the forum that suggested that the presence of these characters might be what causes the wizard to crash (it didn't help).

 

Also attached is an image of my Library Config window, where I set the parameters for the function call (I'm trying to use the "SetSteeringMotor" function listed in the .h).

 

I tried swapping the calling conventions (C vs stdcall).

I get different error messages depending on whether the "Specify Path" box is checked.

When it's unchecked, the error message is:

The function name specified for this node cannot be found in the library. Right-click the Call Library Function node and select Configure, then choose the correct function name.

 

When it's checked, the error message is:

One or more required inputs to this function are not wired or are wired incorrectly. Show the Context Help window to see what the connections to this function should be.

 

I have the Call Library's error checking set to maximum.

 

I guess the bottom line is that I don't really know what I'm doing with calling Libraries. In the past, whenever I used them, I just modified LabVIEW code that was provided by the device manufacturer. I'm clearly missing something important here now that I'm "starting from scratch" with this device.

 

Any suggestions would be appreciated!

 

 
0 Kudos
Message 1 of 5
(1,079 Views)

If it were me, I'd buy a cheap USB-UART adapter and use that to connect to the board.  Then you would have your friendly COM port once again.

0 Kudos
Message 2 of 5
(1,061 Views)

If this proves to be the hardware I want, then I'm going to need to force every student in my class to buy one.This just adds to a growing list of stuff they're already buying.

If possible, I'd like to figure out the DLL instead.

0 Kudos
Message 3 of 5
(1,017 Views)

@pogo wrote:

I recently bought a servo control card that I want to operate in LabVIEW 2020 (https://www.amazon.com/WITMOTION-Channel-Controller-Steering-Raspberry/dp/B07VMDFTVR/ref=sr_1_16?dch... )

It works great with the software provided with it (so, the hardware is connected OK).

 

When it's unchecked, the error message is:

The function name specified for this node cannot be found in the library. Right-click the Call Library Function node and select Configure, then choose the correct function name.

That's because this DLL is not a classical DLL. It does not export any functions through the PE export table. I assume that it is rather a .Net assembly since it internally interfaces to the mscoree.dll and mscorlib.dll, which is the .Net runtime interface. Try to point a LabVIEW method node to this DLL and see if it allows you to select any of the methods from your header file.

 

The fact that there is an actual C header file is however rather strange. Either there is another DLL somewhere that implements this API as described in the header file or those developers were on speed somehow.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 5
(1,014 Views)

Hi Rolf,

 

There *is* another DLL in a subfolder. I'll try to mess around with that later today...

 

Thanks,

 

Pogo

 

0 Kudos
Message 5 of 5
(998 Views)