skyfox Posted March 6, 2023 Report Posted March 6, 2023 Is it possible to enumerate all the files in the SD card get their names into a string array? File names will have the format... RUN0001 data.csv RUN0002 data,csv ..... RUN9999 data.csv I want to be able to first find the # of data files (get a count) and load the first ten file names it finds into an array and display those names on the HMI. User then presses a button on HMI and PLC gets the next 10 filenames to displays and so forth. All file names on the card will have the same name format (fixed length file names). Can this be done with Sysmac studio and NX1P2? I did not find any SD function blocks that had this capability. Cheers. Quote
Str8jCkt Posted March 8, 2023 Report Posted March 8, 2023 I can send you sample Omron NX code that will generate a list of the files in a defined directory on the SD Card and put them into an array of strings. I also have a variable that will return the file count for you. I originally did the code in an NX102-1220 to test and then changed the device to an NX1P2. The only problem would be your request for 1 to 9999 files. With the NX102-1220 I set the read list array size to [0..10000] and it will work but with the NX1P2 there is not sufficient memory in the PLC to support those large arrays. I can limit the array size to [0..2000] and use up about half the PLC memory in the NX1P2. So depending on how big the rest of your program is that size may still not be practical. I have tried many times but for some reason I have never been able to attach any files on this Forum. I always get an upload failed message. Just let me know if you want the sample code for getting the list of files. If you send me a message I can email you the file. ON another note related to one of your posts about SD Card size, the last few years I have been using 16 GB and 32GB SanDisk Ultra (120 MB/s) SD cards on NJ and NX PLCs. I used a 32 GB in the NX102-1220 for testing the code I just did for returning the file list. Quote
skyfox Posted March 9, 2023 Author Report Posted March 9, 2023 Str8jCkt, That would be awesome and thank you. My NXIP2 Array will still be say 20 elements. SD Card can have 1000 files; I only want to load 20 file names at a time using the same array. I will send you my email address as soon as I figure out how. Thank you so much. Your help is greatly appreciated. Cheers. Quote
AlphaPapa Posted February 15, 2024 Report Posted February 15, 2024 Hi @Str8jCkt, I don't suppose you still have that sample code for listing files? I'd be really interested in seeing it, I'm working on something now that needs this exact functionality. Quote
Str8jCkt Posted February 15, 2024 Report Posted February 15, 2024 @AlphaPapa here is the file i had reated. The idea is to turn on the PLC ftp server. Then have the PLC ask itself what files are on the server directory (SD Card). R&D - ReadSDFileList.smc2 Quote
pturmel Posted February 15, 2024 Report Posted February 15, 2024 2 hours ago, Str8jCkt said: The idea is ... Clever! Quote
photovoltaic Posted February 15, 2024 Report Posted February 15, 2024 3 hours ago, Str8jCkt said: @AlphaPapa here is the file i had reated. The idea is to turn on the PLC ftp server. Then have the PLC ask itself what files are on the server directory (SD Card). R&D - ReadSDFileList.smc2 You can also use the loopback address (127.0.0.1) and this will make it so that changing your PLC's IP address won't break your code. Quote
AlphaPapa Posted February 16, 2024 Report Posted February 16, 2024 Thanks for sharing. After i saw you're post i was wondering how on earth you'd done it and then had the same idea, also using the loopback address. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.