Assign variable int [] values

0

I'm using this method, I'm having difficulty.

  

int [] ReadWriteMultipleRegisters (int startingAddressRead, int   quantityRead, int startingAddressWrite, int [] values)

     

Read / Write Multiple Registers (Function code 23).

     

startingAddressRead: First input register to read.

     

quantityRead: Number of input registers to read.

     

startingAddressWrite: First input register to write.

     

values: Values to write.

     

returns: Int Array which contains the holding registers   [0..quantityRead-1].

I'm having an error assigning the variable int[] values , they could help me.

Thank you.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EasyModbus;

namespace comunicacion_tcp
{
    class Program
    {
        private string IpAddress = "192.168.178.111";
        private int port = 502;
        private ushort startAddres = 4352;
        private ushort quantity = 1;
        private ushort startAddres1 = 4353;
        private int writeData;
        private ModbusClient modbustcp;
        public Program()
        {
            modbustcp = new ModbusClient(IpAddress, port);
            modbustcp.Connect();
            int[] response = modbustcp.ReadWriteMultipleRegisters( startAddres,quantity, startAddres1 , writeData);
            modbustcp.Disconnect();
            Console.WriteLine("value of input register 1" + response[0].ToString());


        }

        static void Main(string[] args)
        {
            Program _program = new Program();
            Console.ReadKey();
        }
    }
}
    
asked by Geraldo Montas 20.08.2018 в 22:41
source

1 answer

0

how it says alanfcm in the comments, you are misplacing the variable writeData , your function expects a int[] and you send a int

//Declaración de variables
int startingAddressRead = 0, quantityRead = 0, startingAddressWrite = 0;
int[] values = new int[5];
//Llamada a la función y almacenado el retorno en 'resultado'
var resultado = ReadWriteMultipleRegisters(startingAddressRead, quantityRead, startingAddressWrite, values);

//Función de ejemplo
int[] ReadWriteMultipleRegisters(int startingAddressRead, int quantityRead, int startingAddressWrite, int[] values) => new int[2];

As you can see in the code snippet, you should have no problem calling your function.

Greetings!

    
answered by 21.08.2018 / 13:46
source