Jump to content

Neon_Light

Members
  • Posts

    33
  • Joined

  • Last visited

Posts posted by Neon_Light

  1. Hello Rolf, thanks again for the great help!

    It's kind off busy here so I was not able to reply earlier..

    On 4/2/2024 at 1:56 PM, Rolf Kalbermatter said:

    If and how the DLL uses exceptions is completely up to the DLL and there are actually several way this could work but only the DLL writer can tell you (if it is not explained in the documentation). Windows has a low level exception handling mechanisme that can be used from the Win32 API. It is however not very likely that a DLL would make use of that. Then you have the structured exception handling or its namesakes from different C++ compilers. And here things get interesting since each compiler builder was traditionally very protective about their own implementation and were very trigger happy about suing anyone trying to infringe on the related patents. It means that GCC for a very long time could not use the Microsoft SEH mechanism and therefore developed their own method that was avoiding Microsoft patents. So if your DLL uses exceptions, and doesn't handle them before returning from a function call to the caller, you might be actually in a bit of a bind as you really need to know what sort of exception handling was used. And if you use a different compiler than what was used for the DLL, you will most likely be unable to properly catch those exceptions anyhow, causing even more problems.

    Well I am in a bit of luck this time I did find some documentation and the compiler used is "MSVC2019".

    It is written in C++ and it: "exports a pure C interface", I like the word pure as it reminds me of clean air, oceans without plastic and being young, in this context however I can not really understand what is meant. maybe you can give a global idea?

    On 4/2/2024 at 1:56 PM, Rolf Kalbermatter said:

    Basically, a DLL interface is either C++ oriented and then needs to be interfaced by the same compiler that was used for the DLL itself anyhow, or it is a standard C interface and then it should NEVER pass unhandled exceptions to the caller since that caller has potentially no way to properly catch them. One exception are Win32 exceptions that the LabVIEW Call Library Node actually is prepared to catch and turn into the well feared 1097 error everybody likes so much, unless you disable the error handling level completely in the Call Library Node configuration dialog. 😁

    If I read this text I think it might be wise to turn error handling off? At this time I did set it at maximum, hoping to get some information about things that might went wrong.

     

    image.png.0884eba95a3bdb34c3b62b73b45efaa4.png

     

     

    On 4/2/2024 at 1:56 PM, Rolf Kalbermatter said:

    Your example code, while probably condensed and not the whole thing, does however ignore very basic error handling that comes into play long before you even get into potential exceptions. There is no check for the Load_Extern_DLL() to return a valid HANDLE. Neither do you check for the function pointers you get from that DLL to be all valid.

    Thank you for the remark, In the real code I do check if the handle is not 0 if it is zero I return a error code to Labview. If the pointer is 0 I also return a error code to Labview

     

    On 4/2/2024 at 1:56 PM, Rolf Kalbermatter said:

    p2_CallbackFunction_t is rather superfluous and a bit misleading. The _t ending indicates it to be a type definition but in fact you simply declare a stack variable and assign the reference to the CallBack function to it. Luckily you then pass the contents of that variable to the function, so the fact that that storage is on the stack and will disappear from memory as soon as your function terminates is of no further consequence. But you could just as well simply pass the CallBack function itself to that function and completely forget about the p2_CallbackFunction_t variable declaration.

    Thank you for the remark. I need to read this remark again when it is not too late, my energy level is kind of low now at the end of the day. I will try to find the example I started with to go with your remark.

     

    On 4/2/2024 at 1:56 PM, Rolf Kalbermatter said:

    Once your function returns, you have indeed no way to detect exceptions from the DLL anymore as there is no stack or call chain on which such an exception could be passed up. The way this should be done is by the DLL handling all exceptions internally and passing an according error indication through the CallBack function in an error variable. It can't use the CallBack function to pass up exceptions either since the CallBack function is called by the DLL, so the exception handling can't go from the callback to LabVIEW but only from the callback to the caller, which is indeed yes ... big drumrolls ... the actual DLL.

    If your DLL doesn't catch all exceptions properly and handles them by translating them to an error code of some sort and passing that through the callback or some other means to the calling application, then it is not finished in terms of asynchronous operation through callbacks. Exceptions only can pass up through the call chain, but if there is no call chain such as with a callback function, there is no path to pass up exceptions either.

     

    I think I understand what you write. The dll I wrap in my own dll uses a callback to send error and status massages. I can see them in Labview now 🙂 .  I think however it is better to use this info in the C code eventually e.g automatic stop logging when there is an error related to the logging. I need to find out the best way to do this though. 

    And even if I can use the error and status messages it would be really helpful if there is something going horrible wrong with the dll, something I did not think about, the dll will not be able to make Labview crash, I rather would have a message telling something like:  "Unknown error at dll, program halted.." ,  better to have a ugly way of telling something went wrong than a crash-ing way which closes down Labview. If this would be possible please let me know.  Maybe I can at least use some kind of exception handling when loading / running the functions of the dll I try to wrap?

    Thanx for the help!

     

     

     

     

     

  2. Hello all,

    background

    A while ago I wrote a dll wrapper to get data from dedicated test-hardware. For this hardware there is a dll available.  To use this dll you need to use an callback function. If you need to use a dll in Labview which needs a callback you need to write the callback in C code and use a Labview C lib to get the data into Labview, basically my dll takes care of this problem .

    Enhance the code and way of working more efficient

    The code I wrote code works fine. However I did not use / test it for hours on a row. And sometimes If I make a mistake when changing the code I run into problems. I was able to fix all the errors and problems however it was not the most efficient way of working. For instance If there  is a serious error in the code the dll I need for the hardware can crash, it can make my wrapper crash, which will in return make Labview crash. This makes the way of coding inefficiënt and it will not enable me to read my C++ book etc etc.

    Example pseudo code

    I did try to extract some main points of intrest from the code, I did add some comment in the code. I hope someone can give me some general guideline or advice what to read.

    At this time I am reading:

    Unhandled C++ exceptions

    I think I might be able to use it, I did not use this before so advice would be welcome.

     

    Thank you all for the help !

     

    // ..
    // This is a part of the code only intended to have a talk about how to catch errors 
    // It is not complete and intended as Pseudo code
    // ..
    
    
    int __stdcall MyDriverLoads(const int NumberToInitialise,const bool enableAnotherOption , const char *const path , LVUserEventRef *rwer)
        {
    		
    	// loads the dll 
    	// Q -- I can check if (F_functionname !=0), if it is not 0 then I can proceed if the function returns 0 I can return an error to Labview
    	Extern_dll =	Load_Extern_dll();
    		
    	// Get the functions I need from the dll
    	p2_ExternDriver F_ExternDriver = 	(p2_ExternDriver)GetProcAddress(Extern_dll, "_ExternDriver");
    	
    	p2_Initialise F_Initialise = 		(p2_Initialise)GetProcAddress(Extern_dll, "_Initialise");	
    	p2_AdapterCount F_AdapterCount = 	(p2_AdapterCount)GetProcAddress(Extern_dll, "_AdapterCount");	
    	p2_StartLogging F_StartLogging = 	(p2_StartLogging)GetProcAddress(Extern_dll, "_StartLogging");	
    
    	p2_StopLogging F_StopLogging = 		(p2_StopLogging)GetProcAddress(Extern_dll, "_StopLogging");	
    	
    	
    	// When there are adapters found I tell it in Labview
    	adapterCount = F_AdapterCount();
    	
    	
    	// Get the callback function adress, if adress == 0 I can see something is wrong
    	void(__stdcall *p2_CallbackFunction_t) (pt2Obj , const LogData & ) = &CallbackFunction;
    	
    	
    	// Q -- I could use try {} and catch {} however I do not have acces to the source code of the dll so,
    	//		I do not know if they used 
    	//			trow "The Blue error" , or
    	//			trow "The Red error"
    	
    	ret = F_ExternDriver(adapterCount, enableLogFile, path, *p2_CallbackFunction_t, pt2Obj);
    	
    	// This tels the dll to start logging before this command you will not receive data in Labview
    	ret F_StartLogging(1,2,3);
    	
    	// Labview is receiving data thats great !!!
    	
    	return ret;
    	// Q -- Labview has been receiving data for a hour what happens if the used extern dll crashes ??
    	//		If the dll crashes when return is passed I can not use try() and catch anymore.
    	// 
    		
    	}
    	
    	
    
    
    	extern void __stdcall CallbackFunction(pt2Obj , const LogData & )
    		{
    		// There is a lot to do here 
    		// do stuff!!
    		// I did not write everything here
    		
    		err = PostLVUserEvent(*event_ref, &tmpEvent);
    	
    		}

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

  3. On 12/4/2023 at 1:14 PM, Rolf Kalbermatter said:

    If you upgraded the cRIO base system to LabVIEW 2018 I do not see how the old rtexe still could be running. It means the chassis got restarted several times, much of it got probably wiped for good and even if the old rtexe would still be there, it could not load into the new 2018 runtime that is now on the system.

    So yes for first tests it should be as simple as opening the main VI and pressing the Run button. Even if you had an old version of the application deployed to the target and set to run automatically (which would have to be done in LabVIEW 2018) LabVIEW will tell you that there is already a deployed application running on the target and that it needs to terminate that in order to upload the new VI code and then run it.

    Hello RolfK,

    Thank you again for the great help. The terminology is not completely clear to me. Although the 9074 does not run Linux but VxWorks, I try to make a quick compare  between Linux to make it easier to understand for me.

     

    • In this screen from MAX I did click next and did install the recommended software. Is this what you mean with "the base system"? This is the same in linux as apt-get upgrade? 
    • I did not update the BIOS with the button on the left. Updating the bios would be going from Ubuntu 20 to Ubuntu 22? 

    Do I need to do a BIOS update to install and test the new version of RT Main ?

     

     

     

     

  4. Hello 

    I try to compile a FPGA clicking the right mouse button on Build specifications -> click the Test FPGA --> build. It starts. But it ends 

    with this window:

    image.png.718030f6bd5cccf54f0c5cdb9ea53ff5.png

     

    then in the compile status I can click details, which shows me:

    image.png.0f63012b76038b9963e2694b8a21eb50.png


     

     

     

    1. I did use windows search to find the first file in the list. I can find it. 
    2. I did try build and rebuild they both result in the same error
    3. I did clear compiled object cache did not help also
    4. added the directory at options --> Paths which did also not work

    I am using Labview 2018, the project was previous build in Labview 2017 which is not available anymore.

    The cRIO type is a 9074

    Hope someone can help me! thank you all

     

    Eddit:

    I did previously use version 2019 of Labview this version worked fine.

    I did find this link:

    https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P9KGSA0&l=nl-NL

    I did try to run the  "FPGA Compile Worker"  it did not start so I did go to the directory where the exe file is located. In This directory I can also find a file with the name: ".NI.LV.FPGA.2019.CompileWorker.lock" This makes me think there is some software left behind from the 2019 version causing a conflict. Can I remove the LOCK file without serious consequences ?

     

     

     

  5. Hello all,

    At work there is an Old 9074 which is running test software. There is also a 9148 connected to the 9074.  I did change the old software tested it in simulation in simulation it works fine. 

     

    What I already did do:

    1. I got RAD working, so I can restore the old software
    2. I did install the packages needed for Labview 2018 
    3. I did find I can use MAX to install new software clicking the cRIO --> software --> add remove software gives me the option to install Labview 2018 recommended packages I did this it removed some files and added a lot of new files

     

    Now I do need to deploy the new RT main to the cRIO there are a lot of actions I do need to perform. Can someone please tell me the basic steps I need to take to deploy the new software and test it on the real hardware? Is it as simple as hitting the run button or do I need to stop the old RT main first? Is action 3 above enough or did I had to remove old software?

     

    hope someone can give me an overview, thanx !

     

     

     

  6. On 11/3/2023 at 6:28 PM, ShaunR said:

    He should have. All the stuff he needed was on the NI site that I gave him a link to.

    Hey ShaunR, most of it did work, the only thing the install complained about was:

     

    "Install National Instruments Device Drivers Now?"

     

    Are these also on one of the files you linked to? Or do I need to download them seperately?

     

    Thanx for the help ! Now I am happy again I hope I can build some nice things and convince my managers etc. to buy a new license ...

     

     

     

  7. Hello hope you can help,

    (did edit this text to make it better to understand)

     

    Normal testcode 

    (If I have more time I can try to include this code)

    I try to simulate the real time main in a cRIO test project. All goes well I can run the real time main on "my computer" target and use the FPGA in simulation mode without the use of real hardware.

    when I add an extra loop to the real time main with new shared variables which are not used in the simulated FPGA,  I can not deploy anymore. In that case I can only deploy  when I use the option disable auto deploy variables (right mouse on RT compact RIO target) and make the variables absolute (right mouse on the variable in the blockdiagram code). but when I run with this option I get an error  -1950679035 when I want to use the shared variables which are *not* used in the FPGA. I Use a desktop execution node to change data on the simulated FPGA this works fine. 

     

    Smaller code without the FPGA 

    I made the code smaller and easier to understand to have focus on the shared network variables,  this code is included below . There is a screenshot and the real code. 

    When I use the small program and try to load the *non* FPGA shared variables,  I get the same error  -1950679035. 

    when I only use the shared variables which are previous used in the FPGA vi  and remove the non FPGA shared variables all is okay, I can also see the FPGA variables in the  in the Ni Distributed system manager. Although the other program simulating the total cRIO code with FPGA has long been stopped.

    What I want is to open a library with a link to the file e.g.:   C  : \folder with *.vlib     . But I am unable to open a direct link to the harddrive e.g.:  C:\Users\noob\Documents\labview projects\cRIO\My Control Application\Shared Variables\Noob Shared Lib.lvlib I get the error -1950679035 again. 

    I only do not get errors when I try to acces network shared variables I did previous use in the test with the FPGA simulation and where where used in the FPGA code.  I think the desktop execution node only adds shared network variables from the FPGA code to the Ni variable server and does not do this for the shared network variables in the Real time main code. I am able to see the old FPGA shared network variables when I use the NI Distributed System Manager which can be found at the tools menu. 

    I think I must  load a variable library into the server before I can acces it with the code below is this correct? Can anyone point me in the correct direction to do this?

    hope you guys can help and I hope this text is easier to understand compared to the text I wrote last night 🙂 at nights it tends to be late and my texts show that. 

    If the question is not clear please let me know then I will try to solve it. Hope you guys can help thanx!

     

    image.png.6b33bb922981c2e22e7a90643dbe5eb5.png

     

     

     

     

     

     

     

     

    Enable Debug modus.vi

  8. 29 minutes ago, Rolf Kalbermatter said:

    The 5 and 10 volume license give you some discount. But it still adds up. And the real volume licenses for large sites are indeed relatively cheap for what you get but I doubt your company is willing to shelf out 50k or more even if it allows them to have 500 licenses to be used. 😀

    I think they are willing but hard to convince, its like chicken egg, chicken egg, chicken egg. etc and then they go like lets have carrots we understand that! 

    What I mean is you need a team to build up knowledge and experience. That costs money like a few licenses. When they, the managers can see what can be done with it then they are willing to pay.   

    That is the same as with software as Altium, Matlab,  other CAD software, etc 

    If I cant get the software working I am certain the chicken or egg will die. 

  9. 7 minutes ago, Rolf Kalbermatter said:

    No you can't anymore. NI added subscription licenses in November or December of 2021 to the order system, and discontinued perpetual development licenses on January 1, 2022.

    After that date they did officially not sell any non-subscription licenses anymore. For a little while you could try to appease a sales representative and if you were good and did it long enough, they could still put an order for a perpetual license into the system, but I'm pretty sure that possibility has long been removed since.

    You could buy a subscription for one year. It gives you the right to download older versions too. If you use the old serial number, it will allow to use the old installation up to the point your maintenance contract expired. If you use the new serial number that comes with the subscription purchase, you can run old versions for as long as your subscription is valid.

    OW well I have got until 23:59 to use this license ... hope I can install the other 2018 after that. 

    I know some big companies have got volume licenses would be happy if my work had one of those. that would be a relaxing thought. They are relative cheap compared to the licenses which only enable a few to people to work with. but then you need 5 or more employee's  who use Labview I think.

     

  10. 1 hour ago, Rolf Kalbermatter said:

    You won't like it but you could never officially download software from the NI site other than the latest version to use as evaluation download without a maintenance support contract. If you were not logged in with an account that had a current maintenance support contract associated, selection of previous versions were blocked from the Download website ever since that Download page got active.

    And NI never ever guaranteed anywhere that you could keep downloading software as far back as you liked. Not even with a maintenance support contract or nowadays a subscription. Even if you pay for it, it is a service that is delivered as is, without any guarantees that you can continue to download older version (for instance LabVIEW 7.1, just to name one very old version) which you indeed can't and never will be able to download anywhere officially.

    So if you build a system that requires a specific version for whatever reason and don't archive all and every piece of that system somewhere, the problem is definitely up your sleeve and always has been.

    As for charging a 100 dollar fee to download software, that may sound an interesting option. But unfortunately companies of the size of NI nowadays will not even lift a telephone of the hook for that amount. Why? Until the order is booked, payment processed, accounting had its pee over the transaction, shipment (or access to the file organized), the whole thing has cost many times more than those 100 bucks.

     

    Can you even get a maintenance support contract on old versions? Or can you only get it on the new versions where you need to pay every year?

     

     

     

  11. On 4/10/2022 at 2:38 PM, Rolf Kalbermatter said:

    It's common industry standard. So why should NI be an exception? Wanting to download Windows XP for whatever strange reason? Visual Studio 2005 or 2008, just to be a bit obnoxious? It all can be done, but no IT company is trying to make that simple without some special paid support contract. Why? One reason is that people who use those versions will eventually often need some kind of support too and giving even the most simple of support such as license activation or some installation troubles is significantly more effort to do for anything but the last version.

     

    Hello Rolf,

    I am afraid this time I have to disagree. 

    Agree

    Dont get me wrong I think it is okay to pay for Labview, I really "value" the software. I did work with other testsoftware and although it is the price was lower or even free, the time needed to get to a working test-setup without bugs etc. made it more expensive. Thats only the price and with Labview you can do so much more than other testsoftware etc etc. So Yes I see there is a price tag and I think it is justified. 

    Dont agree

    Now for the parts I do not agree with.  Some testmachines can be complex expensive, much much much more expensive than the Labview license. These machines need to be reliable. They are used a lot and you can not simply change your software when you want to. For machines like this I would rather use the Old Labview version thats already running on the machine and use a new version when the total machine is being replaced. The decision what version to use should be up to the company who did build the machine and did buy the license. Not up to NI. If I take a look at the Ni website they are simply making it hard for you to download an old version. They should not do this. Introducing risk in expensive equipment is not wanted. Dont get me wrong I rather build new setups but a lot of times it is not wanted. And Yes I know you could ask cash for install files etc of old versions, but would this make my manager happy when I need to spend extra time on that? Will my manager be extra willing to pay for a new license when I need to spend a lot of time on ridicule subjects like this? Think not. If you add that a lot of managers simply are not able to understand advantages of a good product as Labview. Then you can get to the sum where the manager tells to quit using Labview.  Sorry to say but what I write it is realistic. btw the last time I did install MS windows on a laptop I did not even need a license key. It was already in the EEprom of the laptop. 

     

    To be clear, I understand you need to pay for capable software and support, but downloading a old version you already paid for? This time I think the sales and marketing department of Ni dont get the point of selling software. And yes I understand installing old software can be annoying but if I dont pay for it is not up to Ni. 

     

     

     

     

     

     

     

     

     

     

     

  12. On 4/7/2022 at 8:52 PM, Sam Dexter said:

    ... to provide us with an upgrade to our software which we bought back in 2017. And this is going on for more than a year now.

     

    The story is simple - our company bought a license for NI EMBEDDED CONTROL AND MONITORING SOFTWARE SUITE, USB,

    SPR17, Rev 007, 2017.06.07 and we successfully downloaded the SP1 upgrade later on. The next year we bought a subscription

    to LabView 2018 but did not renew it for 2019 and went back to using 2017. Meanwhile our downloaded SP1 files gone missing.

    "No problem" - we thought - "We'll just go to the NI website and download our SP1."

     

    https://www.ni.com/en-ca/support/downloads/software-products/download.embedded-control-and-monitoring-software-suite.html#306390

     

    Not that fast! To download previous versions of LabView you need an active subscription. OK... So, how do you get missing pieces

    for your software you have a license for if you do not have an active subscription? We contacted NI and their representative Newark

    and asked them for help... Long story short - we are still waiting for a resolution.

     

    Meanwhile, I see no other option but to ask the community for help if NI is so ignorant.

     

    Maybe some of the members can share their LabView 2017 SP1 installation files? I don't think it will be a copyright violation or something -

    what can you do with it without the license? In any case, I would greatly appreciate any input and, maybe, perhaps an advise or a comment.

     

    https://www.ni.com/en-ca/shop/software/products/embedded-control-and-monitoring-software-suite.html

     

    We are looking for:

    1. LabView2017SP1-WinEng

    2. 2017SP1RealTime-WinEng

    3. 2017SP1FPGAModule-WinEng

    4. 2017SP1XILINXCompilationTools

     

    Best Regards.

     

    Hello Sam,

    Did you manage to solve your problem? I aks because I am running into the same problem.  Have got a valid serial number but .... one DVD is missing 

    Same software etc. If you managed to solve the problem can you please tell me how you did solve it?

     

    hope you can help, thanx !

     

     

     

     

  13. So I can give the adres of handle to testDataBlock.dataRecords, like this:

     

    size_t len = offsetof(DataArrayRec, elms) + size * sizeof(DataRecord)
        if (!handle)
        {
            handle = DSNewHandle(len);
      		// testDataBlock.dataRecords = Null 
    		testDataBlock.dataRecords = & handle
      		// testDataBlock.dataRecords != Null 
              
            if (!handle)
                err = mFullErr;
        }
        else
        {
            err = DSSetHandleSize(handle, len);
          	// do I need to repeat this:
          	// testDataBlock.dataRecords = & handle 
          	// or does the adres not change ?    
          
          
        }

     

    and thats it ? 

     

    when I try the code above I get:

    a value of type "DataArrayHdl*" cannot be assigned to an antity of type "DataArrayHdl"

    in the line: 

    testDataBlock.DataRecords = &handle;

    Can anyone tell me what I might be doing wrong ?

     

     

    thanx !!

     

     

     

     

     

     

     

  14. Hello Rolf thank you for your patience,

    I did copy a piece of your code and added some comment, can you please check if I am correct?

     

    static MgErr PostDataMessage(LVUserEventRef rwer, int32_t adapterNr, DataRecord *dataPtr, int32_t numElements)
    {
        // when you create the variable "testDataBlock" everything in the block is made 0 with the use of {0}
      	// dataRecords points to a memory location which has got an unknow size. At this time the pointer is a Null pointer maybe ?
      	DataBlock testDataBlock = {0};
      	// Here you use the function "NumericArrayResize" to resize the memorylocation dataRecords points to,  
        MgErr err = NumericArrayResize(uL, 1, (UHandle*)&testDataBlock.dataRecords, 2 * numElements);
        if (!err)
        {
            testDataBlock.adapterNr = adapterNr;
          	// Here you use MoveBlock to Move the data from the source location where dataPtr points, to the
          	// correct location of testDataBlock. You use the (*(..)) because if you would have used 
          	// *testDataBlock.dataRecords->elms you did point at the beginning of testDataBlock and not to the begining of elms
            MoveBlock(dataPtr, (*(testDataBlock.dataRecords))->elms, numElements * sizof(DataRecord));
            (*(testDataBlock.dataRecords))->dimSize = numElements;
            err = PostLVUserEvent(rwer, &testDataBlock);
            // (this was your comment): PostLVUserEvent  does a deep copy so we need to deallocate this handle to avoid a memory leak
            DSDisposeHandle(testDataBlock.dataRecords);
        }
        return err;

    I hope I start to understand what's going on, then it is easier to remember. 

    How do I change the code when I want to change the array from int int,  to int double? Can I use this piece of code you gave earlier:

     

     if (!handle)
        {
            handle = DSNewHandle(sizeof(DataArrayRec) * (size - 1));
            if (!handle)
                err = mFullErr;
        }
        else
        {
            err = DSSetHandleSize(handle, sizeof(DataArrayRec) * (size - 1));
        }

    and change the adres where  to testDataBlock.dataRecords points ?

    the handle is it easy to explain whats done here is it that the Labview functions add some extra bytes to make every variable the same size e.g. when I have char and a int they ad 3 chars for the char to make the size the same as a int or is there more going on? 

    thank you for the help you are great !!

     

     

     

     

     

  15. Yes! its not 36C anymore!! There is even a cold wind blowing in my room !!

     

    From what I read I am not allowed to use C memory functions, but there is a Labview function called MoveBlock:

    void MoveBlock(ps, pd, size);


    ps      UPtr    Pointer to source.
    pd     UPtr    Pointer to destination.
    size  int32   Number of bytes you want to move.

     

    When I take a look here to see how it is used: 

    https://lavag.org/topic/23177-send-cluster-struct-from-dll-with-a-couple-of-ints-and-a-string-of-text-to-labview/#comment-150817

    I see it is used here:

    {
    		MoveBlock(stringData, LStrBuf(**lvStringHandle), len);
    		LStrLen(**lvStringHandle) = (int32_t)len;
    	}

     

    The pdf "Using External Code in Labview " shows:

    uChar *LStrBuf(s);

    Returns the address of the string data of a long Pascal string, that is, the address of s->str.

    So do I need to do something like:

     

    Datablock testDataBlock;
    
    testDataBlock.adapterNr = 1;
    MoveBlock(*handle, testDataBlock->elms, len);

     

    I'll give it a try, am I going in the correct direction?

     

     

  16. Thanks but how do I get the data in? I get confused because there is another level added by "testStructArray"

    (And it is 36 C in my room now and I am melting )

     

     

     

    TD1 testStructArray;
    testStructArray.AdapterNr = 1;  // give te adapter a number
    
     (*handle)->elm[i].status = status[i];  // in the example above this was used to fill the array elements
    										// what must I do now to get the data in? The "testStructArray" made it a level deeper 

     

    thanx

  17. Hello Rolf, thanx !!

    Yesterday it was late and I was behaving stupidly, I should stop sooner. I did connect the cluster to a create user event and that one to a Reg  event and that one to a function node. I should have connected the cluster directly to the function node that creates the correct C file I think.

     

     

    /* Call Library source file */
    
    #include "extcode.h"
    
    /* lv_prolog.h and lv_epilog.h set up the correct alignment for LabVIEW data. */
    #include "lv_prolog.h"
    
    /* Typedefs */
    
    typedef struct {
    	int32_t Status;
    	int32_t Value;
    	} TD3;
    
    typedef struct {
    	int32_t dimSize;
    	TD3 elt[1];
    	} TD2;
    typedef TD2 **TD2Hdl;
    
    typedef struct {
    	TD2Hdl DataRecord;
    	int32_t AdapterNr;
    	} TD1;
    
    #include "lv_epilog.h"
    
    void funcName(TD1 *TestInput);
    
    void funcName(TD1 *TestInput)
    {
    
    	/* Insert code here */

    This makes sense If I look at it. Thanx again 🙂

     

     

     

     

     

  18. Hello Rolf, thanx for all the help you give,

     

    This start working fine now!! It has been a great learning experience for me !

    (1) The next question might be kind of silly but how do I change the 1D array to a 2D array ?  

     

     (2)With one adapter everything seems to work out okay! Now I got the question to make it work for multiple adapters. I can receive the data in my wrapper from multiple adapters. So the question is: How can I put the 1D array in a cluster with another int to indicate which adapter the array comes from? Ho do I change the C code so Labview can receive something like this:

     

     1427597583_Knipsel-kopie.PNG.3ae2e3950cc102cfac34558e7100b4ba.PNG

     

    Thanx !!

     

     

     

     

     

  19. 16 hours ago, Rolf Kalbermatter said:

    You clearly have not much C programming experience. Which of course is a very bad starting point to try to write C code that should then interoperate with LabVIEW.

    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!

     

     

     

  20. 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;
    }

     

     

     

     

     

     

     

     

     

     

     

×
×
  • Create New...

Important Information

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