Beispiel #1
0
        private void Write_array(float[] array, ushort adress)
        {
            try
            {
                modbus.Open();
                for (int i = 0; i < array.Length; i++)
                {
                    modbus.WriteFloat((ushort)(adress + 2 * i), array[i]);
                }
            }
            catch (Exception ex)
            {
                throw (new Exception(ex.Message));
            }
            finally
            {
                modbus.Close();
            }

            //modbus.WriteMemory(0, adress, b_buf, Convert.ToByte(Count * 4));
        }
Beispiel #2
0
            public void WriteRegister(ushort reg, short value)
            {
                Modbus link = new Modbus();

                link.Open(port, 9600, 8, Parity.None, StopBits.Two);
                short[] val = { value };
                bool    ret = link.SendFc3(address, reg, 1, ref val);

                if (!ret)
                {
                    throw new EngineMessageException(
                              "Writing 0x" + value.ToString("x") +
                              " to register 0x" + reg.ToString("x") + " failed: " + link.modbusStatus);
                }
                link.Close();
            }
Beispiel #3
0
            public short ReadRegister(ushort reg)
            {
                Modbus link = new Modbus();

                link.Open(port, 9600, 8, Parity.None, StopBits.Two);
                short[] val = new short[1];
                bool    ret = link.SendFc3(address, reg, 1, ref val);

                if (!ret)
                {
                    throw new EngineMessageException(
                              "Read from register 0x" + reg.ToString("x") + " failed: " + link.modbusStatus);
                }
                link.Close();
                return(val[0]);
            }