The forum is to discuss topics related to robotics, like building robot, controlling it, its software and hardware, etc.
by andrew.kirillov » Tue Jul 05, 2011 4:17 pm
Now I am totally lost ... Piero wrote:When I turn on the brick and I launch the program, I have the complete list of programs, but, for retrieve another time the complete list, i have to turn off and turn on again the brick
Why do you need to turn off/on the brick to get the list of files again? If you want to search some files on your PC, do you do the same - off/on every time? Piero wrote:My question at this point is: how I can have EVERY time I lauch my program, the complete list from the FIRST file?
Do you want to get list off all files? Then do Find First command and then repeat Find Next till the search is done. If you want to do all the same from the first file, then do Find First command again and then continue with Find Next ...
-

andrew.kirillov
- Site Admin, AForge.NET Developer
-
- Posts: 3451
- Joined: Fri Jan 23, 2009 9:12 am
- Location: UK
by Piero » Tue Jul 05, 2011 5:34 pm
Mmmhhhh... this is the code: - Code: Select all
if (portaSeriale.IsOpen) { listBox1.Items.Clear(); button5.Enabled = false; button3.Enabled = false;
byte[] comando = new byte[22];
// Find First
// I set first 2 bytes comando[0] = (byte)0x01; comando[1] = (byte)0x86; // I send first 2 bytes byte[] messageLenght = new byte[2] { (byte)comando.Length, 0 }; portaSeriale.Write(messageLenght, 0, 2); // I send message System.Text.ASCIIEncoding.ASCII.GetBytes("*.rxe", 0, 5, comando, 2); portaSeriale.Write(comando, 0, comando.Length); // I read reply int daLeggere = portaSeriale.ReadByte(); portaSeriale.ReadByte(); byte[] risposta = new byte[daLeggere]; int lunghezza = portaSeriale.Read(risposta, 0, daLeggere);
string numErrore = ""; // For all files in the brick while (numErrore != "135") { // Find Next
// I set first 2 bytes comando[0] = (byte)0x01; comando[1] = (byte)0x87;
// I send first 2 bytes messageLenght = new byte[2] { (byte)comando.Length, 0 }; portaSeriale.Write(messageLenght, 0, 2); // I send message System.Text.ASCIIEncoding.ASCII.GetBytes("*.rxe", 0, 5, comando, 2); portaSeriale.Write(comando, 0, comando.Length); // I read reply daLeggere = portaSeriale.ReadByte(); portaSeriale.ReadByte(); risposta = new byte[daLeggere]; lunghezza = portaSeriale.Read(risposta, 0, daLeggere); // I contro if there are others files numErrore = risposta[2].ToString();
// I convert reply form bytes to string and I write it in the listbox nomeFile = System.Text.ASCIIEncoding.ASCII.GetString(risposta, 4, 15); string estensione = "rxe"; Boolean presente = nomeFile.Contains(estensione); if (presente == true) { listBox1.Items.Add(nomeFile); } } button5.Enabled = true; } else { MessageBox.Show("Non connesso", "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error); }
With this code, if the brick was turned on for the first time, I retrieve the complete list of programs (.rxe). If I launch this command another time, I don't retrieve any files. I don't understand if there is a pointer to reset etc...
-
Piero
-
- Posts: 19
- Joined: Mon Dec 13, 2010 3:52 pm
by andrew.kirillov » Wed Jul 06, 2011 8:44 am
I am not sure how the code works at all, since it seems to be wrong. I would suggest you taking a look at NXT documentation first ....
You send command 0x86 (find fisrt) - OK, fine. Then you get reply and it seems you just ignore it. The "find first" command gives you seacrh handle - where do you use it? Instead of using search handle, you continue sending your "*.rxe" wildcard again and again. But command 0x87 does not need it at all. All it needs is just a search handle.
-

andrew.kirillov
- Site Admin, AForge.NET Developer
-
- Posts: 3451
- Joined: Fri Jan 23, 2009 9:12 am
- Location: UK
by Piero » Wed Jul 06, 2011 12:24 pm
I've tried to set the byte 2 in the Find Next with the byte 3 of the reply of Find First (not in the posted code, in others experiments). In the official documentation is reported this. Now, I've used the handle number of the reply of the Find First in Find Next, BUT, I've the complete list ONLY the first time. If i want to retrieve the files name another time, i have to turn off and turn on the brick. This is the point that I don't understand. Any time I've to start from the FIRST file, and with Find First I retrieve the first file, ok. When I launch Find Next command (if it isn't the first time I execute command), Next Command starts in a point that it isn't the begin. I've red documentation, excuse me but I don't understand what is the error... 
-
Piero
-
- Posts: 19
- Joined: Mon Dec 13, 2010 3:52 pm
by Piero » Thu Jul 07, 2011 7:31 pm
Now the program is done, this is the correct code for the files list in the brick: - Code: Select all
try { if (portaSeriale.IsOpen) { listBox1.Items.Clear(); button5.Enabled = false; button3.Enabled = false;
byte[] comando = new byte[22];
// Find First
comando[0] = (byte)0x01; comando[1] = (byte)0x86; byte[] messageLenght = new byte[2] { (byte)comando.Length, 0 }; portaSeriale.Write(messageLenght, 0, 2); System.Text.ASCIIEncoding.ASCII.GetBytes("*.rxe", 0, 5, comando, 2); portaSeriale.Write(comando, 0, comando.Length); int daLeggere = portaSeriale.ReadByte(); portaSeriale.ReadByte(); byte[] risposta = new byte[daLeggere]; int lunghezza = portaSeriale.Read(risposta, 0, daLeggere); string nomeFile = System.Text.ASCIIEncoding.ASCII.GetString(risposta, 4, 15);
string numErrore = ""; comando[2] = risposta[3]; while (numErrore != "135") { // Find Next
comando[0] = (byte)0x01; comando[1] = (byte)0x87;
messageLenght = new byte[2] { (byte)comando.Length, 0 }; portaSeriale.Write(messageLenght, 0, 2); portaSeriale.Write(comando, 0, comando.Length); daLeggere = portaSeriale.ReadByte(); portaSeriale.ReadByte(); risposta = new byte[daLeggere]; lunghezza = portaSeriale.Read(risposta, 0, daLeggere); numErrore = risposta[2].ToString();
nomeFile = System.Text.ASCIIEncoding.ASCII.GetString(risposta, 4, 15); string estensione = "rxe"; Boolean presente = nomeFile.Contains(estensione); if (presente == true) { listBox1.Items.Add(nomeFile); } } button5.Enabled = true; } else { MessageBox.Show("Non connesso", "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception) { MessageBox.Show("Si è verificato un errore", "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error); }
Thank you Andrew for your help!
-
Piero
-
- Posts: 19
- Joined: Mon Dec 13, 2010 3:52 pm
Return to Robotics
|

|