Retrieving and storing serial string data to an array
Hello,
I'm working on a small project where I'm interfacing with the uMP3 player. I would like to issue a serial command ("FC L") and receive a directory listing into an array. The data (filenames) received should be separated by {CR}. I'm having trouble getting past this. I would really appreciate if anyone has sample SPIN code to perform this type of function.
The uMP3 datasheet can be found here (http://www.roguerobotics.com/files/ump3/documentation/UMP3-110-A1-102.pdf)
Thanks in advance!
-Justin
I'm working on a small project where I'm interfacing with the uMP3 player. I would like to issue a serial command ("FC L") and receive a directory listing into an array. The data (filenames) received should be separated by {CR}. I'm having trouble getting past this. I would really appreciate if anyone has sample SPIN code to perform this type of function.
The uMP3 datasheet can be found here (http://www.roguerobotics.com/files/ump3/documentation/UMP3-110-A1-102.pdf)
Thanks in advance!
-Justin
Comments
First, have you already been trying to get it to work and have some code? If so, please post what you have done so far. Next, is there a maximum number of file names or could it be that the file names could be grow and you can't determine the number? The reason is that if you want to store the file names into an array, you will have to consider that at some point there may not be enough memory to temporarily hold all the names at once. If that is the case, you would need to determine what is the purpose of having the list held at once, and if it can be that you could read in some amount of names based on array size, do something with that info, then read more. Are the file names in an 8.3 format or can they exceed that size? (12345678.123)
There are several serial objects that will make sending the get list command and then reading the data back with the CR delimiter, that part is very east. I am sure that others will have good suggestions on this as well. But first things first, can you explain what the goal of the list is, and then someone can best show an example of how to manage the data. Can the uMP3 allow getting a partial list, pause, then continue where it left off reading?
http://obex.parallax.com/objects/156/
I have never used the uMP3, probably others here have and will have more input.
I am using that object for other commands, but it doesn't have a file listing command. Are there any serial communication objects that will store the received data in an array (using CR as a delimiter)?
Thanks!
I'm not sure what you mean by "received data". Is this data you're typing in? Could you have your list of songs hard coded into the program in the DAT section?
Resave the uMP3 object after adding this so the main program can use the new method.
Add this method to the main program as the first method ( uMP3 test )
Add to uMP3 obj and save it.
Duane,
I would like to receive the list from the SD Card connected to the uMP3 device. I could store the list with predetermined song names, but that is my backup plan if I cannot retrieve a dynamic file list from uMP3.
T Chap,
Thanks for writing this test code. I appreciate your time looking at this. I have tried the test code and the output so far is unreadable. I will keep working on it. I have tried reading different directories, just the root, and changing filename lengths, and number of files. It looks like it may also be due to limitations in "Serial.RxStrTime". I'll look more tomorrow and let you know. Thanks for the help!
-Justin
The uMP3 object uses Extended_FDSerial. That has RxStrTime (ms,stringptr) : Value | ptr, temp and RxTime(ms).
The RxTime method only has one parameter, which is why I modified your code above to use RxStrTime. The uMP3 player manual also states it first returns a space character, then starts transmitting the file list with CR delimiters.
So I guess I have 2 questions.
If I use RxTime, how should I rewrite the code for only one parameter? Or should I use RxStrTime...
Is the space character causing me an issue?
I really appreciate your time T Chap. I have a bit of a learning curve, so I understand if you cannot help further. I can test with a static file naming system if I cannot get a dynamic list. Retrieving the listing was my preferred method.
Thanks!
-Justin
What you want to accomplish is easy, just takes a little time to sort it out, and there is a learning curve which is very rewarding. Plenty of the other guys on here could write something in a few minutes to solve your concept and it would be slick right away, but I have to spend time trying to figure things out as I go(referred to as a 'hack'). Most people on the forums know that it is best for the new guys to dive in, try some things, post what they have, and hash it out part by part, which enhances the learning process. I would recommend that you see what results you get from the above, post the results. But also post your methods and/or spin files here, plenty of the more experienced guys here will then have much faster and more frequent input if they can see the code 'at a glance'.
Side note: The code I posted does not parse out any characters, it is simply to attempt to get a response and show anything that resembles a file name. It may be a good idea to go ahead and incorporate the PST(parallax serial terminal) as an extra display for debug purposes, so you can see the responses on the PC. It is the same exact method of serial.str(xxxxxxxx) except you are replacing the LCD with the PST object ie pst.str(xxxxxx).
Did you get the uMP3.status or uMP3.idle to get a response from the device to make sure there is actual communication? Have you actually gotten the Prop to make it play a song? Just want to make sure the bauds are right. I assume that you have a Prop board that does have a crystal(5m) so that the Prop is running at the right speed set in the CON.
One thing I just noticed, the code for that demo is for 4x20 LCD. The example to read 64 bytes and display it is for a 2x16 display. You need to specify which LCD you have. If you have the 4x20 then you could display 80 characters, so you could set the the array to 80, change the repeat serial.rxtime to 79 for a total of 80 bytes it can read and display at once.
I've spent more time on this and here is what I have so far. I ended up using the BS2 object in the main program to receive the data. I know it is not the best way to do this, but it works.
I am also able to play songs using the ump3 object.
In the ump3 object
In the main program
This gives me the first file in the listing. Can you help me store the data from @listarray into another array SongList[x], so I can loop through file listing, increase x, and store the string to the next array element?
Thanks,
Justin