Fix Fanuc File Management
This commit is contained in:
@@ -1177,39 +1177,45 @@ namespace CMS_CORE.Fanuc
|
||||
nReturn = Focas1.cnc_upstart4(nLibHandle[0], 0, partProgramPath);
|
||||
|
||||
//Throw Exception if there's an error
|
||||
if (nReturn != 0)
|
||||
ThrowNCException(NC_PROD_ERROR, nReturn);
|
||||
ErrorHandler(NC_PROD_ERROR, nReturn);
|
||||
|
||||
do
|
||||
{
|
||||
// Local buffer
|
||||
char[] tmpContentBuffer = new char[256];// TODO find function to read size file
|
||||
char[] tmpContentBuffer = new char[256]; // TODO find function to read size file
|
||||
|
||||
// Read file
|
||||
nReturn = Focas1.cnc_upload4(nLibHandle[0], ref lenght, tmpContentBuffer);
|
||||
|
||||
// If File ended
|
||||
if (nReturn == (short)Focas1.focas_ret.EW_RESET)
|
||||
switch(nReturn)
|
||||
{
|
||||
fileEnded = true;
|
||||
case (short)Focas1.focas_ret.EW_RESET:
|
||||
{
|
||||
fileEnded = true;
|
||||
}break;
|
||||
case (short)Focas1.EW_OK:
|
||||
{
|
||||
// Add the characters into string with all the content
|
||||
partProgramContent += new string(tmpContentBuffer);
|
||||
}break;
|
||||
case (short)Focas1.focas_ret.EW_BUFFER:
|
||||
{
|
||||
continue;
|
||||
}break;
|
||||
default:
|
||||
{
|
||||
ThrowNCException(NC_PROD_ERROR, nReturn);
|
||||
}break;
|
||||
}
|
||||
else if (nReturn == (short)Focas1.focas_ret.EW_OK)
|
||||
{
|
||||
// Add the characters into string with all the content
|
||||
partProgramContent += new string(tmpContentBuffer);
|
||||
}
|
||||
// TODO
|
||||
//else if (nReturn != (short)Focas1.focas_ret.EW_BUFFER && nReturn != Focas1.focas_ret.EW_LENGTH) // case 10 = EW_BUFFER = wait until the buffer contains data
|
||||
//{
|
||||
// ThrowNCException(NC_PROD_ERROR, nReturn);
|
||||
//}
|
||||
} while ((nReturn == (short)Focas1.focas_ret.EW_OK || nReturn == (short)Focas1.focas_ret.EW_BUFFER) && !fileEnded);
|
||||
|
||||
// End read
|
||||
nReturn = Focas1.cnc_upend4(nLibHandle[0]);
|
||||
|
||||
if (nReturn != 0)
|
||||
ThrowNCException(NC_PROD_ERROR, nReturn);
|
||||
ErrorHandler(NC_PROD_ERROR, nReturn);
|
||||
|
||||
partProgramContent = partProgramContent.Replace("\0", String.Empty);
|
||||
}
|
||||
|
||||
public override void W_NCWritePartProgramFromFile(string partProgramPath, FileStream localFile)
|
||||
@@ -1240,8 +1246,7 @@ namespace CMS_CORE.Fanuc
|
||||
nReturn = Focas1.cnc_dwnstart4(nLibHandle[0], 0, partProgramPath);
|
||||
|
||||
//Throw Exception if there's an error
|
||||
if (nReturn != 0)
|
||||
ThrowNCException(NC_PROD_ERROR, nReturn);
|
||||
ErrorHandler(NC_PROD_ERROR, nReturn);
|
||||
|
||||
//int lenghtMax = fileData.Length;
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
@@ -1250,14 +1255,12 @@ namespace CMS_CORE.Fanuc
|
||||
nReturn = Focas1.cnc_download4(nLibHandle[0], ref lenght, partProgramContent);
|
||||
|
||||
//Throw Exception if there's an error
|
||||
if (nReturn != 0)
|
||||
ThrowNCException(NC_PROD_ERROR, nReturn);
|
||||
ErrorHandler(NC_PROD_ERROR, nReturn);
|
||||
|
||||
nReturn = Focas1.cnc_dwnend4(nLibHandle[0]);
|
||||
|
||||
//Throw Exception if there's an error
|
||||
if (nReturn != 0)
|
||||
ThrowNCException(NC_PROD_ERROR, nReturn);
|
||||
ErrorHandler(NC_PROD_ERROR, nReturn);
|
||||
}
|
||||
|
||||
public override void NCCopyPartProgram(string partProgramPath, string newPartProgramPath, bool failIfExist)
|
||||
@@ -1269,7 +1272,7 @@ namespace CMS_CORE.Fanuc
|
||||
|
||||
// If the 2 path are the same
|
||||
if(partProgramPath == newPartProgramPath)
|
||||
ThrowNCException(NC_PROD_ERROR, 0); // TODO FIX
|
||||
ThrowNCException(NC_PROD_ERROR, 5); // TODO FIX
|
||||
|
||||
if (failIfExist)
|
||||
{
|
||||
@@ -1277,8 +1280,7 @@ namespace CMS_CORE.Fanuc
|
||||
nReturn = Focas1.cnc_pdf_copy(nLibHandle[0], partProgramPath, newPartProgramPath);
|
||||
|
||||
//Throw Exception if there's an error
|
||||
if (nReturn != 0)
|
||||
ThrowNCException(NC_PROD_ERROR, nReturn);
|
||||
ErrorHandler(NC_PROD_ERROR, nReturn);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1286,6 +1288,28 @@ namespace CMS_CORE.Fanuc
|
||||
// Find a function to check if file exist, delete and copy.
|
||||
// Read and put file
|
||||
// TODO
|
||||
//
|
||||
nReturn = Focas1.cnc_pdf_copy(nLibHandle[0], partProgramPath, newPartProgramPath);
|
||||
|
||||
if(nReturn == 5)
|
||||
{
|
||||
Focas1.ODBERR errorDetails = new Focas1.ODBERR();
|
||||
Focas1.cnc_getdtailerr(nLibHandle[0], errorDetails);
|
||||
|
||||
if (errorDetails.err_no == 4)
|
||||
{
|
||||
NCDeletePartProgram(newPartProgramPath, "");
|
||||
|
||||
nReturn = Focas1.cnc_pdf_copy(nLibHandle[0], partProgramPath, newPartProgramPath);
|
||||
|
||||
ErrorHandler(NC_PROD_ERROR, nReturn);
|
||||
}
|
||||
}
|
||||
else if(nReturn != 0)
|
||||
{
|
||||
ThrowNCException(NC_PROD_ERROR, nReturn);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1296,16 +1320,21 @@ namespace CMS_CORE.Fanuc
|
||||
|
||||
short nReturn;
|
||||
|
||||
nReturn = Focas1.cnc_pdf_del(nLibHandle[0], partProgramPath + "/" + partProgramName);
|
||||
nReturn = Focas1.cnc_pdf_del(nLibHandle[0], partProgramPath + partProgramName);
|
||||
|
||||
if(nReturn != 0)
|
||||
ThrowNCException(NC_PROD_ERROR, nReturn);
|
||||
ErrorHandler(NC_PROD_ERROR, nReturn);
|
||||
}
|
||||
#endregion
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#region Subordinate Private Functions
|
||||
|
||||
private void ErrorHandler(uint errorClass, short exNum)
|
||||
{
|
||||
if (exNum != 0)
|
||||
ThrowNCException(errorClass, exNum);
|
||||
}
|
||||
|
||||
private void ReadRelativeAxisPos(Focas1.POSELM pos, ref Dictionary<string, double> Axes)
|
||||
{
|
||||
//If is setted VISIBLE add to List
|
||||
|
||||
@@ -8,7 +8,9 @@ using System.Threading.Tasks;
|
||||
namespace CMS_CORE.Utils
|
||||
{
|
||||
public static class Nc_Utils
|
||||
{//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
private static string partProgramFolder = "./tmp/";
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// NC <-> .NET Conversions
|
||||
|
||||
// INT -> 2 WORD
|
||||
@@ -147,7 +149,7 @@ namespace CMS_CORE.Utils
|
||||
public static void WriteLocalFile(string fileName, string fileContent, ref FileStream fileReference)
|
||||
{
|
||||
// Create new local Part Program
|
||||
fileReference = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
|
||||
fileReference = new FileStream(partProgramFolder + fileName, FileMode.OpenOrCreate, FileAccess.Write);
|
||||
|
||||
// Write Part Program
|
||||
StreamWriter writer = new StreamWriter(fileReference);
|
||||
|
||||
Reference in New Issue
Block a user