Jump to content

Neon_Light

Members
  • Posts

    36
  • Joined

  • Last visited

Everything posted by Neon_Light

  1. I am afraid you are correct, the C I did was low level ANSI... I bought a book to learn C++, but I am afraid to have landed in a chicken egg situation: I really want to finish this project so I can start with the book but I am losing a lot of time finishing this project because the lack of knowledge. I can copy and understand parts from the internet, but without the overview which a book can give ... ow well I think you get the point. Anyway your answer helps me a lot I hope I can start reading the book soon. Is my assumption correct that: I only need a handle if the size of the data is unknown e.g. the struct with a unknown string size? But when I do something like this: typedef struct { int firstInt; int secondInt; int thirdInt // The string is gone !! Now I know it is 3 x int = 12 bytes }structSample; .. Then I do not need a handle? Thanx again Rolf!! Your help is great!
  2. Hello to you all, Sending a cluster with int's I did manage to send an array with clusters from a dll to Labview. Thank you all for the help. You can find the link here: https://lavag.org/topic/22877-can-someone-help-me-with-an-example-for-an-existing-wrapper-dll-which-uses-function-pointer-with-callback-function/#comment-147496 It works fine I am very pleased with it. ๐Ÿ˜ƒ Sending a text string I did got a example here: https://forums.ni.com/t5/Example-Code/Posting-Events-to-a-LabVIEW-Event-Structure-From-a-Dll/ta-p/3996283 Tested it and it works fine. Again I am happy ๐Ÿ˜ƒ Sending a cluster with int's AND a string Now I want to send a cluster / struct with a couple of int's AND a string of text. I Got a example of how to send text from a C / C++ wrapper to Labview, can someone please help me out? The thing I do not get is, how to combine the both examples. Is "sizeof(structSample)" valid with a LStrHandle in it? How do I copy the data from the string to the struct, etc. Can someone change the code example or help me with the example so it works? I did add some text to the example code to make it more clear I added +++ signs in my comment in the code. Hope someone can help me. Thanx ! // LVUserEvent.cpp : Defines the entry point for the DLL application. // #include "stdafx.h" #include <stdio.h> #include "LVUserEvent.h" #define STRING_LENGHT 256 //Can be any size // ++++ I want to send this Cluster/Struct to Labview typedef struct { int firstInt; int secondInt; int thirdInt // +++++ I try to add this, Gues this will not work .. see extcode.h LStrHandle textString[TEXT_STRING_SIZE]; }structSample; typedef struct{ int32_t size; structSample elm[1]; }totalstructSample, **structHdl LVUSEREVENT_API void SendEvent(LVUserEventRef *rwer) { LStrHandle newStringHandle; //Allocate memory for a LabVIEW string handle using LabVIEW's //memory manager functions. newStringHandle=(LStrHandle)DSNewHandle(sizeof(int32)+STRING_LENGHT*sizeof(uChar)); // +++++ OW no another one ... structHdl = (eventHdl)DSNewHandle(sizeof(totalstructSample)); Sleep(2000); PopulateStringHandle(newStringHandle,"+++ Dear int I don't want you in my PostLVUserEvent"); //Post event to Event structure. Refer to "Using External Code //with LabVIEW manual for information about this function. PostLVUserEvent(*rwer,(void *)&newStringHandle); return; } void PopulateStringHandle(LStrHandle lvStringHandle,char* stringData) { //Empties the buffer memset(LStrBuf(*lvStringHandle),'\0',STRING_LENGHT); //Fills the string buffer with stringData sprintf((char*)LStrBuf(*lvStringHandle),"%s",stringData); //Informs the LabVIEW string handle about the size of the size LStrLen(*lvStringHandle)=strlen(stringData); return; }
  3. Hello Rolf, thank you, you were completely correct. The label was missing. I did spent a lot of evenings coding and most of it seems to work. To setup the IDE I did use this site it describes how to setup the C environment in VSC and tips how to debug the DLL software. https://gitlab.com/serenial/talks/11-20-labview-and-vscode-shared-libraries I did also try to get rid of the array changing this code: typedef struct { int32_t status; double value; } DataRecord; into typedef struct { int32_t status; double value; } DataRecord, *dataHdl; ...... ...... dataHdl handle = NULL; the rest of the code I did keep the same. This does not work. How can I send one cluster back at a time? Does the handle always need a size even when the size is one cluster / struct? The reason I ask is because the size of the array is different every call, I did find out when using a debug window as described in the link above. Another question I have is how to transport the Labview LVUserEventRef data to the callback function? Is the part below legal? LVUserEventRef giveReftoCallback; FuncCalledFromLabviw(LVUserEventRef *rwer,int bla) { .... giveReftoCallback = rwer; ..... } void __stcall MyCallback(....) { .... err = PostLVUserEvent(giveReftoCallback, &handle); } You also did write: Yes the callback function will be called ever time there is new measurement data. So I there is a change the callback function is still sending data to Labview when it is called for new data. Is there a easy way to fix this? thank you for the help!!
  4. Thank you Rolf !! but the thing I can still not find is how do I get acces to the array in the event structure. If I wire a number for example index to the create user event it ends up in the event structure. Wile the callback array does not appear. I added a screenshot, hope that helps.
  5. Hello I did give it a try I am able to compile some C code send some data to the created DLL and receive data from the DLL. So that is great ๐Ÿ™‚ thanks ! The original DLL however will return a array with structs to my C DLL I will try to implement thePostLVUserEvent part there . When I try to make an even structure as an experiment I am not able to get the array out again. This makes me think I am not using the event method in the correct way. what will be the best way to get an array from the DLL back to the Labview event? Do I need to send every array element back with a PostLVUserEvent?
  6. Hello ShaunR, thank you for the answer. I have to admit it was not the answer I hoped for as this will take more time, on the other side learning new things is always a great thing ๐Ÿ™‚ . I did read this forum: And I think for me the most important points are: Although the document is old I can use most parts of: "Using External Code in LabVIEW". The link to the Ni site contains more recent info: https://www.ni.com/docs/en-US/bundle/labview/page/lvhelp/labview_help.html One part which is outdated of the external code document is how to set up the environment in the IDE. At this time I am using VSC, as a IDE. Do you have a link to a VSC setup to develop a DLL for Labview?
  7. Hello Rolf and ShaunR, Thank you for the help! I do not have the source code of the wrapper but they included 2 files a Typedefs.h and a interface.h The: Int LOGEXPORT __sdcall LOG_StartLogging{const char ** logFilename, ptLogCallbackfunction ptFunction, ptObject ptObject} is implemented in the dll and I can call it with a CLFN, first I tried to wire the output of a Register For Events function to the "ptLogCallbackfunction" as I understood this would provide a function-pointer to a Labview function/vi which would then behave as a callback function. It makes Labview crash though. When the driver is not running it returns a error message. I think the function does not try to use the callback pointer when the driver is not running. My communication might not be completely correct as I am new to callback functions. Maybe this helps, above example text: Void __stdcall callbackLog(ptObject object, const int ArraySize, const StructLogdata *const logDataArray) there is also the text: typedef Void( __stdcall *callbackLogFunction)(ptObject object, const int ArraySize, const StructLogdata *const logDataArray) I can give it a try, but how do I approach this? I can also try to code it in C, think it is interesting and fun but it has been a while since I did code C. Although I planned to refresh my C knowledge, this would take time and focus on one thing to learn at a time might be more successful. It is late now, I will read trough the examples and Using External code pdf tomorrow. Thank you for the help you provided!
  8. Well the header file I mention is from the wrapper someone else wrote. I have got some functions working from this wrapper. The only part I havent managed to get working is the part with the callback. So what you are saying I need a wrapper to use this wrapper because it uses a callback function? I will read the example you did provide thank you!
  9. Hello I hope someone can help me, I have been trying to get this to work for days but no success yet. What I want to do I got a dll with a wrapper, this dll and wrapper can be used for a special datalogger. The wrapper contains multiple functions, I have got some of them working using a CLFN, for instance I can read a jumper setting from the datalogger in LabView. So far everything is fine. Of course I am not that interested in the jumper setting, I would rather use the datalogger to log data. I need to run one function to start logging. When there is enough data in the databuffer of the driver dll it will call a callback function I need to write in Labview, here is the function which starts the logging as described in the header file: Int LOGEXPORT __sdcall LOG_StartLogging{const char ** logFilename, ptLogCallbackfunction ptFunction, ptObject ptObject} logFilename needs to be a NULL pointer, from my understanding I do not need to do anything with it. Only provide it. If I do not do anything with it some data is saved at a default location. ptLogCallbackfunction, as far as I know I need to provide a pointer to the callback function ptObject ptObject, this must be a void pointer The header also provided how the callback function could look like in ๐Ÿ˜„ Void __stdcall callbackLog(ptObject object, const int ArraySize, const StructLogdata *const logDataArray) { // copy data from logDataArray for use in my code } StructLogdata is a struct with different datatypes. What I did try I did a search on internet there are some examples about callback functions, most of them point to NET and active X. They use a reg Event Callback. I did read the helpfile at the end of the helpfile there is the text: โ€œUse the Event structure or the Register For Events function to register and handle non-.NET or non-ActiveX events dynamicallyโ€ I am having a hard time to find a proper example. I did find this site with some information: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P8XJSA0&l=nl-NL and this one about the refnum: https://forums.ni.com/t5/LabVIEW/Passing-Event-Refnum-to-Call-Library-Function/td-p/4107748 So I did make a user event, I wired a static Vi ref containing a callback vi to the input of this user event. I did wire the user event to a Reg event and wired the event registration refnum to the start logging dll call library function node function pointer input and also to an event structure. I did place a counter in the event structure. But nothing happens besides for an exception which makes Labview crash. The parameters I did use in the call library function are: logFilename: type numeric, datatype: Signed Pointer-sized int Pass: pointer to value ptLogCallbackfunction: type: adapt to type, Data format handles by value (tried all options) ptObject: same as logFilename I did try a lot of different things. Writing them in this post will result in chaos and I donโ€™t want that. I hope someone can help me with a simple example how to make this work, or point me into the correct direction. Thank you all for the help!
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.