private (bool IsError, string ErrorMessage, List <Dose> Datas) GetPLCData() { var datas = new List <Dose>(); PlcMemory dm = PlcMemory.DM; short resultCountCells = 0; EtherNetPLC cp1 = new EtherNetPLC(); try { cp1.Link(_configApp.IpAddress, _configApp.PortAddress, 300); cp1.ReadWord(dm, COUNTER_CELLS_FOR_READING, out resultCountCells); if (resultCountCells > 0) { short total = (short)(resultCountCells / PACKEGES); //целое число пакетов (кратное числу возможному для приема пакетов за раз). short mod = (short)(resultCountCells % PACKEGES); //остаток пакетов от целого числа short[] data = new short[600]; for (int i = 0; i < total; i++) { cp1.ReadWords(dm, (short)(START_CELL + (i * PACKEGES * COUNT_DATAROWS)), (short)((PACKEGES * COUNT_DATAROWS)), out data); datas.AddRange(TransformArrayToDose(data).ToArray()); } if (mod > 0) { cp1.ReadWords(dm, (short)(START_CELL + ((short)total * PACKEGES * COUNT_DATAROWS)), (short)((mod * COUNT_DATAROWS)), out data); datas.AddRange(TransformArrayToDose(data).ToArray()); } cp1.WriteWord(dm, COUNTER_CELLS_FOR_READING, 0); } // cp1.WriteWord(dm, COUNTER_CELLS_FOR_READING, 0); return(false, "", datas.ToList()); } catch { return(true, "Connection to PLC didn't establish", null); } finally { cp1.Close(); } }