-> Hier kostenlos registrieren
Hallo Zusammen,
Ich soll für meine Bachelorarbeit aus einer Steuerung SINUMERIK 840d sl auf einige Werkzeug- und Achsdaten zugreifen. Trotz meiner geringen Programmierkenntnisse habe ich (dank AGlink) geschafft, die Daten zuzugreifen. Jetzt versuche ich zum Automatischen Steuern der CNC-Maschine "PLCStop" funktion benutzen und die Machine in Stop versetzen. Leider bekomme ich die Fehler Meldung "AGL40_WRONG_KONTEXT". Unten ist ein Teil meines Codeschnipsels. Ich wäre sehr dankbar, falls mir jemand helfen könnte.
Viele Grüße
Mert
Ich soll für meine Bachelorarbeit aus einer Steuerung SINUMERIK 840d sl auf einige Werkzeug- und Achsdaten zugreifen. Trotz meiner geringen Programmierkenntnisse habe ich (dank AGlink) geschafft, die Daten zuzugreifen. Jetzt versuche ich zum Automatischen Steuern der CNC-Maschine "PLCStop" funktion benutzen und die Machine in Stop versetzen. Leider bekomme ich die Fehler Meldung "AGL40_WRONG_KONTEXT". Unten ist ein Teil meines Codeschnipsels. Ich wäre sehr dankbar, falls mir jemand helfen könnte.
Viele Grüße
Mert
C#:
using System;
using System.IO;
using System.Reflection;
using Accon.AGLink;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Globalization;
namespace NCK1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Consolen Test");
AGL4.Activate("----");
IAGLink4 agl;
Int32 devnr = 0;
Int32 plcnr = 1;
Int32 timeout = 1000;
Int32 result = 0;
Int32 cycletime = 1;
bool onlyonchange = false;
Int32 handle = 0;
string errormsg = "";
List<string> werte = new List<string>();
//Initialisierung des rwfields
AGL4.NckDataRW[] rwfield = new AGL4.NckDataRW[3];
string FullPath = Assembly.GetExecutingAssembly().Location;
string path = Path.GetDirectoryName(FullPath);
Console.WriteLine(path);
AGL4.SetParaPath(path);
agl = AGL4ConnectionFactory.CreateInstance(devnr, plcnr, timeout);
bool res = agl.Connect();
if (res == true)
{
Console.WriteLine("Connection succesfull");
//Rwfield konfigurieren und in Funktion anpassen
SetupRwfield(ref rwfield);
result = AGL4.NCK_ReadMixEx(agl.ConnNr, ref rwfield, timeout);
//Testdaten zu Beginn auskommentieren
while (true)
{
Cycle(agl.ConnNr, cycletime, onlyonchange, ref rwfield, handle, timeout);
double Xachswert = System.BitConverter.ToDouble(rwfield[0].Buff, 0);
double Yachswert = System.BitConverter.ToDouble(rwfield[1].Buff, 0);
double Zachswert = System.BitConverter.ToDouble(rwfield[2].Buff, 0);
Console.SetCursorPosition(2, 4);
Console.WriteLine("Achsdaten");
Console.SetCursorPosition(2, 5);
Console.WriteLine("X Achse: "+ Xachswert);
Console.SetCursorPosition(2, 6);
Console.WriteLine("Y Achse: "+ Yachswert);
Console.SetCursorPosition(2, 7);
Console.WriteLine("Z Achse: " + Zachswert);
if((Xachswert>=145 && Xachswert<=180) && (Yachswert>=420 && Yachswert<=460) &&(Zachswert>=(425) && Zachswert<=600))
{
doPLCStop(agl.ConnNr, timeout);
}
}
}
else
{
Console.WriteLine("Connection failed");
Console.ReadLine();
}
}
static void SetupRwfield(ref AGL4.NckDataRW[] rwfield)
{
//X Achsenwerte
rwfield[0] = new AGL4.NckDataRW();
rwfield[0].Area = AGL4.NCK_Area.eNCK_AreaNCK;
rwfield[0].Block = AGL4.NCK_Block.eNCK_BlockSMA;
rwfield[0].Column = 2;
rwfield[0].Row = 1;
rwfield[0].RowCount = 1;
rwfield[0].Unit = 1;
rwfield[0].DDEVarType = AGL4.NCK_DDEVarFormat.eNCK_LE_Float64;
rwfield[0].BuffLen = 8;
rwfield[0].Buff = new Byte[rwfield[0].BuffLen];
rwfield[0].Result = 0;
//Y Achsenwerte
rwfield[1] = new AGL4.NckDataRW();
rwfield[1].Area = AGL4.NCK_Area.eNCK_AreaNCK;
rwfield[1].Block = AGL4.NCK_Block.eNCK_BlockSMA;
rwfield[1].Column = 2;
rwfield[1].Row = 2;
rwfield[1].RowCount = 1;
rwfield[1].Unit = 1;
rwfield[1].DDEVarType = AGL4.NCK_DDEVarFormat.eNCK_LE_Float64;
rwfield[1].BuffLen = 8;
rwfield[1].Buff = new Byte[rwfield[0].BuffLen];
rwfield[1].Result = 0;
//Z Achsenwerte
rwfield[2] = new AGL4.NckDataRW();
rwfield[2].Area = AGL4.NCK_Area.eNCK_AreaNCK;
rwfield[2].Block = AGL4.NCK_Block.eNCK_BlockSMA;
rwfield[2].Column = 2;
rwfield[2].Row = 3;
rwfield[2].RowCount = 1;
rwfield[2].Unit = 1;
rwfield[2].DDEVarType = AGL4.NCK_DDEVarFormat.eNCK_LE_Float64;
rwfield[2].BuffLen = 8;
rwfield[2].Buff = new Byte[rwfield[0].BuffLen];
rwfield[2].Result = 0;
}
static void Cycle(Int32 ConnNr, Int32 cycletime, bool onlyonchange, ref AGL4.NckDataRW[] rwfield, Int32 handle, Int32 timeout)
{
Int32 result;
string errormsg = "";
// Inititalisierung der zyklischen NCK abfrage
result = AGL4.NCK_InitCyclicReadEx(ConnNr, cycletime, onlyonchange, ref rwfield, out handle, timeout);
if (result == AGL4.AGL40_SUCCESS)
{
//Start des Lesens
result = AGL4.NCK_StartCyclicRead(ConnNr, handle, timeout);
if (result == AGL4.AGL40_SUCCESS)
{
//Empfangen der Daten
result = AGL4.NCK_GetCyclicReadEx(ConnNr, ref rwfield, handle, timeout);
if (result == AGL4.AGL40_SUCCESS)
{
//Console.WriteLine("Cycle Start erfolgreich");
}
else
{
// Error happened
AGL4.GetErrorMsg(result, out errormsg);
}
// If you don't require any other data, log off
AGL4.NCK_StopCyclicRead(ConnNr, handle, timeout);
AGL4.NCK_ExitCyclicRead(ConnNr, handle, timeout);
}
else
{
result = AGL4.NCK_ExitCyclicRead(ConnNr, handle, timeout);
// Error happened
AGL4.GetErrorMsg(result, out errormsg);
}
}
else
{
// Error happened
AGL4.GetErrorMsg(result, out errormsg);
}
}
static void doPLCStop(Int32 ConnNr, Int32 timeout)
{
Int32 result = AGL4.AGL40_PARAMETER_ERROR;
// Run only if the timeout was positive
if (timeout > 0)
{
// For a successful call, a connection must be built up to the AG.
result = AGL4.PLCStop(ConnNr, timeout);
if (result != AGL4.AGL40_SUCCESS)
{
// Error happened.
String errormsg = "";
AGL4.GetErrorMsg(result, out errormsg);
Console.SetCursorPosition(1, 24);
Console.WriteLine(errormsg);
}
}
}
}
}