コード例 #1
0
ファイル: Class1.cs プロジェクト: ufjl0683/slSecureAndPD
        void MakeConnect()
        {

            client = new ModbusTCP.Master();
          //  client.OnException += client_OnException;
            client.connect(ip, (ushort)port);
            Console.WriteLine("try COnnect");

        }
コード例 #2
0
        public String ejecutar(ModbusTCP.Master master)
        {
            if (tipo == 2)
            {
                master.ReadHoldingRegister(0, startAddres, 1, ref salida);
            }
            if (tipo == 1)
            {
                master.WriteSingleRegister(0, startAddres, entrada, ref salida);
            }
            StringBuilder respuesta;

            respuesta = new StringBuilder();
            respuesta.Append(instruccion);
            respuesta.Append("-->");
            respuesta.Append(salida[0]);
            respuesta.Append(",");
            respuesta.Append(salida[1]);
            return(respuesta.ToString());
        }
コード例 #3
0
        void GetAllData()
        {
            ModbusTCP.Master master = new ModbusTCP.Master();
            //   data = new byte[29 * 2];
            byte[] tdata = null;
            try
            {
                master.connect(ip, (ushort)port);
                master.ReadHoldingRegister(1, 0, (ushort)(Address.VA), 36, ref tdata);
                if (tdata != null)
                    data = tdata;
                byte[] temp = new byte[4];
                byte[] dest = new byte[4];
                master.ReadHoldingRegister(1, 0, (ushort)(Address.CumulateValue), 2, ref temp);
                if (temp != null)
                {
                    dest[0] = temp[1];
                    dest[1] = temp[0];
                    dest[2] = temp[3];
                    dest[3] = temp[2];
                    CumulateValue = System.BitConverter.ToSingle(dest, 0);
                }

                //this.data = data;
                master.ReadHoldingRegister(1, 0, (ushort)(Address.InstantaneousValue), 2, ref temp);
                if (temp != null)
                {
                    dest[0] = temp[1];
                    dest[1] = temp[0];
                    dest[2] = temp[3];
                    dest[3] = temp[2];
                    InstantaneousValue = System.BitConverter.ToSingle(dest, 0);
                }
                master.ReadHoldingRegister(1, 0, (ushort)(Address.kwh), 2, ref temp);
                if (temp != null)
                {
                    dest[0] = temp[1];
                    dest[1] = temp[0];
                    dest[2] = temp[3];
                    dest[3] = temp[2];
                    kwh = System.BitConverter.ToSingle(dest, 0)/10000;
                }
                master.ReadHoldingRegister(1, 0, (ushort)(Address.CT), 2, ref temp);
                if (temp != null)
                {
                    dest[0] = temp[1];
                    dest[1] = temp[0];
                    dest[2] = temp[3];
                    dest[3] = temp[2];
                    CT = System.BitConverter.ToSingle(dest, 0);
                }
            }
            catch
            {
                //  data = null;
                Console.WriteLine(master.connected);

            }
            finally
            {
                master.Dispose();
            };
        }