Main Site Documentation

Reading Data from a USB


#1

Hi All,

I am using the ALFAT-USB and it is working very nicely. I have “saving” to the USB working 100% and also reading the saved data back from the USB working, however the manner which I am saving the data on the USB is a little complicated as I am using a Real time clock saving the the file to avoid over writing my text files saved in the folder

I am saving the file as shown below

USB04537 I am using the date/minute and sec as shown in the bold/strong text USB04537 as then I know I can overwrite or get duplicates.

The challenge come is when I have multiple files in the folder, how can I read one by one?, or is there an easier means on reading this data back?, current I do the following:

“I U0:”,10
“J”, 10
“K U0:”, 10
“K U0:”, 10
“N”, 10
“N”, 10
“N”, 10
“O 0R>U0:\BUCKLE2\U”, STR NBUFF\8,".TXT", 10
“O 1R>U0:\BUCKLE2\U”, STR NBUFF\8,".TXT", 10
“R 0^>62”, 10
“C 0”

the above works 100%, but I am not sure what to do with the next 10 files in the folder?

I have written my code in Pic Basic Pro

Regards,

Gavin


#2

sorry, can you in pseudo-code try to tell us what you need to achieve? Its not clear what you’re having issues with.


#3

Hi Brett,

Thanks for the reply,

My apologies for the poor explanation, I am just wanting to know how I can read the data back multiple saved text files in a single folder, please see attached, how do I read these text files one by one?

Regards,

Gavin


#4

You can use the @ command to return a directory listing, and use N to cycle through results. Or collect them in your local microcontroller logic, and iterate through them.


#5

Hi Brett,

I noticed the N commands send the amount of files in the folder but but you need to keep pressing the N function to read through all. I have assumed you need to do the following for each text file:

I U0:
@ U0:\OVERRIDE_001
N
N
N (this is the 1st N which feeds the first text file)
O 0R>U0:\OVERRIDE_001\USB044329.TXT
O 1R>U0:\OVERRIDE_001\USB044329.TXT
R 0^>94
C 0

and then repeat and use the N functions 4 times then to read the next file, and 5 x N’s to read the 3rd file and so forth, is there not a faster means of doing this?


#6

You must be doing something wrong. But let me ask, is this a new commercial design you are working on?


#7

Make new folder and try again, probably there are some hidden files.


#8

Yes this is something new we are busy with, we can write no problems to the ALFAT, reading is also ok but just with one file per folder, is the sequence we are using correct?


#9

Hi Dat,

There should not be any hidden files, this is “saved” data from what the Alfat has saved via the PIC MCU


#10

Is there no single command to “flush out” all files?


#11

What do you mean “just with one file per folder”?

As I see it wasn’t connect, look like you opened 2 handle for same file.
I believe you had some error returned.

No, just single handle. You can program the master to do that.


#12

Hi Dat, I can read back one file below with no errors using the format below

I U0:
@ U0:\OVERRIDE_001
N
N
N (this is the 1st N which feeds the first text file)
O 0R>U0:\OVERRIDE_001\USB044329.TXT
O 1R>U0:\OVERRIDE_001\USB044329.TXT
R 0^>94
C 0

do you see issues above?


#13

If you type the command via serial manually then yes, you have to look at the return and open single file, because there is no command to list all files out.

But for the real master application, I believe there is error code that tell you that end of folder or result was file or folder.

Idea is

while (send N return != end of folder) 
{
      if N return == file
         Do Open for Read  
}```

#14

Dat, my apologies, everything is coded via the serial port?, I am reading and sending via the serial port so I don’t have the luxury of the above


#15

Here is the answer why you only get file after send N command 3 times

So keep sending N until get error = 0x04 (end of folder) and only select error == 0x20 as file.

Also I forget one thing, for reading we can open same file multi time as Windows does.


#16

Unless you are MANUALLY typing the read commands via a terminal program on your PC, you do have the luxury here - you should add this in your code