Giter VIP home page Giter VIP logo

Comments (4)

timyhac avatar timyhac commented on June 25, 2024

This is a good pickup, according to once of my go-to sources:

Once disposed, an object is beyond redemption. It cannot be reactivated, and calling its methods or properties (other than Dispose) throws an ObjectDisposedException.
Albahari, Joseph; Albahari, Ben. C# 7.0 in a Nutshell (p. 514). O'Reilly Media. Kindle Edition.

FYI Internally, IsInitialized is separate to IsDisposed - the tag handle creation does some communication with the PLC, and libplctag core library has the concept of an async constructor. Of course in C# there is no such thing as an async constructor, so we decided to separate the initialization, so it can be lazily initialized (or if you wanted to create several hundred tags at once, you could do them all at once, asynchronously, rather than one after the other).

from libplctag.net.

timyhac avatar timyhac commented on June 25, 2024

Btw @romanka5150 - what you've done is fine. You don't need to call Dispose() yourself because the GarbageCollector will do this for you.

from libplctag.net.

jkoplo avatar jkoplo commented on June 25, 2024

@romanka5150 - it also looks like you're using the lower level (native) class for Tag. That's fine by all means, but there is also an implementation that handles types and offsets for you.

It looks like your setting up a length read in order to eventually retrieve a string.

Here's an example of the higher level syntax, in this case writing an array of strings:

            var stringTag = new Tag<StringPlcMapper, string[]>()
            {
                Name = "MY_STRING_1D[0]",
                Gateway = gateway,
                Path = path,
                Protocol = Protocol.ab_eip,
                PlcType = PlcType.ControlLogix,
                ArrayDimensions = new int[] { 100 },
            };
            var r = new Random((int)DateTime.Now.ToBinary());

            for (int ii = 0; ii < stringTag.Value.Length; ii++)
                stringTag.Value[ii] = r.Next().ToString();

            stringTag.Write();

More examples here: https://github.com/libplctag/libplctag.NET/tree/master/src/Examples/CSharp%20DotNetCore

from libplctag.net.

jkoplo avatar jkoplo commented on June 25, 2024

This should be closed by #99.
It'll make it into the next build.

from libplctag.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.