07-08-2020 08:21 AM
Hello,
I'm building this simple CNC gcode sender and have recently refactored it and fixed a bunch of problems that folks such as @GerdW and others have suggested, it was a huge help and now the code is working much better. However when I run the code for a long while (for example when reading in a full gcode file with thousands of entries), it eventually will crash. Generally it's a no warning shutdown of the whole NI environment, sometimes it has said it ran out of memory without much more detail.
I am figuring it's something having to do with not handling memory very well and am hoping you might help me track down what I'm doing poorly?
Thanks for the help!
07-08-2020 08:52 AM
Hi JFWM,
again you are uploading VIs using the latest LabVIEW version. By downconverting you can reach far more people to help you… (I still prefer LV2017.)
More suggestions:
07-08-2020 09:28 AM
Yep, thanks, here it is in LV 15, zipped.
07-08-2020 09:48 AM
Hi JFWM,
@JFWM wrote:
am hoping you might help me track down what I'm doing poorly?
Still bad code:
Do you really need to plot all coordinates? How many points do you collect?
07-08-2020 11:49 AM
In your "Run GCode File" case there is potential for the X, Y and Z vector arrays to grow unbound. They are also duplicated in the plot VI so there are 6 arrays that grow every iteration unbound. That could eat up memory pretty quickly.
Also it looks like your "Open GCode File" case is.... wrong. The for loop makes no sense. Do you really want an array element for every character in the file?
07-08-2020 11:57 AM
I can add more subVIs (am doing so now), didn't know there was as a style guide so I'll look into that, and have been researching BytesAtPort and still am unclear as to how it should be used properly for this scenario. If you have any more info on that it would be helpful.
This is all very good, thank you. The last major LV build I did was using LV 7 + IMAQ Vision for a laser imager that found defects in solar cells and then excised them. Which was night and day compared to the LV6 on mac I learned on. It's been quite a while since then...
07-08-2020 11:59 AM
Ah... so when it comes to memory you're saying having duplicative arrays that can grow infinitesimally large is a problem?! Thanks. 🙂
07-08-2020 12:26 PM
Even if they aren't duplicated, there is no limit on how large they can be. Duplicated just means you will run out of memory twice as fast. As I mentioned before I also think you are converting the file into an array of strings incorrectly. You are adding an element for every character in the file. That array also determines how big those vector arrays will be.
Here's what you have versus what I think you want to be doing (Array 2)
The bytes at port is usually the wrong way to do serial communication. If you can, using the termination character is a much better way to do things. When used, the VISA read will read until it sees the termination character or it exceeds the timeout set. Using bytes at port doesn't guarantee a complete message. It may depend on the device you are talking too, but it looks like you append a carriage return when you send a message, so I would be surprised if it is not sending one back at the end of it's messages. Many devices use carriage return and line feed so the default line feed termination character might work just fine. The manual for the device should specify.
With the termination character working you can remove all the Bytes at port property nodes and data coming from the visa reads will contain a complete message.
07-08-2020 01:07 PM
Gotcha. You're right on the 'open g code section', I just opened a bunch of test files and on a few of them your code churns it out correctly when my existing did not. Thanks!
I try removing all the bytes at port and seeing how it performs. Thanks again!
As for the XYZ vectors, how can I minimize memory usage if I hold it true that they should be expandable to deal with whatever size thing they may see? Or do I just give a cap and start overwritting points?
Also, on a modern desktop computer how many points are too many in a 3D plot?
07-08-2020 01:41 PM
Well each double is 8 bytes, there are 6 arrays so that's 48 bytes per iteration. You should be able to do almost 21,000 iterations before using a Gig. Not sure what a reasonable number would be in your case, but I would probably cap it at least at that. I doubt your plot is going to make any sense at that point anyway.