Example #1
0
        public void WriteMemory(byte device, UInt32 adress, byte[] data, byte count)
        {
            MEMORY_OPERATE p = new MEMORY_OPERATE();

            p.count         = count;
            p.function_code = (byte)ModbusCodes.MOD_WRITE_FLASH;
            p.device        = device;
            p.adress        = adress;
            p.data          = data;
            CreateMBSend(p);
            WRITECOMPORT(p.DataBuffer, 0, p.BufferSize);
            int            TrustSize = p.BufferSize;
            MEMORY_OPERATE p1        = new MEMORY_OPERATE();

            p1.count_read = count;

            Read(p, p1);
            if (p.BufferSize != TrustSize)
            {
                throw (new Exception("Ошибка WRITE_MEMORY"));
            }
        }
Example #2
0
        public byte[] ReadMemory(byte device, UInt32 adress, byte count)
        {
            MEMORY_OPERATE p = new MEMORY_OPERATE();

            p.count_read    = count;
            p.function_code = (byte)ModbusCodes.MOD_READ_FLASH;
            p.device        = device;
            p.adress        = adress;
            CreateMBSend(p);

            WRITECOMPORT(p.DataBuffer, 0, p.BufferSize);

            MEMORY_OPERATE p1 = new MEMORY_OPERATE();

            p1.count = count;
            int TrustSize = p1.BufferSize;

            Read(p, p1);
            if (p1.BufferSize != TrustSize)
            {
                throw (new Exception("Ошибка Read_MEMORY"));
            }
            return(p1.data);
        }