[DllImport("dtl.dll", SetLastError=true)]
static extern public int DTL_C_DEFINE(ref int name_id, StringBuilder def);
Declare Function DTL_C_DEFINE Lib "dtl.dll" (TODO) As TODO
None.
Do you know one? Please contribute it!
None.
Please add some!
public static int DtlCDefine(ref int nameId, StringBuilder defString)
{
new UIPermission(UIPermissionWindow.AllWindows).Demand();
return (UnsafeNativeMethods.DTL_C_DEFINE(ref nameId, defString));
}
bool DtlStatusOk(string dtlFunction, int dtlSts, ref string errorText, string address = null, int ioStat = 0, bool logIt = false)
{
var msg = new StringBuilder(256);
if (dtlSts != DtlSuccess)
{
if (ioStat == 0)
{
ioStat = dtlSts;
}
Dtl.DtlErrorS(ioStat, msg, msg.MaxCapacity);
if (address != null)
{
errorText = dtlFunction + ": " + address + ' ' + msg;
}
else
{
errorText = dtlFunction + ": " + msg;
}
if (logIt)
{
_logger.Warn(LoggerEvent.RockwellPlcError, msg.ToString());
}
return (false);
}
return (true);
}
public void DefineData(string address, int numberOfBytes, bool isWriteable)
{
var definition = new StringBuilder(256);
string slot = " ";
string msgTxt = " ";
int hops = 0;
bool ok = true;
if (numberOfBytes <= MaxTagSize)
{
_address = address;
_sizeOfTag = numberOfBytes;
_elements = _sizeOfTag / 2;
_writeable = isWriteable;
_defined = false;
_type = "WORD";
_access = _writeable ? "MODIFY" : "READ";
switch (_plcType)
{
case 5:
_procType = "PLC5";
_portId = "AB:LOCAL";
_wordSize = 2;
switch (_driverMethod)
{
case 2:
slot = Convert.ToString(_nodeAddress, 8); // octal
break;
case 3:
slot = _ipAddress;
_portId = string.Format("AB:ASA/L:{0:d}", _nodeAddress);
break;
default:
slot = string.Format("{0:d}", _nodeAddress);
break;
}
break;
case 500:
_procType = "SLC500";
_portId = "AB:LOCAL";
_wordSize = 2;
switch (_driverMethod)
{
case 2:
slot = Convert.ToString(_nodeAddress, 8); // octal
break;
default:
slot = Convert.ToString(_nodeAddress);
break;
}
break;
case 5000:
_procType = "PLC5";
_portId = "AB:CIP";
_wordSize = 4;
switch (_driverMethod)
{
case 1:
slot = string.Format("{0:d}.{1:d}", 1, _nodeAddress);
break;
case 2:
string decip = ConvertIp(_ipAddress, ref hops);
slot = string.Format("{0:d}.{1:d}.{2}.{3:d}.{4:d}", 16, hops, decip, 1, _nodeAddress);
break;
default:
ok = false;
break;
}
break;
default:
_procType = "NOTDEFINED";
_portId = "NOTDEFINED";
ok = false;
break;
}
if (ok)
{
definition.Append(string.Format("${0},{1:d},{2},{3},{4},{5},{6},{7:d}",
_address,
_elements,
_type,
_access,
_portId,
slot,
_procType,
_driverId));
_maxWordNo = (_sizeOfTag/_wordSize) - 1;
_nameId = 0;
int dtlSts = Dtl.DtlCDefine(ref _nameId, definition);
if (DtlStatusOk("DtlCDefine", dtlSts, ref msgTxt, "", 0, true))
{
_defined = true;
}
else
{
_logger.Error(LoggerEvent.RockwellPlcError, msgTxt);
throw new PlcException();
}
}
else
{
string msg = string.Format("{0}", "Cannot define data, check configuration");
_logger.Error(LoggerEvent.RockwellPlcError, msg);
throw new PlcException();
}
}
else
{
string msg = string.Format("{0}", "Data file size passed is too large");
_logger.Error(LoggerEvent.RockwellPlcError, msg);
throw new PlcException();
}
}