-> Hier kostenlos registrieren
Wrong place
Zuletzt bearbeitet:
Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
C1_S_actToolIdent1:
STRUCT
SYNTAX_ID : BYTE := B#16#82;
bereich_u_einheit : BYTE := B#16#41;
spalte : WORD := W#16#21;
zeile : WORD := W#16#1;
bausteintyp : BYTE := B#16#7F;
ZEILENANZAHL : BYTE := B#16#1;
typ : BYTE := B#16#13;
laenge : BYTE := B#16#20;
END_STRUCT ;
END_STRUCT ;
PLCConnection _myConn = new PLCConnection("ReadFromNck");
_myConn.Configuration.CpuIP = "192.168.214.1";
_myConn.Configuration.CpuSlot = 4;
_myConn.Connect();
var tag = new NC_Var(0x82, 0x41, 0x21, 0x1, 0x7F, 0x1, 0x13, 0x20).GetNckTag();
//var tag = new NC_Var(0x82, [FONT=arial black]0x40[/FONT], 0x21, 0x1, 0x7F, 0x1, 0x13, 0x20).GetNckTag([FONT=arial black]1[/FONT]); //Kanal
_myConn.ReadValue(tag);
private void abc()
{
PLCConnection _myConn = new PLCConnection("");
string IPAddress = "192.168.214.1";
try
{
_myConn.Configuration.CpuIP = !string.IsNullOrEmpty(IPAddress) ? IPAddress : "192.168.214.1";
_myConn.Configuration.CpuSlot = 4;
_myConn.Connect();
#region ACX File laden
byte[] bAr = _myConn.BinaryUploadFromNC("_N_NC_GD2_ACX");
byte[] GudFile = new byte[bAr.Length - 24];
Array.Copy(bAr, 24, GudFile, 0, GudFile.Length);
#endregion
#region parse
var bArX = Separate(GudFile, new byte[] { 4, 0, 0, 0, 0 });
List<GudVar> lGUD = new List<GudVar>();
for (int i = 1; i < bArX.Length; i++)
{
string name = string.Empty;
int gudIndex = 0;
int size = 0;
int dim1 = 0;
int dim2 = 0;
int dim3 = 0;
int[] range = new int[0];
GudVar.E_NCK_Type nckType = GudVar.E_NCK_Type.NULL;
int index = 3;
name = Encoding.Default.GetString(bArX[i], index, bArX[i][0]);
index += bArX[i][0];
for (int j = index; j < bArX[i].Length; j++)
{
if (bArX[i][j] == 0x20)
{
int valueBytesCount = bArX[i][j - 2];
var value = getValue(bArX[i], valueBytesCount, j + 1);
switch (bArX[i][j - 1])
{
case 0x85: //String länge
size = value;
break;
case 0x88: //Index der Variablen im GUD-Bereich
gudIndex = value;
break;
case 0x89: //Datentype
getNckType(value, ref size, ref nckType);
break;
case 0x98: //Größe Dimension1
dim1 = value;
break;
case 0x99: //Größe Dimension2
dim2 = value;
break;
default:
break;
}
j += valueBytesCount;
}
else if (bArX[i][j] == 0x25)
{
int valueBytesCount = bArX[i][j - 2];
var value = getValue(bArX[i], valueBytesCount, j + 1);
switch (bArX[i][j - 1])
{
case 0x67: //Größe Dimension3
dim3 = value;
break;
default:
break;
}
j += valueBytesCount;
}
}
if (dim3 != 0)
range = new int[] { dim1, dim2, dim3 };
else if (dim2 != 0)
range = new int[] { dim1, dim2 };
else if (dim1 != 0)
range = new int[] { dim1 };
GudVar gud = new GudVar(gudIndex, dim1 != 0, name, range, size, nckType);
lGUD.Add(gud);
}
#endregion
var _gud = lGUD[0];
var ncVar = new NC_Var(0x82, 0x1, _gud.GudNumber, (_gud.IsArray ? 0x0 : 0x1), 0x2D, 1, (int)_gud.Type, _gud.Size);
var tag = ncVar.GetNckTag();
_myConn.ReadValue(tag);
var _value = tag.Value;
}
catch (Exception)
{
}
if (_myConn != null)
{
if (_myConn.Connected)
_myConn.Disconnect();
_myConn.Dispose();
}
}
private static dynamic getValue(byte[] source, int lenth, int index)
{
switch (lenth)
{
case 1:
return source[index];
case 2:
return BitConverter.ToInt16(source, index);
case 4:
return BitConverter.ToInt32(source, index);
case 8:
return BitConverter.ToInt64(source, index);
default:
var bAr = new byte[lenth];
Array.Copy(source, index, bAr, 0, bAr.Length);
return bAr;
}
}
private static void getNckType(byte type, ref int size, ref GudVar.E_NCK_Type nckType)
{
switch ((GudVar.E_NCK_AcxType)type)
{
case GudVar.E_NCK_AcxType.BOOL:
nckType = GudVar.E_NCK_Type.BOOL;
size = 1;
break;
case GudVar.E_NCK_AcxType.INT:
nckType = GudVar.E_NCK_Type.INT;
size = 4;
break;
case GudVar.E_NCK_AcxType.CHAR:
nckType = GudVar.E_NCK_Type.CHAR;
size = 1;
break;
case GudVar.E_NCK_AcxType.REAL:
nckType = GudVar.E_NCK_Type.REAL;
size = 8;
break;
case GudVar.E_NCK_AcxType.STRING:
nckType = GudVar.E_NCK_Type.STRING;
break;
case GudVar.E_NCK_AcxType.AXIS:
nckType = GudVar.E_NCK_Type.AXIS;
size = 1;
break;
case GudVar.E_NCK_AcxType.FRAME:
nckType = GudVar.E_NCK_Type.FRAME;
size = 1;
break;
default:
break;
}
}
public static byte[][] Separate(byte[] source, byte[] separator)
{
var Parts = new List<byte[]>();
var Index = 0;
byte[] Part;
for (var i = 0; i < source.Length; ++i)
{
if (Equals(source, separator, i))
{
Part = new byte[i - Index];
Array.Copy(source, Index, Part, 0, Part.Length);
Parts.Add(Part);
Index = i + separator.Length;
i += separator.Length - 1;
}
}
Part = new byte[source.Length - Index];
Array.Copy(source, Index, Part, 0, Part.Length);
Parts.Add(Part);
return Parts.ToArray();
}
static bool Equals(byte[] source, byte[] separator, int index)
{
for (int i = 0; i < separator.Length; ++i)
if (index + i >= source.Length || source[index + i] != separator[i])
return false;
return true;
}
internal class GudVar
{
public string Name = string.Empty;
public E_NCK_Type Type;
public bool IsArray;
public int[] Range;
public int Size;
public ushort GudNumber;
/// <summary>
///
/// </summary>
/// <param name="GudNumber">Position im GUD-Bereich</param>
/// <param name="IsArray"></param>
/// <param name="Name"></param>
/// <param name="Range">Anzahl an Dimensionen</param>
/// <param name="Size"></param>
/// <param name="Type">Datentyp</param>
internal GudVar(int GudNumber, bool IsArray, string Name, int[] Range, int Size, E_NCK_Type Type)
{
this.GudNumber = (ushort)GudNumber;
this.IsArray = IsArray;
this.Name = Name;
this.Range = Range;
this.Size = Size;
this.Type = Type;
}
internal enum E_NCK_AcxType
{
BOOL = 0x0,
INT = 0x3,
CHAR = 0x5,
REAL = 0xA,
STRING = 0xC,
FRAME = 0xD,
AXIS = 0xE
}
internal enum E_NCK_Area
{
NCK = 0x1,
CHAN = 0x41 //Channel 1
//CHAN = 0x3
}
internal enum E_NCK_Type
{
NULL = 0x0,
BOOL = 0x1,
AXIS = 0x2, //???
FRAME = 0x2, //???
BYTE = 0x3,
WORD = 0x4,
INT = 0x5,
DWORD = 0x6,
DINT = 0x7,
FLOAT = 0x8,
REAL = 0xF,
INT64 = 0x12,
CHAR = 0x13,
STRING = 0x13
//FRAME = 0x14 //???
//AXIS = 0x15 //???
}
}
Wir verwenden essentielle Cookies, damit diese Website funktioniert, und optionale Cookies, um den Komfort bei der Nutzung zu verbessern.
Siehe weitere Informationen und konfiguriere deine Einstellungen