Cancel
Showing results for 
Search instead for 
Did you mean: 

C interface listAt

Creator
Creator

Hello Everyone!
I would like to use the C interface of Plant Simulation. I managed to create a DLL file in C++ and call it from a Plant Simulation model. The DLL uses the listAtPut function to write into the cells of a TableFile.
Now I try to read one cell of a TableFile with listAt function (just like ListAtPut function), and here comes my problem. I thought that "data1" is a variable that would contain the string which is read, but i was wrong.
So can you tell me how to modify my source code below to have a variable which contains the string (and after that I can write it to a csv)?

SourceCode:

//includes...

extern "C" __declspec(dllexport)
	void listRead(UF_Value *ret, UF_Value *arg)
{
	char data1[1];
	UF_Value val1;
	val1.type=UF_STRING;
	val1.value.string=data1;
	val1=listAt(arg[0].value.object,1,1); //read the 1,1 cell of the TableFile

	//writing to file
	std::ofstream f_Opt_Sim("C:\\Users\\testcsv.csv");
	f_Opt_Sim<<data1;
	f_Opt_Sim.close();


	ret->type = UF_NONE;
}

 

(What I found in the .csv file, was not even close to the string which i expected)

Thank you for your help!

3 REPLIES

Re: C interface listAt

Siemens Phenom Siemens Phenom
Siemens Phenom

Hello Hun,

listAt returns a variable of type UF_Value. You don't have to initialize any part of this structure before calling it.

After the function returned the value, you should inspect val1.type to see which part of the union contains valid data. If type is UF_STRING then val1.value.string has the corresponding string. If type is UF_REAL then val1.value.real has the corresponding real value.

Regards,

Ralf
------------------------------------------------------------------------------------------------------
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.

Re: C interface listAt

Creator
Creator

Thank you! It works now!

Re: C interface listAt

Experimenter
Experimenter

hi,may u show your spp file 


@Hun wrote:

Thank you! It works now!