337 lines
10 KiB
C#
337 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Runtime;
|
|
using System.Security.Policy;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Mitsubishi
|
|
{
|
|
internal class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
|
|
// preparo area x file test x debug successivo
|
|
var appPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
|
var fPath = Directory.GetParent(appPath).FullName;
|
|
string basePath = Path.Combine(fPath, "Test");
|
|
if (!Directory.Exists(basePath))
|
|
{
|
|
Directory.CreateDirectory(basePath);
|
|
}
|
|
outPath = Path.Combine(basePath, "test.log");
|
|
File.WriteAllText(outPath, "");
|
|
|
|
bool testWrite = false;
|
|
|
|
DoLog(sep);
|
|
DoLog("Mitsubishi Client test application");
|
|
DoLog(sep);
|
|
DoLog("");
|
|
Console.WriteLine("Vuoi simulare scritture? S/N");
|
|
ConsoleKeyInfo answ = Console.ReadKey();
|
|
testWrite = answ.KeyChar == 's' || answ.KeyChar == 'S';
|
|
|
|
// obj connessione
|
|
EZNCAUTLib.DispEZNcCommunication oEZNcAutCom = null;
|
|
oEZNcAutCom = new EZNCAUTLib.DispEZNcCommunication();
|
|
|
|
// [Local variable declaration]
|
|
object BlockValue = "";
|
|
int iRet = 0;
|
|
//Open communication
|
|
iRet = oEZNcAutCom.SetTCPIPProtocol("192.168.213.199", 683);
|
|
//Console.WriteLine($"R: {iRet}");
|
|
iRet = oEZNcAutCom.Open3(5, 1, 10, "EZNC_LOCALHOST");
|
|
|
|
DoLog(sep);
|
|
DoLog("Retrieve Serial/Vers");
|
|
DoLog(sep);
|
|
int partSys = -1;
|
|
oEZNcAutCom.System_GetSystemInformation(0, out partSys);
|
|
DoLog($"PartSys: {partSys}");
|
|
int numAx = -1; ;
|
|
oEZNcAutCom.System_GetSystemInformation(1, out numAx);
|
|
DoLog($"Num Ax: {numAx}");
|
|
string serNo = "";
|
|
oEZNcAutCom.System_GetSerialNo(out serNo);
|
|
DoLog($"SerNo: {serNo}");
|
|
string pVers = "";
|
|
oEZNcAutCom.System_GetVersion(0, 0, out pVers);
|
|
DoLog($"Vers 0: {pVers}");
|
|
oEZNcAutCom.System_GetVersion(0, 1, out pVers);
|
|
DoLog($"Vers 1: {pVers}");
|
|
oEZNcAutCom.System_GetVersion(0, 2, out pVers);
|
|
DoLog($"Vers 2: {pVers}");
|
|
DoLog(sep);
|
|
DoLog("");
|
|
|
|
DoLog(sep);
|
|
DoLog("Test DateTime");
|
|
DoLog(sep);
|
|
// preparo memorie
|
|
int pDate = 0;
|
|
int pTime = 0;
|
|
try
|
|
{
|
|
oEZNcAutCom.Time_GetClockData(out pDate, out pTime);
|
|
DoLog($"Date-Time | D: {pDate} | T: {pTime}");
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
DoLog($"{exc}");
|
|
}
|
|
DoLog(sep);
|
|
DoLog("");
|
|
|
|
DoLog(sep);
|
|
DoLog("Test Program");
|
|
DoLog(sep);
|
|
// preparo memorie
|
|
string prgText = "";
|
|
int prgState = 0;
|
|
// solo nome...
|
|
iRet = oEZNcAutCom.Program_GetProgramNumber2((Int32)PROGRAMTYPE.EZNC_MAINPRG, out String strProgramNo);
|
|
DoLog($"ProgramName: {strProgramNo}");
|
|
DoLog("");
|
|
|
|
// leggo contenuto
|
|
try
|
|
{
|
|
oEZNcAutCom.Program_CurrentBlockRead(10, out prgText, out prgState);
|
|
DoLog($"Program {prgState} | {prgText}");
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
DoLog($"{exc}");
|
|
}
|
|
DoLog(sep);
|
|
DoLog("");
|
|
|
|
DoLog(sep);
|
|
DoLog("Test CycleTyme");
|
|
DoLog(sep);
|
|
// preparo memorie
|
|
int plTime = 0;
|
|
try
|
|
{
|
|
oEZNcAutCom.Status_GetCycleTime(out plTime);
|
|
DoLog($"GetCycleTime | Time: {plTime}");
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
DoLog($"{exc}");
|
|
}
|
|
DoLog(sep);
|
|
DoLog("");
|
|
|
|
DoLog(sep);
|
|
DoLog("Test Lettura posizioni");
|
|
DoLog(sep);
|
|
double pdPosit = 0;
|
|
for (int i = 1; i < 4; i++)
|
|
{
|
|
iRet = oEZNcAutCom.Position_GetCurrentPosition(i, out pdPosit);
|
|
DoLog($"Pos: {i} | {pdPosit}");
|
|
}
|
|
DoLog(sep);
|
|
DoLog("");
|
|
|
|
DoLog(sep);
|
|
DoLog("Test scrittura Var500");
|
|
DoLog(sep);
|
|
// NB: max 7 char!!!
|
|
if (testWrite)
|
|
{
|
|
oEZNcAutCom.CommonVariable_SetName(500, "ODL");
|
|
oEZNcAutCom.CommonVariable_SetName(501, "CodArt");
|
|
oEZNcAutCom.CommonVariable_SetName(502, "NumPz");
|
|
oEZNcAutCom.CommonVariable_SetName(503, "");
|
|
|
|
oEZNcAutCom.CommonVariable_Write2(500, 105, 1);
|
|
oEZNcAutCom.CommonVariable_Write2(501, 205, 1);
|
|
oEZNcAutCom.CommonVariable_Write2(502, 305, 1);
|
|
oEZNcAutCom.CommonVariable_Write2(503, 0, 1);
|
|
}
|
|
DoLog("CommonVariable 500..503 Write Done!");
|
|
DoLog(sep);
|
|
DoLog("");
|
|
|
|
DoLog(sep);
|
|
DoLog("Test lettura Var500");
|
|
DoLog(sep);
|
|
string varName = "";
|
|
double pData = 0;
|
|
int pType = 0;
|
|
for (int i = 500; i < 505; i++)
|
|
{
|
|
oEZNcAutCom.CommonVariable_GetName(i, out varName);
|
|
oEZNcAutCom.CommonVariable_Read2(i, out pData, out pType);
|
|
DoLog($"Var: {i} | {varName} | val: {pData} | type: {pType}");
|
|
}
|
|
DoLog(sep);
|
|
DoLog("");
|
|
|
|
// lettura lampade
|
|
DoLog(sep);
|
|
DoLog("Test lettura lampade Y60..Y63");
|
|
DoLog(sep);
|
|
object pvRead = "bbb";
|
|
int sec = 53;
|
|
Dictionary<string, string> DictLamp = new Dictionary<string, string>();
|
|
//Y60 --> 10000+96
|
|
int subSec = 10096;
|
|
for (int j = 0; j < 5; j++)
|
|
{
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
oEZNcAutCom.Generic_ReadData(0, sec, subSec + i, ref pvRead);
|
|
DictLamp.Add($"{subSec + i}", $"{pvRead}");
|
|
}
|
|
StringBuilder sb = new StringBuilder();
|
|
foreach (var item in DictLamp)
|
|
{
|
|
sb.Append($"{item.Key}:{item.Value} | ");
|
|
}
|
|
|
|
DoLog($"Lamp: Generic ReadData | sec: {sec} | {sb.ToString()}");
|
|
Thread.Sleep(100);
|
|
DictLamp = new Dictionary<string, string>();
|
|
}
|
|
DoLog(sep);
|
|
DoLog("");
|
|
|
|
// lettura parametri (pzcount)
|
|
DoLog(sep);
|
|
DoLog("Test Parametri");
|
|
DoLog(sep);
|
|
int lAxis = 0;
|
|
int startPar = 8001;
|
|
if (testWrite)
|
|
{
|
|
// scrivo pz req a 100...
|
|
String[] sValue = new String[1];
|
|
sValue[0] = "101";
|
|
oEZNcAutCom.Parameter_SetData3(0, 8003, lAxis, (object)sValue);
|
|
}
|
|
|
|
object parValue = "www";
|
|
try
|
|
{
|
|
oEZNcAutCom.Parameter_GetData3(0, startPar, 3, lAxis, out parValue);
|
|
string[] rawData = (string[])parValue;
|
|
DoLog($"Found {rawData.Count()} values");
|
|
int i = 0;
|
|
foreach (var item in rawData)
|
|
{
|
|
DoLog($"Params | #: {startPar + i} | {item}");
|
|
i++;
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
DoLog($"{exc}");
|
|
}
|
|
DoLog(sep);
|
|
DoLog("");
|
|
|
|
DoLog(sep);
|
|
DoLog("Test Allarmi");
|
|
DoLog(sep);
|
|
// preparo memorie
|
|
Array plSystem = new long[1];
|
|
Array pbWarning = new bool[1];
|
|
Array plAlarmType = new long[1];
|
|
string pbstrBuffer = "";
|
|
try
|
|
{
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
oEZNcAutCom.System_GetAlarm2(1, i, out pbstrBuffer);
|
|
DoLog($"Alarm {i}: {pbstrBuffer}");
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
DoLog($"{exc}");
|
|
}
|
|
DoLog(sep);
|
|
DoLog("");
|
|
|
|
DoLog(sep);
|
|
DoLog("Test Feed");
|
|
DoLog(sep);
|
|
// preparo memorie
|
|
double feed = 0;
|
|
try
|
|
{
|
|
for (int i = 0; i <= 5; i++)
|
|
{
|
|
oEZNcAutCom.Position_GetFeedSpeed(i, out feed);
|
|
DoLog($"FeedSpeed {i}: {feed}");
|
|
|
|
oEZNcAutCom.Command_GetFeedCommand(i, out feed);
|
|
DoLog($"FeedCommand {i}: {feed}");
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
DoLog($"{exc}");
|
|
}
|
|
DoLog(sep);
|
|
DoLog("");
|
|
|
|
DoLog(sep);
|
|
DoLog("Test RunStatus");
|
|
DoLog(sep);
|
|
// preparo memorie
|
|
int plStatus = 0;
|
|
try
|
|
{
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
oEZNcAutCom.Status_GetRunStatus(i, out plStatus);
|
|
DoLog($"GetRunStatus | Idx: {i} | Status: {plStatus}");
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
DoLog($"{exc}");
|
|
}
|
|
DoLog(sep);
|
|
DoLog("");
|
|
|
|
// Close.
|
|
iRet = oEZNcAutCom.Close();
|
|
//Release object
|
|
oEZNcAutCom = null;
|
|
|
|
DoLog("Press enter to close");
|
|
Console.ReadLine();
|
|
|
|
}
|
|
|
|
protected static void DoLog(string logMessage)
|
|
{
|
|
File.AppendAllText(outPath, $"{logMessage}{Environment.NewLine}");
|
|
Console.WriteLine(logMessage);
|
|
}
|
|
|
|
public enum PROGRAMTYPE
|
|
{
|
|
EZNC_MAINPRG = 0, //メインプログラム
|
|
EZNC_SUBPRG = 1, //サブプログラム
|
|
}
|
|
|
|
protected static string outPath = "";
|
|
|
|
private static string sep = "------------------------";
|
|
private static Stopwatch sw = new Stopwatch();
|
|
}
|
|
}
|