02-11-2018 03:42 AM
Hi guys,
I need your opinion on an File I/O operation that I need to do. ( Just to clarify - my code is working without any issue but seeking your opinion to see if there are better ways of doing this)
Here is what I need to do.
I have a hex file and I need to append a new line to a line that starts with ":09000000". This line could be anywhere in the hex file. So, what I did was, I loop through the lines and till I find ":09000000" and breakout of the loop, offset the file pointer to the beginning of that line by providing the amount of offset bytes.
Then write to the file (based on the bytes). Code is below.
Your feedback would be much appreciated.
Thanks.
02-11-2018 03:43 AM
Hi guys,
I need your opinion on an File I/O operation that I need to do. ( Just to clarify - my code is working without any issue but seeking your opinion to see if there are better ways of doing this)
Here is what I need to do.
I have a hex file and I need to append a new line to a line that starts with ":09000000". This line could be anywhere in the hex file. So, what I did was, I loop through the lines and till I find ":09000000" and breakout of the loop, offset the file pointer to the beginning of that line by providing the amount of offset bytes.
Then write to the file (based on the bytes). Code is below.
Your feedback would be much appreciated.
Thanks.
02-11-2018 09:43 AM
The Get File Position doesn't need to be in the loop. Moving it to the right, outside the loop makes more sense. I doubt it will effect performance much, but it would be clearer to read by others or future you.
You might need a better fall back mechanism. What happens if the string is not found?
Oh, and I would straighten those wires. But that's just me. (I know it's not just me, but suit yourself.)
02-11-2018 02:54 PM
I'm conflicted. On the one hand, I usually yell and scream "Attach your code, not a picture!", as that lets us "play with the code", "fix" it (keeping the wires running straight, doing a "cleanup" of code -- you might try the Broom item on the Menu bar), and even test out other algorithms. On the other hand, if your code has sub-VIs, you'd need to attach them as well (compressing a Project Folder will usually do the trick), and if you are running a version of LabVIEW we don't have (I, for example, can't get LabVIEW 2017 to install without killing all of my LabVIEW development, and sometimes killing my entire Windows installation), we can't even open it. Oh, well.
So here's just an observation for you to consider. It appears that when you find the line that starts ":090000000", you back up 29 bytes (why 29?), append a new line, and terminate the file, discarding what was there. The following seems to me to be logically simpler (though it might not be as fast, and might have "memory" problems, depending on the size of your file):
Here's one way to do the search:
Bob Schor
02-11-2018 04:19 PM - edited 02-11-2018 04:20 PM
Point taken weibe@CRAYA ! Thanks for raising it.
02-11-2018 04:28 PM
Thanks Bob for your input. Can't say your solution didn't cross my mind. The reason why I decided against it, is because I was little worried about data corruption when writing back and forth to a file(large amount of data). The hex file goes to a microcontroller straight away after this file operation, therefore couldn't take a risk. Anyway, thanks for sharing your thought and I'll remember to attach the vi next time.
02-12-2018 03:19 AM
> On the one hand, I usually yell and scream "Attach your code, not a picture!"
I don't mind images, as long as they are embedded in the mail. An attached image is the worst of both worlds. If I need to download it, it might as well be a VI...
On a tablet (while traveling or while watching TV), an image is convenient...