* Added File funtions to Osai Nc

* WIP Added file functions to Fanuc Nc
This commit is contained in:
Lucio Maranta
2017-11-08 16:35:59 +00:00
parent 10d8210bde
commit c9155378e5
15 changed files with 434 additions and 39 deletions
+26
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
@@ -687,6 +688,31 @@ namespace CMS_CORE.Demo
}
#endregion
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region File Management
public override void R_NCReadPartProgramToFile(string partProgramPath, string partProgramLocalName, ref FileStream localFile)
{
throw new NotImplementedException();
}
public override void W_NCWritePartProgramFromFile(string partProgramPath, FileStream localFile)
{
throw new NotImplementedException();
}
public override void NCCopyPartProgram(string partProgramPath, string newPartProgramPath, bool failIfExist)
{
throw new NotImplementedException();
}
public override void NCDeletePartProgram(string partProgramPath, string partProgramName)
{
throw new NotImplementedException();
}
#endregion
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Subordinate Private Functions
+167 -6
View File
@@ -7,6 +7,8 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using CMS_CORE.Utils;
#pragma warning disable 1591
@@ -128,7 +130,7 @@ namespace CMS_CORE.Fanuc
//Check if the NC is Connected
CheckConnection();
readStaticNCData();
ReadStaticNCData();
Language = ConverToSTEPLanguage(FanucLanguage);
}
@@ -140,7 +142,7 @@ namespace CMS_CORE.Fanuc
//Check if the NC is Connected
CheckConnection();
readStaticNCData();
ReadStaticNCData();
SN = Cnc_SeriesNum;
}
@@ -152,7 +154,7 @@ namespace CMS_CORE.Fanuc
//Check if the NC is Connected
CheckConnection();
readStaticNCData();
ReadStaticNCData();
SWV = Cnc_SftVersion;
}
@@ -164,7 +166,7 @@ namespace CMS_CORE.Fanuc
//Check if the NC is Connected
CheckConnection();
readStaticNCData();
ReadStaticNCData();
ModelName = Cnc_name;
}
@@ -176,7 +178,7 @@ namespace CMS_CORE.Fanuc
//Check if the NC is Connected
CheckConnection();
readStaticNCData();
ReadStaticNCData();
ProcNumber = (ushort) Cnc_NumPath;
}
@@ -1140,6 +1142,165 @@ namespace CMS_CORE.Fanuc
#endregion
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region File Management
public override void R_NCReadPartProgramToFile(string partProgramPath, string partProgramLocalName, ref FileStream localFile)
{
string partProgramContent = "";
// Read NC part program content
R_NCReadPartProgram(partProgramPath, ref partProgramContent);
try
{
// Write content into local file
Nc_Utils.WriteLocalFile(partProgramLocalName, partProgramContent, ref localFile);
}
catch (Exception ex)
{
ThrowNCException(INTERNAL_ERROR, 0);
}
}
private void R_NCReadPartProgram(string partProgramPath, ref string partProgramContent)
{
//Check if the NC is Connected
CheckConnection();
bool fileEnded = false;
short nReturn;
int lenght = 256;
// Start read process
nReturn = Focas1.cnc_upstart4(nLibHandle[0], 0, partProgramPath);
//Throw Exception if there's an error
if (nReturn != 0)
ThrowNCException(NC_PROD_ERROR, nReturn);
do
{
// Local buffer
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)
{
fileEnded = true;
}
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);
}
public override void W_NCWritePartProgramFromFile(string partProgramPath, FileStream localFile)
{
string partProgramContent = "";
try
{
// Read local file content
partProgramContent = Nc_Utils.ReadLocalFile(localFile);
}
catch (Exception ex)
{
ThrowNCException(INTERNAL_ERROR, 0);
}
W_NCWritePartProgram(partProgramPath, partProgramContent);
}
private void W_NCWritePartProgram(string partProgramPath, string partProgramContent)
{
//Check if the NC is Connected
CheckConnection();
short nReturn;
// Start write
nReturn = Focas1.cnc_dwnstart4(nLibHandle[0], 0, partProgramPath);
//Throw Exception if there's an error
if (nReturn != 0)
ThrowNCException(NC_PROD_ERROR, nReturn);
//int lenghtMax = fileData.Length;
System.Threading.Thread.Sleep(1000);
int lenght = partProgramContent.Length;
// Write program
nReturn = Focas1.cnc_download4(nLibHandle[0], ref lenght, partProgramContent);
//Throw Exception if there's an error
if (nReturn != 0)
ThrowNCException(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);
}
public override void NCCopyPartProgram(string partProgramPath, string newPartProgramPath, bool failIfExist)
{
//Check if the NC is Connected
CheckConnection();
short nReturn;
// If the 2 path are the same
if(partProgramPath == newPartProgramPath)
ThrowNCException(NC_PROD_ERROR, 0); // TODO FIX
if (failIfExist)
{
// Copy Nc part program to the new path
nReturn = Focas1.cnc_pdf_copy(nLibHandle[0], partProgramPath, newPartProgramPath);
//Throw Exception if there's an error
if (nReturn != 0)
ThrowNCException(NC_PROD_ERROR, nReturn);
}
else
{
// Try a copy and if error is 4 delete file and retry
// Find a function to check if file exist, delete and copy.
// Read and put file
// TODO
}
}
public override void NCDeletePartProgram(string partProgramPath, string partProgramName)
{
//Check if the NC is Connected
CheckConnection();
short nReturn;
nReturn = Focas1.cnc_pdf_del(nLibHandle[0], partProgramPath + "/" + partProgramName);
if(nReturn != 0)
ThrowNCException(NC_PROD_ERROR, nReturn);
}
#endregion
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1263,7 +1424,7 @@ namespace CMS_CORE.Fanuc
//Read Static Data
private void readStaticNCData()
private void ReadStaticNCData()
{
short nReturn;
Focas1.ODBSYS node = new Focas1.ODBSYS();
+43 -1
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -564,7 +565,48 @@ namespace CMS_CORE
* <param name="Value">Reference of a variable with Param values</param>
* */
public abstract void R_NCParam(short Index, ref double Value);
#endregion
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region File Management (To override)
/**
* <summary> Read a Part Program by path and name
* </summary>
* <exception cref="Exceptions.Nc_Exception">Thrown when an internal or a library error occours</exception>
* <param name="partProgramPath">Path of the Part Program stored in the Nc</param>
* <param name="partProgramLocalName">Name of the Part Program and name of new local file</param>
* <param name="localFile">Reference to the new local file where the NC Part Program data will be saved</param>
* */
public abstract void R_NCReadPartProgramToFile(string partProgramPath, string partProgramLocalName, ref FileStream localFile);
/**
* <summary> Write/Overwrite a Part Program by path and name
* </summary>
* <exception cref="Exceptions.Nc_Exception">Thrown when an internal or a library error occours</exception>
* <param name="partProgramPath">Path of the Part Program stored in the Nc</param>
* <param name="localFile">Reference to the local Part Program file</param>
* */
public abstract void W_NCWritePartProgramFromFile(string partProgramPath, FileStream localFile);
/**
* <summary> Copy a Part Program into another path
* </summary>
* <exception cref="Exceptions.Nc_Exception">Thrown when an internal or a library error occours</exception>
* <param name="partProgramPath">Path where the Part Program is saved in the NC</param>
* <param name="newPartProgramPath">Path of the copy Part Program destination</param>
* <param name="failIfExist"></param>
* */
public abstract void NCCopyPartProgram(string partProgramPath, string newPartProgramPath, bool failIfExist);
/**
* <summary> Delete a Nc Part Program</summary>
* <exception cref="Exceptions.Nc_Exception">Thrown when an internal or a library error occours</exception>
* <param name="partProgramPath">Path where the Nc Part Program is saved in the NC</param>
* <param name="partProgramName">Name of the Part Program file</param>
* */
public abstract void NCDeletePartProgram(string partProgramPath, string partProgramName);
#endregion
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+140 -32
View File
@@ -14,7 +14,6 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using CMS_CORE_Library.OPENControl;
using System.ComponentModel;
namespace CMS_CORE.Osai
{
@@ -1031,6 +1030,146 @@ namespace CMS_CORE.Osai
#endregion
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region File Management
public override void R_NCReadPartProgramToFile(string partProgramPath, string partProgramLocalName, ref FileStream localFile)
{
string partProgramContent = "";
// Read NC part program content
R_NCReadPartProgram(partProgramPath, ref partProgramContent); ;
try
{
// Write content into local file
Nc_Utils.WriteLocalFile(partProgramLocalName, partProgramContent, ref localFile);
}
catch (Exception ex)
{
ThrowNCException(ex);
}
}
private void R_NCReadPartProgram(string partProgramPath, ref string partProgramContent)
{
//Check if the NC is Connected
CheckConnection();
ushort nReturn;
uint errorClass, errorNum;
uint size = 0;
try
{
// Get part program file size
nReturn = OpenNC.LogFSGetFileSize(partProgramPath, out size, out errorClass, out errorNum);
// Read part program content
nReturn = OpenNC.GetFile(partProgramPath, ref size, out partProgramContent, out errorClass, out errorNum);
//If there's an error launch exception
if (errorClass != 0 || errorNum != 0 || nReturn == 0)
throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum));
}
catch (Exception ex)
{
ThrowNCException(ex);
}
}
public override void W_NCWritePartProgramFromFile(string partProgramPath, FileStream localFile)
{
string partProgramContent = "";
try
{
// Read local file content
partProgramContent = Nc_Utils.ReadLocalFile(localFile);
}
catch (Exception ex)
{
ThrowNCException(ex);
}
// Write/Overwrite Nc file
W_NCWritePartProgram(partProgramPath, partProgramContent);
}
private void W_NCWritePartProgram(string partProgramPath, string partProgramContent)
{
//Check if the NC is Connected
CheckConnection();
ushort nReturn;
uint errorClass, errorNum;
try
{
// Write the local file NC
nReturn = OpenNC.PutFile(partProgramContent, (uint)partProgramContent.Length, partProgramPath, out errorClass, out errorNum);
//If there's an error launch exception
if (errorClass != 0 || errorNum != 0 || nReturn == 0)
throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum));
}
catch(Exception ex)
{
ThrowNCException(ex);
}
}
public override void NCCopyPartProgram(string partProgramPath, string newPartProgramPath, bool failIfExist)
{
//Check if the NC is Connected
CheckConnection();
uint errorClass, errorNum;
ushort nReturn;
// If the 2 path are the same
if (partProgramPath == newPartProgramPath)
throw new Nc_Exception(getError(NC_PROD_ERROR, 0, 0)); // TODO FIX
try
{
// Copy Nc part program to the new path
nReturn = OpenNC.LogFSCopyFile(partProgramPath, newPartProgramPath, failIfExist, out errorClass, out errorNum);
//If there's an error launch exception
if (errorClass != 0 || errorNum != 0 || nReturn == 0)
throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum));
}
catch (Exception ex)
{
ThrowNCException(ex);
}
}
public override void NCDeletePartProgram(string partProgramPath, string partProgramName)
{
//Check if the NC is Connected
CheckConnection();
uint errorClass, errorNum;
ushort nReturn;
try
{
// Delete part program
nReturn = OpenNC.LogFSRemoveFile(partProgramPath, partProgramName, out errorClass, out errorNum);
//If there's an error launch exception
if (errorClass != 0 || errorNum != 0 || nReturn == 0)
throw new Nc_Exception(getError(NC_PROD_ERROR, errorClass, errorNum));
}
catch (Exception ex)
{
ThrowNCException(ex);
}
}
#endregion
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1422,37 +1561,6 @@ namespace CMS_CORE.Osai
return ErrororOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")";
case 5:
szErrorClassDesc = "FILESYSTEM error class";
switch (Num)
{
case 0x001: szErrorDesc = "An error has occurred while opening a transaction with the target for file transfer."; break;
case 0x002: szErrorDesc = "An error has occurred while closing a transaction with the target for file transfer."; break;
case 0x003: szErrorDesc = "Invalid file ID."; break;
case 0x004: szErrorDesc = "The number of transaction is not valid."; break;
case 0x005: szErrorDesc = "Error opening file."; break;
case 0x006: szErrorDesc = "Error closing file."; break;
case 0x007: szErrorDesc = "A file path containing wildcards was passed to a function that does not support wildcards."; break;
case 0x008: szErrorDesc = "Error reading data from file."; break;
case 0x009: szErrorDesc = "Error writing data to file."; break;
case 0x00A: szErrorDesc = "The logical drive was not found on the target."; break;
case 0x00C: szErrorDesc = "The specified file path was not valid."; break;
case 0x00D: szErrorDesc = "An attempt was made to create a logical drive on the target with the same name as an existing logical drive."; break;
case 0x00E: szErrorDesc = "The invoked function requires a different security level on the target."; break;
case 0x00F: szErrorDesc = "A logical drive cannot be created on a remote PC."; break;
case 0x010: szErrorDesc = "Insufficient disk space to complete the requested operation."; break;
case 0x011: szErrorDesc = "The requested file was not found."; break;
}
return ErrororOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")";
case 6:
szErrorClassDesc = "WINDOWS error class";
szErrorDesc = new Win32Exception((int) Num).Message;
return ErrororOwner + szErrorClassDesc + ": " + szErrorDesc + " (" + Class + "-" + Num + ")";
case 10:
szErrorClassDesc = "DLL_INTERFACE error class";
switch (Num)
+25
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -142,5 +143,29 @@ namespace CMS_CORE.Utils
return Uint;
}
public static void WriteLocalFile(string fileName, string fileContent, ref FileStream fileReference)
{
// Create new local Part Program
fileReference = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
// Write Part Program
StreamWriter writer = new StreamWriter(fileReference);
writer.WriteLine(fileContent);
// Close file Writer
writer.Close();
}
public static string ReadLocalFile(FileStream fileReference)
{
// Get File Content
StreamReader reader = new StreamReader(fileReference);
string fileContent = reader.ReadToEnd();
reader.Close();
return fileContent;
}
}
}
Binary file not shown.
Binary file not shown.
@@ -463,6 +463,39 @@
<param name="Index">Index of the parameter</param>
<param name="Value">Reference of a variable with Param values</param>
</member>
<member name="M:CMS_CORE.Nc.R_NCReadPartProgramToFile(System.String,System.String,System.IO.FileStream@)">
<summary> Read a Part Program by path and name
</summary>
<exception cref="T:CMS_CORE.Exceptions.Nc_Exception">Thrown when an internal or a library error occours</exception>
<param name="partProgramPath">Path of the Part Program stored in the Nc</param>
<param name="partProgramLocalName">Name of the Part Program and name of new local file</param>
<param name="localFile">Reference to the new local file where the NC Part Program data will be saved</param>
</member>
<member name="M:CMS_CORE.Nc.W_NCWritePartProgramFromFile(System.String,System.IO.FileStream)">
<summary> Write/Overwrite a Part Program by path and name
</summary>
<exception cref="T:CMS_CORE.Exceptions.Nc_Exception">Thrown when an internal or a library error occours</exception>
<param name="partProgramPath">Path of the Part Program stored in the Nc</param>
<param name="localFile">Reference to the local Part Program file</param>
</member>
<member name="M:CMS_CORE.Nc.NCCopyPartProgram(System.String,System.String,System.Boolean)">
<summary> Copy a Part Program into another path
</summary>
<exception cref="T:CMS_CORE.Exceptions.Nc_Exception">Thrown when an internal or a library error occours</exception>
<param name="partProgramPath">Path where the Part Program is saved in the NC</param>
<param name="newPartProgramPath">Path of the copy Part Program destination</param>
<param name="failIfExist"></param>
</member>
<member name="M:CMS_CORE.Nc.NCDeletePartProgram(System.String,System.String)">
<summary> Delete a Nc Part Program</summary>
<exception cref="T:CMS_CORE.Exceptions.Nc_Exception">Thrown when an internal or a library error occours</exception>
<param name="partProgramPath">Path where the Nc Part Program is saved in the NC</param>
<param name="partProgramName">Name of the Part Program file</param>
</member>
<member name="M:CMS_CORE.Osai.Nc_Osai.#ctor(System.String,System.UInt16,System.UInt16)">
<summary>
Binary file not shown.
Binary file not shown.