// checkConnCpuBtn private void checkConnCpuBtn_Click(object sender, EventArgs e) { string errorString; try { using (var plc = new Plc( GetCpuTypeConnect.GetCpuType(Properties.Settings.Default.CpuType), Properties.Settings.Default.IpCpu, Properties.Settings.Default.RackCpu, Properties.Settings.Default.SlotCpu)) //"172.17.132.200" "127.0.0.1" { plc.Open(); if (plc.IsConnected) { statusConnLimitsCpu = true; checkConnCpuBtn.BackColor = Color.Green; } else { statusConnLimitsCpu = false; checkConnCpuBtn.BackColor = Color.Red; } errorString = plc.LastErrorString; logger.Warn(errorString); // Write error log } } catch (Exception ex) { checkConnCpuBtn.BackColor = Color.Red; logger.Error(ex.Message, " TEST connect Cpu to Entity"); // Write error log errorString = ex.Message; } errViewTextBox.Text = errorString; // Show error on screen }
public void WritePositionLimitsCpu(int newPositionRead) { try { using (var plc = new Plc( GetCpuTypeConnect.GetCpuType(Properties.Settings.Default.CpuType), Properties.Settings.Default.IpCpu, Properties.Settings.Default.RackCpu, Properties.Settings.Default.SlotCpu)) //"172.17.132.200" "127.0.0.1" { Thread.Sleep(timeWaitForOpenConnectCpu); plc.Open(); if (plc.IsConnected) { statusConnCpu = true; plc.Write(dbTable + Properties.Settings.Default.DataBlockLimit + dbwTable, newPositionRead); } else { statusConnCpu = false; //TODO need a logger } } } catch (Exception ex) { statusConnCpu = false; //TODO need a logger } }
private Model_dateTime ReadDatetimeLogics(int startByteAdr) { int dataBlock = Properties.Settings.Default.DataBlockDatetime; indexShag = startByteAdr - 1; Model_dateTime modelDateTime = null; //int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0; int[] dateTimeArr = new int[6]; int addShagBytes = indexShag * byteStep; try { using (var plc = new Plc( GetCpuTypeConnect.GetCpuType(Properties.Settings.Default.CpuType), Properties.Settings.Default.IpCpu, Properties.Settings.Default.RackCpu, Properties.Settings.Default.SlotCpu)) //"172.17.132.200" "127.0.0.1" { Thread.Sleep(timeWaitForOpenConnectCpu); plc.Open(); if (plc.IsConnected) { modelDateTime = new Model_dateTime(); for (int i = 0; i < dateTimeArr.Length; i++) { dateTimeArr[i] = GetPlcRead(plc, dataBlock, i * 2 + addShagBytes); } modelDateTime.Id_DateTime = getIdDateTimeForReadDatetime(dateTimeArr); modelDateTime.DateTime = getDateTimeForReadDatetime(dateTimeArr); } else { modelDateTime = null; //TODO need a logger } } } catch (Exception ex) { modelDateTime = null; //TODO need a logger } return(modelDateTime); }
private LimitsCpu ReadLimitsLogics() { LimitsCpu limitsCpu = null; try { using (var plc = new Plc( GetCpuTypeConnect.GetCpuType(Properties.Settings.Default.CpuType), Properties.Settings.Default.IpCpu, Properties.Settings.Default.RackCpu, Properties.Settings.Default.SlotCpu)) //"172.17.132.200" { Thread.Sleep(timeWaitForOpenConnectCpu); plc.Open(); if (plc.IsConnected) { limitsCpu = new LimitsCpu(); limitsCpu.PositionWrite = GetPlcRead(plc, Properties.Settings.Default.DataBlockLimit, 0); limitsCpu.PositionRead = GetPlcRead(plc, Properties.Settings.Default.DataBlockLimit, 2); limitsCpu.PositionMin = GetPlcRead(plc, Properties.Settings.Default.DataBlockLimit, 4); limitsCpu.PositionMax = GetPlcRead(plc, Properties.Settings.Default.DataBlockLimit, 6); } else { limitsCpu = null; //TODO need a logger } } } catch (Exception ex) { limitsCpu = null; //TODO need a logger } return(limitsCpu); }