• Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Reading digital input from switch

    Scheduled Pinned Locked Moved CODESYS
    4 Posts 2 Posters 2.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • O
      OlivierP
      last edited by

      Hi all,

      I'm playing around for the first time with my new Unipi Neuron L503. I've set-up all the required things for Codesys (based on the Codesys-Unipi manual). I can successfully connect to the Unipi using Codesys :)

      But I'm having some difficulties understanding the I/O mapping, I just used the Rapsberry before using Codesys and it was easy to identify/understand the I/O.

      Is there anyone that can give me some hints? Because I can't find the "link" between the "Modbus Registers" document and what I see on the "Modbus TCPSlave I/O mapping".

      Example: I've connected a switch to DI1.4 (LED is green) but I can't find a single "TRUE" value in the "Modbus TCPSlave I/O mapping" while in RUN mode.

      Thank you for helping a newbie out :)

      1 Reply Last reply
      Reply Quote 0
      • O
        OlivierP
        last edited by

        Okay, I made some progress but I still don't understand all of it. So it seems I need some PRG in order to set/read the values from the PLC. So I skinned out the UnipiDemo program. Result:

        • I kept the GVL (Application)

        • I kept the PLC_PRG

        • I removed/disabled the other items from "Application". So I'm able to read the status of my connected switch. But I would like to understand what the code in PLC_PRG does? Can anyone explain what the code below does and how it relates to the "Modbus TCPSlave I/O mapping" values read from the PLC?

        NeuronL50xGroup1.wLED := wLED;
        NeuronL50xGroup1.wDigitalOutput := wDO;
        wDI := NeuronL50xGroup1.wDigitalInput;
        IF xSetDebounce THEN
        	NeuronL50xGroup1.wDI1Debounce := wDI1Debounce;
        	NeuronL50xGroup1.wDI2Debounce := wDI2Debounce;
        	NeuronL50xGroup1.wDI3Debounce := wDI3Debounce;
        	NeuronL50xGroup1.wDI4Debounce := wDI4Debounce;
        END_IF
        NeuronL50xGroup1.xSetDI1Debounce := xSetDebounce;
        NeuronL50xGroup1.xSetDI2Debounce := xSetDebounce;
        NeuronL50xGroup1.xSetDI3Debounce := xSetDebounce;
        NeuronL50xGroup1.xSetDI4Debounce := xSetDebounce;```
        1 Reply Last reply
        Reply Quote 0
        • D
          DavidCozens
          last edited by

          Hi Oliver,

          The POU NeuronL50xGroup1 is a function block automatically created when the IO device for the Neuron is added to the application. It provides easy access to all of the IO and features for Group1, just add the device and then access the IO through the VAR and methods on the function block.

          The statements that you have identified are writing to the variables in the function block. these in turn end up mapped to the registers in the channels for the device.

          The mechanism of creating channels, and then mapping the values to variables is the standard CODESYS mechanism for modbus devices. UniPi Neuron for CODESYS adds naming for all channels and coils to make this easier. It also adds a function block for Group 1 (which is identical on all Neuron) and performs all of the mapping automatically.

          I would be interested in your opinion on this approach of automatically creating a function block with all of the IO mapped. For some users it will be helpful, for others it may not provide what they want. I am considering if I should add the same support for other groups.

          For now access to groups 2 and 3 requires you to manually create channels for the IO you wish to access and then map these to VAR in you application. There are some function blocks in the supplied library that may be helpful. This is the same for all CODESYS modbus devices.

          There is more detailed help in the datasheet.

          1 Reply Last reply
          Reply Quote 0
          • O
            OlivierP
            last edited by

            Thank you for the clarification, this is exactly what I did... but I must have missed something, now it works :)

            I don't think it is needed to add the other channels already, seems easy enough.

            1 Reply Last reply
            Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post