Navigation

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. knebb
    K
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    knebb

    @knebb

    0
    Reputation
    50
    Posts
    695
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    knebb Follow

    Best posts made by knebb

    This user hasn't posted anything yet.

    Latest posts made by knebb

    • RE: Analog Output- which regsiter to use in modbus?

      @knebb
      Answering myself as I figured it out by try&error. Use address 2. Use values from 0 to 4096 (as documented).

      However, I measured the AO port and never came above 8V (with 4096) with default settings (did not change any of Vref, Vrefint, Voffs, Vdev). Is this measurement issue or something wrong with my code?

      /KNEBB

      posted in UniPi Neuron Series
      K
      knebb
    • Analog Output- which regsiter to use in modbus?

      Hi all,

      I am on the way in using the C library modbus to read/write to my Neuron M103.

      I have a question regarding the documentation:
      Here it writes about the calculation of the value to be set for the desired voltage.

      Now I checked the Register Docs and found two addresses:
            2  Analog Output (raw value) as Obsolete
      3000 Analog Output value as Basic

      So would I write to address 2 using the calculated value?
      Or woud I use the desired voltage (0-10) to write to address 3000?
      Or calculate and write to 3000?

      Thanks!

      /KNEBB

      posted in UniPi Neuron Series
      K
      knebb
    • RE: Need Some sort of Jumpstart

      @ntd

      Sorry to bother you. I think I got it finally!
      Using modbus_read_bits will read nb bits and write (according to the state) 0 or 1 into dst[0]...dst[nb].
      I had thought when reading 4 bits it will write the first state into the first bit of dst, second into the second and so on.

      But no, it writes the state as 0 or 1 into each of the uint8_t .

      I was successfull in reading RO2.8 and DI2.1 together with

      int nb,i;
      uint8_t dst[2];
      nb=2;
      modbus_read_bits(modbus,107,nb,dst);
      for (i=0;i<nb;i++)
      {
        if (dst[i] != 0) 
        {
          printf("Bit %d is %u\n",i,dst[i]);
        } else {
          printf("Bit %d is %u\n",i,dst[i])
        }
      }
      

      And in case RO2.8 is on an DI2.1 is off I will get:
      Bit 0 is 1
      Bit 1 is 0

      Similar this would apply to modbus_read_register();

      Holy sh**, I think I really got it now!

      Thanks for your patience!

      /KNEBB

      posted in Official EVOK API
      K
      knebb
    • RE: How to Read M103 Modbus Doc?

      @ntd
      Perfect!

      Got it finally. I mixed up modbus_read_bits and modbus_read_register. Now working like a charm!

      Thanks a lot!

      /KNEBB

      posted in UniPi Neuron Series
      K
      knebb
    • RE: How to Read M103 Modbus Doc?

      Thanks for the explanation; I figured it already out Raspbian is littleEndian.

      Just to make sure:
      To read i.e. the counter for digital input 2.1 (address 103-104 with DWORD, 32bit in total) I would use:

      uint8_t counter[4];
      modbus_read_bits(bus, 103, 4, counter);
      

      Or this one?

      uint8_t counter1[2],counter2[2];
      modbus_read_bits(bus, 103, 2, counter1);
      modbus_read_bits(bus, 104, 2, counter2);
      

      Would both work?

      Sorry for my dumb question, I am really new to modbus...

      /KNEBB

      posted in UniPi Neuron Series
      K
      knebb
    • RE: How to Read M103 Modbus Doc?

      @ntd :Thanks a lot four your input, I really appreciate it.

      I am just wondering as there seems to be no difference between uint8_t, uint16_t and uint32_t.

      See my question here.
      When using uint8_t the result is exactly the same. All seem to be 32bit long...

      So how does modbus deal with this? It writes only the least significant 8 bits? Others are set to zero?

      /KNEBB

      posted in UniPi Neuron Series
      K
      knebb
    • Testing DI through DO?

      Hi,

      as I am currently coding my application and I am unsure about electronics. Would the following work for testing purposes? To see the DI changes when DO is set ON? Or is this a really bad idea?
      0_1562184703842_DI-DO Test.png

      Thanks a lot!

      /KNEBB

      posted in UniPi Neuron Series
      K
      knebb
    • How to Read M103 Modbus Doc?

      Hi all,

      ok, I manged to use the relays through modbus with libmodbus with my C-code. Now I am trying to use the DI/DO/AO/AI interfaces.

      I see the Neuron Registers Map but I am only able to understand it partially...

      I am aware the function modbus_read_bits() can be usedd to read the DIs. So I open a modbus_tcp connection with the address of DI2.1 for example:

      modbus_read_bits(modbus_handle, 108, nb, *dest);
      

      *dest is supposed to be uint16_t.

      I was able to read the above- finally I have some data in *dest. But how do I have to read the data there? I expected something like "bit 1 tells if the DI is currently ON or OFF and bit2 is the counter while writing bit3 will reset the counter" or stuff like this.

      So I am a little bit lost here to interpret the values I got.

      Nearly the same is for writing. What values should I put into uint16_t to enable the DI?

      And how can I configure the AO?

      Thanks a lot for hints!

      /KNEBB

      posted in UniPi Neuron Series
      K
      knebb
    • RE: Need Some sort of Jumpstart

      Hi,

      for reference purposes even though some questions are still unanswered.
      I was able to set my relays as expected with the following code:

      #include <modbus/modbus.h>
      #include <errno.h>
      #include <stdio.h>
      #include <stdlib.h>
      #include <string.h>
      #include <unistd.h>
      
      void main()
      {
      
      modbus_t *modbusglob;
      int errlvl;
      
      void fieldbus_free(modbus_t *modbus)
      {
              if (modbus != NULL) {
              modbus_close(modbus);
              modbus_free(modbus);
          }
        return;
      }
      
      modbus_t *fieldbus_new(void)
      {
          int err;
          modbus_t *modbus;
          char host[15];
          int port;
      
      // Need to use IP as it does not resolve DNS Names to IPs
          strcpy(host,"127.0.0.1");
          port   = 502;
          modbus = modbus_new_tcp(host, port);
      
          if (modbus == NULL )
          {
               printf("modbus is NULL\n");
              fieldbus_free(modbus);
              exit (55);
          }
      
           err = modbus_connect(modbus);
           if (err  == -1)
           {
              printf("modbus_connect, %s",modbus_strerror(errno));
              fieldbus_free(modbus);
              exit (55);
           };
       
           err=modbus_set_slave(modbus, 0);
           if(  err == -1)
          {
              printf("modbus_set_slave, %s",modbus_strerror(errno));
              fieldbus_free(modbus);
              modbus = NULL;
              exit (55);
          }
      
          return modbus;
      }
      
      modbusglob=fieldbus_new();
      printf("ON\n");
      // Using fixed address of 100 here for first relay (M103), relay 2.2 ist 101 and so on.
      // Using TRUE as synonym for HIGH or ON
      errlvl=modbus_write_bit(modbusglob, 100, TRUE);
      // Just for demo purposes- keep the relay on for 10 seconds
      sleep(10);
      printf("OFF\n");
      errlvl=modbus_write_bit(modbusglob, 100, FALSE);
      fieldbus_free(modbusglob);
      }
      
      posted in Official EVOK API
      K
      knebb
    • RE: Need Some sort of Jumpstart

      @ntd Thanks a lot! I think I got it so far. The adresses of the devices you got from Neuron documentation I assume?

      Only one question left so far. If I want to write the current state of the relay I would use (according to doc):

      //int modbus_write_bit(modbus_t *ctx, int addr, int status);
      errlvl=modbus_write_bit(modbus_handle, 100, status);
      

      I am unsure about the "status". This means I will enable or disable the bit and therefore switching the relay, right?

      Ok, how about reading the DI 2.1?
      Would I use the following?

      //int modbus_read_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest);
      errlvl=modbus_read_bits(modbus_handle, 108, nb, *dest);
      

      Here I have no clue for what I would need the nb... does it mean it will read nb bits? To be stored in nb*dest? I would always use the value 1, wouldn't I? If using 2 it would return the value of the second DI 2.2 in the second bit, correct?

      Thanks a lot in advance!

      /KNEBB

      posted in Official EVOK API
      K
      knebb