private void Write() { try { TPointValue[] values = Points .Select(p => p.Value) .ToArray(); //Get the factory IMasterContextFactory factory = _context.ModbusAdapterProvider.GetFactory(); //Perform the operation using (IModbusMaster master = factory.CreateMaster()) { WriteCore(master, _context.SlaveId, StartAddress, values); } //Mark the points as clean. foreach (var point in Points) { point.IsDirty = false; } } catch (Exception ex) { _context.MessageBoxService.Show(ex, "Write Failed"); } }
private void ReadCore() { IMasterContextFactory factory = _context.ModbusAdapterProvider.GetFactory(); using (IModbusMaster master = factory.CreateMaster()) { TPointValue[] values = ReadCore(master, _context.SlaveId, StartAddress, NumberOfPoints); for (int index = 0; index < values.Length; index++) { Points[index].SetValue(values[index]); } } }