DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem creating channel property in tdm file

I'm using a C api from a dll called "nilibddc.dll" (not the TDM Header Writer api) to write/generate tdm files. I program in C# myself.

I've managed to create tdm files, channel groups and channels without any problems. Appending values to the channels has also been straightforward.

However, when i try to create a new property there is some sort of malfunction. The method used (e.g. "DDC_CreateChannelPropertyV") returns a value (0) indicating that the property has been created succesfully (and i can also locate it in the tdm file afterwards), but if i try to load/view this file using DIAdem i get an error message saying the file cannot be loaded. This will also generate a log file with the following text:

"(49) : fatal error xercesc::SAXParseException 15 : Invalid character (Unicode: 0x1C)"
fatal error (42) :Errors while processing the model"

The definition of the method is as follows:

int DDC_CreateChannelProperty (DDCChannelHandle channel, const char *property, DDCDataType dataType, ...);

and my implementation of it (when passing a string datatype, which is what i'm trying to do) is:

[DllImport("nilibddc.dll", EntryPoint = "DDC_CreateChannelPropertyV", ExactSpelling = false)]
public static extern int DDC_CreateChannelProperty(int channelHandle, string propertyName,
DDCDataType dataType, string propertyValue);

Does anyone have any experience with this, or any idea what i might be doing wrong? I'm guessing the problem is related to the string object being passed as parameter, but it's unclear to me how to get around this. I don't have a lot of experience working with unmanaged dll's.
0 Kudos
Message 1 of 17
(7,114 Views)
I've some more testing and foundt that if i pass as paramter (propertyValue) a string with three characters ("aaa" or "aba" etc) then the file is accepted by DIAdem. However, in the property field no text shows up (only the property name, no value).

If I pass anything but that, like "aa" or "bbbb" the program will throw an exception telling me that I'm attempting to read or write protected memory.

If I pass a string containing three digits ("111") the program executes fine but i get the same problem as described in my previous post (DIAdem cant open/read the file due to some invalid character).
0 Kudos
Message 2 of 17
(7,100 Views)

Hi salte,

It looks like you are calling the "DDC_CreateChannelPropertyV" function.  R&D says that you should instead be calling the "DDC_CreateChannelProperty" function.  The last parameter in the "V" version of the function is a va_list, not a character pointer (string), whereas the "non-V" version of the function has a normal character pointer as the last parameter.  R&D also said that it is tricky to call the C++ library using C#.  If switching from the "V" to "non-V" function does not help, you might try hacking together a C++ version of the code for debugging purposes only.  You might potentially need a wrapper C DLL to buffer the C# code and the C++ library.

Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 3 of 17
(7,064 Views)
Thanks for you input Brad. I managed to solve this one on my own.

I think i tried using the method without the "V" first, but was told no such method existed in the dll file.

What confused me here was the wording of the help/documentation file actually. It's like this:
.
.
.
int DDC_CreateChannelProperty (DDCChannelHandle channel, const char *property, DDCDataType dataType, ...);

Purpose
Creates a new property for the specified channel.

Parameters
Name Type Description
...
value any type ([b]passed by value[/b]) The value of the new channel property.
.
.
.
The "passed by value" bit puzzled me, probably due to the differences between managed and unmanaged code. What I found to work in the end was quite the opposite; the "ref" keyword (explicitly passing the reference to the object, not the value).
0 Kudos
Message 4 of 17
(7,053 Views)

Hi Salte

I have a question, how have you done the type definition in C#

typedef

struct _DDCFile DDCFile;

typedef

struct _DDCChannelGroup DDCChannelGroup;

typedef

struct _DDCChannel DDCChannel;

typedef

DDCFile* DDCFileHandle;

typedef

DDCChannelGroup* DDCChannelGroupHandle;

typedef

DDCChannel* DDCChannelHandle;

Regards

Manfred

0 Kudos
Message 5 of 17
(7,013 Views)
All the "handle" structs are integer values as far as I can tell, so I've just used that, and so far I've not have any problems with that.

Example:
The (C++) CreateFile method:
int __stdcall DDC_CreateFile (const char *filePath, const char *fileType, const char *name, const char *description, const char *title, const char *author, DDCFileHandle *file);

I call like this (C#):
[DllImport("nilibddc.dll", EntryPoint = "DDC_CreateFile", ExactSpelling = false)]
public unsafe static extern int DDC_CreateFile(string filePath, string fileType, string name, string description, string title, string author, ref int fileHandle);

The only enum I've implemented is the DDC_DataType, like this:

public enum DDCDataType
{
DDC_UInt8 = 5, // unsigned char
DDC_Int16 = 2, // short
DDC_Int32 = 3, // int
DDC_Int64 = 4, // long
DDC_Float = 9, // float
DDC_Double = 10, // double
DDC_String = 23, // string
} ;

Message Edited by salte on 09-27-2006 02:21 AM

0 Kudos
Message 6 of 17
(7,000 Views)

This works fine for me. Have you tried to convert DIAdem .DAT Files into DIAdem .tdm and read it with the library?

Regards

Manfred

0 Kudos
Message 7 of 17
(6,989 Views)
No, I don't have any experience with DAT files. I haven't used the library for reading TDM files either, only for writing them.
0 Kudos
Message 8 of 17
(6,982 Views)

Hi, Brad:

 

I have a problem with DDC_CreateFileProperty.

 

Here is the definition of the function.

int DDC_CreateFileProperty (DDCFileHandle file, const char *property, DDCDataType dataType, void *value); 

 

Here is the way I used it:

    DDC_CreateFileProperty (file, FILE_Property_Test,   DDC_Double,   &Test); //where, Test is a double type, double Test=10.0; 

 

I got an error information as: Error: An invalid argument was passed to the library.

 

My question is the value of file property can only be string type or any data type like double, float...? How can I attach the value of the property to the property?

 

Many Thanks!

 

Kuo 

0 Kudos
Message 9 of 17
(5,624 Views)

Hi Kuo,

 

what is the content of the string constant 'FILE_Property_Test' you are passing as property name?

 

Greetings from sunny Aachen

Stefan

 

0 Kudos
Message 10 of 17
(5,611 Views)