Forum
List and select program
Quote from Matteo Berettam on November 19, 2020, 10:07 amHi, i've found your guide very usefull, i'm new on Focas Library, and i can't find any documentation about list all the loaded NC programs, and select one as the current one.
Someone know if it's possible to do this with Focas
Thank you
Hi, i've found your guide very usefull, i'm new on Focas Library, and i can't find any documentation about list all the loaded NC programs, and select one as the current one.
Someone know if it's possible to do this with Focas
Thank you
Quote from Versex on November 19, 2020, 11:05 amHi Matteo,
Yes, it is possible to get a list of programs that are currently stored in the control. To do this you need to look at the code below. It can be a bit confusing at first. It basically gets the information from the current directory and the subdirectories. Then it will use the information about how many files are in the directories to iterate through them. You will pull each file one at a time and read the name from it and store it in the list. Let me know if you need anything else.
object dir = "";
// Obtain the current directory
_ret = Focas1.cnc_rdpdf_curdir(Fanuc.Handle, 1, dir);// Obtain the subdirectories
_ret = Focas1.cnc_rdpdf_subdirn(Fanuc.Handle, dir, pdf_nfil);short reqCount = 1;
Focas1.IDBPDFADIR pdfadirin = new Focas1.IDBPDFADIR();
Focas1.ODBPDFADIR pdfadirout = new Focas1.ODBPDFADIR();
pdfadirin.path = (string)dir;
pdfadirin.req_num = 1;
pdfadirin.size_kind = 2;
pdfadirin.type = 1;
var counter = 0;while (counter != pdf_nfil.file_num + 1)
{
short ret = Focas1.cnc_rdpdf_alldir(Fanuc.Handle, ref reqCount, pdfadirin, pdfadirout);if (pdfadirout.data_kind == 1 && new string(pdfadirout.d_f.ToArray()))
{
programList.Add(new string(pdfadirout.d_f.ToArray()));
}pdfadirin.req_num++;
counter++;
}
Hi Matteo,
Yes, it is possible to get a list of programs that are currently stored in the control. To do this you need to look at the code below. It can be a bit confusing at first. It basically gets the information from the current directory and the subdirectories. Then it will use the information about how many files are in the directories to iterate through them. You will pull each file one at a time and read the name from it and store it in the list. Let me know if you need anything else.
object dir = "";
// Obtain the current directory
_ret = Focas1.cnc_rdpdf_curdir(Fanuc.Handle, 1, dir);// Obtain the subdirectories
_ret = Focas1.cnc_rdpdf_subdirn(Fanuc.Handle, dir, pdf_nfil);short reqCount = 1;
Focas1.IDBPDFADIR pdfadirin = new Focas1.IDBPDFADIR();
Focas1.ODBPDFADIR pdfadirout = new Focas1.ODBPDFADIR();
pdfadirin.path = (string)dir;
pdfadirin.req_num = 1;
pdfadirin.size_kind = 2;
pdfadirin.type = 1;
var counter = 0;while (counter != pdf_nfil.file_num + 1)
{
short ret = Focas1.cnc_rdpdf_alldir(Fanuc.Handle, ref reqCount, pdfadirin, pdfadirout);if (pdfadirout.data_kind == 1 && new string(pdfadirout.d_f.ToArray()))
{
programList.Add(new string(pdfadirout.d_f.ToArray()));
}pdfadirin.req_num++;
counter++;
}
Quote from Matteo Berettam on November 19, 2020, 12:29 pmThank you so much, but return empty, it's possible that after this method
Focas1.cnc_rdpdf_curdir
varible dir still string empty?
Thank you so much, but return empty, it's possible that after this method
Focas1.cnc_rdpdf_curdir
varible dir still string empty?
Quote from Versex on November 19, 2020, 1:35 pmI am sorry... I messed that up. The dir variable should be something like //CNC_MEM/USER/PATH1/ or //DATA_SV/ if you have a dataserver on your machine. That should be equal to where ever your programs are stored.
I am sorry... I messed that up. The dir variable should be something like //CNC_MEM/USER/PATH1/ or //DATA_SV/ if you have a dataserver on your machine. That should be equal to where ever your programs are stored.
Quote from Matteo Berettam on November 20, 2020, 3:45 amPerfect thank you, work like a charm.
To select working program i could use this function cnc_pdf_slctmain right? It receive the path of the program
Perfect thank you, work like a charm.
To select working program i could use this function cnc_pdf_slctmain right? It receive the path of the program
Quote from Paul Eick on June 10, 2021, 5:26 amHi , i'm a newbie to programming and have found your site a great start for fanuc focas.
I tried to use the above code to read the directories, but the section of code:
if (pdfadirout.data_kind == 1 && new string(pdfadirout.d_f.ToArray()))
reports message about, CS0019 operand && cannot be applied to bool and string
Have I missed something?
Hi , i'm a newbie to programming and have found your site a great start for fanuc focas.
I tried to use the above code to read the directories, but the section of code:
if (pdfadirout.data_kind == 1 && new string(pdfadirout.d_f.ToArray()))
reports message about, CS0019 operand && cannot be applied to bool and string
Have I missed something?
Quote from Versex on June 10, 2021, 8:33 amHi Paul,
So what is happening is that an "if" statement only works on boolean statements. So the first statement "pdfadirout.data_kind == 1", is either true or it is false, which makes that a boolean statement.
However, the second statement "new string(pdfadirout.d_f.ToArray())" does not result in a true or a false. All that does is take the value you feed it, and spit out a string representation of that input. So this means that you cannot use this in the if statement.
Now, with that in mind, I believe what you may be attempting to do is something like this "new string(pdfadirout.d_f.ToArray()) == "some_program_name.nc"". This will result in a boolean statement because you are making a comparison of two objects. So you might be able to check for any file it finds that ends in .nc for instance by doing "new string(pdfadirout.d_f.ToArray()).EndsWith(".nc")" or something like that.
I hope this was helpful, and if you need any further help, please let me know.
Hi Paul,
So what is happening is that an "if" statement only works on boolean statements. So the first statement "pdfadirout.data_kind == 1", is either true or it is false, which makes that a boolean statement.
However, the second statement "new string(pdfadirout.d_f.ToArray())" does not result in a true or a false. All that does is take the value you feed it, and spit out a string representation of that input. So this means that you cannot use this in the if statement.
Now, with that in mind, I believe what you may be attempting to do is something like this "new string(pdfadirout.d_f.ToArray()) == "some_program_name.nc"". This will result in a boolean statement because you are making a comparison of two objects. So you might be able to check for any file it finds that ends in .nc for instance by doing "new string(pdfadirout.d_f.ToArray()).EndsWith(".nc")" or something like that.
I hope this was helpful, and if you need any further help, please let me know.
Quote from Paul Eick on June 14, 2021, 10:43 amHi,
Thank you for your prompt reply, what I have been trying to do is get the "comment" of the main program running in MEM.
Started with the main program running number, but no comment:
Focas1.ODBPRO pro = new Focas1.ODBPRO();
short ret = Focas1.cnc_rdprgnum(FlibHndl, pro);if (ret == 0)
{
MainProgramNumber.Text = Convert.ToString(pro.mdata);
}
Tried this to read program number and comment, Using :
Focas1.PRGDIR3_data prg = new Focas1.PRGDIR3_data();
But it's reading a different folder. I get program numbers and comments, but not the main program because it's not in the right directory.
Looks like at least 4 folders have programs in them.
I did move the current program into the read folder, Compared the MainProgramNumber to the list to pick up it's comment..
using:
ret = Focas1.cnc_rdpdf_alldir(FlibHndl, ref reqCount, pdfadirin, pdfadirout);
listBox1.Items.Add(new string(pdfadirout.d_f.ToArray()));
Gives me program numbers, relative to the directory I select.
Thank you for your help.
Hi,
Thank you for your prompt reply, what I have been trying to do is get the "comment" of the main program running in MEM.
Started with the main program running number, but no comment:
Focas1.ODBPRO pro = new Focas1.ODBPRO();
short ret = Focas1.cnc_rdprgnum(FlibHndl, pro);
if (ret == 0)
{
MainProgramNumber.Text = Convert.ToString(pro.mdata);
}
Tried this to read program number and comment, Using :
Focas1.PRGDIR3_data prg = new Focas1.PRGDIR3_data();
But it's reading a different folder. I get program numbers and comments, but not the main program because it's not in the right directory.
Looks like at least 4 folders have programs in them.
I did move the current program into the read folder, Compared the MainProgramNumber to the list to pick up it's comment..
using:
ret = Focas1.cnc_rdpdf_alldir(FlibHndl, ref reqCount, pdfadirin, pdfadirout);
listBox1.Items.Add(new string(pdfadirout.d_f.ToArray()));
Gives me program numbers, relative to the directory I select.
Thank you for your help.