Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

DTL_C_DEFINE (dtl)
 
.
Summary
TODO - a short description

C# Signature:

[DllImport("dtl.dll", SetLastError=true)]
static extern public int DTL_C_DEFINE(ref int name_id, StringBuilder def);

VB Signature:

Declare Function DTL_C_DEFINE Lib "dtl.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

    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();
        }
    }

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions