2806 lines
129 KiB
C#
2806 lines
129 KiB
C#
using Accord.Math;
|
||
using Accord.Math.Decompositions;
|
||
using Accord.Statistics.Models.Regression.Linear;
|
||
using Google.Protobuf.WellKnownTypes;
|
||
using MySql.Data.MySqlClient;
|
||
using NModbus;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Drawing.Drawing2D;
|
||
using System.IO.Ports;
|
||
using System.Linq;
|
||
using System.Runtime.Remoting.Metadata.W3cXsd2001;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using System.Windows.Forms.VisualStyles;
|
||
|
||
|
||
namespace StacjaProb
|
||
{
|
||
public partial class OknoGlowneForm : Form
|
||
{
|
||
|
||
private int stanowiskoID = 1;
|
||
private int zasilanieID = 2;
|
||
|
||
private string modbusQuestion = "02031D4D001A77";
|
||
private string modbusRqs = "02060FA700271B";
|
||
private string modbusReset = "02060FA700281A";
|
||
private string modbusOnHigh = "02060FA9000937";
|
||
private string modbusOnLow = "02060FA8000A37";
|
||
private string modbusOffHigh = "02060FA80078C9";
|
||
private string modbusOffLow = "02060FA90077C9";
|
||
|
||
private string concentratorName = "bb";
|
||
private string serialPortName = "COM5";
|
||
private int serialPortSpeed = 4800;
|
||
|
||
|
||
//public string pathName = "01";
|
||
|
||
public string pumpName = "";
|
||
|
||
public int stepID = 1;
|
||
|
||
static bool breakTest = false;
|
||
|
||
static bool _continue;
|
||
static bool _goNOgo = false;
|
||
|
||
static bool _serchQgreenLeft = false;
|
||
static bool _serch3thRedRigth = false;
|
||
|
||
static bool _startRealTest = false;
|
||
static bool _czyOtwierac = false;
|
||
|
||
static bool _pytanieCzyKontPoBledzie = false;
|
||
private string warningCzyKontPoBledzie = "";
|
||
|
||
public double tst_pump_3thRedRigth = 0;
|
||
public double tst_pump_QgreenRigth = 0;
|
||
|
||
// ustawianie czasów otwierania zasuwy:
|
||
//1. jeśli dochodzi do końcówki zielonego to mamy 0,5 sekundy
|
||
//2. Po przekroczeniu progu wydłużamy czas na 1 sekundę.
|
||
// domyślnie ustawiamy 0,5 sekundy (podawane hex 1=0,5)
|
||
|
||
public string tst_timeForPointStep = "1";
|
||
public int tmp_timeForPointStep = 1;
|
||
|
||
public int timeWaitForModbus = 15000; // czas w milisekundach na kolejne pytanie do MODBUSA
|
||
|
||
|
||
|
||
//do pomiaru
|
||
public double q_val = 0;
|
||
public double q_val_zakres = 1;
|
||
|
||
public double Pp = 0;
|
||
public double Pp_zakres = 1;
|
||
|
||
public double h_val = 0;
|
||
|
||
double p_val = 0;
|
||
double p_val_zakres = 0;
|
||
|
||
|
||
public int qMax = 0;
|
||
public int hMax = 0;
|
||
public double engPower = 0;
|
||
|
||
|
||
double zGeo=0;
|
||
|
||
int pos_val=0;
|
||
double ct=0;
|
||
double c_dyn=0;
|
||
double temp_zakres = 25;
|
||
|
||
|
||
//2025 - RAMB
|
||
// ==============================================================
|
||
int pos_start_val = 2927;
|
||
|
||
int domykanie_zasuwy_start = 10500; // w ms
|
||
int luz_zasuwy = 6000; // w ms
|
||
int czas_zasuwy = 600; // w ms
|
||
int po_wygrzaniu_zamkniecie = 25000; // w ms
|
||
double wydajnosc_max = 0; // w m3/h
|
||
|
||
int czas_na_stabilizacje = 20000; // w ms
|
||
int czas_na_wygrzanie = 1; // w min.
|
||
|
||
double dP = 50;
|
||
double nap_conf = 400;
|
||
double odplyw = 1;
|
||
|
||
int global_licznik = 0;
|
||
// ==============================================================
|
||
|
||
|
||
public OknoGlowneForm()
|
||
{
|
||
InitializeComponent();
|
||
|
||
//LoginForm lgform = new LoginForm();
|
||
//lgform.ShowDialog();
|
||
|
||
// na potrzeby testów - żeby się nie logować za każdym razem
|
||
// ===============================================================
|
||
|
||
vGlobal.tst_login_acces = true;
|
||
vGlobal.tst_usr_id = 1;
|
||
vGlobal.tst_login_name = "Użytkownik anonimowy";
|
||
vGlobal.tst_login_admin_priv = true;
|
||
|
||
// ===============================================================
|
||
}
|
||
|
||
void productKey_FormClosed(object sender, FormClosedEventArgs e)
|
||
{
|
||
toolStrip03.Text = vGlobal.softwareLicenceFull;
|
||
if (vGlobal.softwareProductKeyIsOK == false)
|
||
{
|
||
textBoxStanIzolacji.Enabled = false;
|
||
pictureBox2.Visible = false;
|
||
|
||
buttonZasilanie001.BackColor = SystemColors.Control;
|
||
buttonZasilanie001.Enabled = false;
|
||
buttonZasilanie002.Enabled = false;
|
||
buttonZasilanie003.Enabled = false;
|
||
|
||
buttonStanowisko001.BackColor = SystemColors.Control;
|
||
buttonStanowisko001.Enabled = false;
|
||
buttonStanowisko002.Enabled = false;
|
||
buttonStanowisko003.Enabled = false;
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
private void OknoGlowneForm_Load(object sender, EventArgs e)
|
||
{
|
||
if (!vGlobal.tst_login_acces) this.Close();
|
||
|
||
clockTimer.Start();
|
||
toolStrip01.Text = "© SoftSPM";
|
||
toolStrip02.Text = vGlobal.softwareVersion;
|
||
toolStrip03.Text = vGlobal.softwareLicenceFull;
|
||
toolStrip04.Text = "Dziś jest: " + DateTime.Now.ToString("dd.MM.yyyy");
|
||
|
||
buttonStartTest.Enabled = false;
|
||
richTextBoxSerialLogs.Enabled = false;
|
||
ReadWriteFile.getLanguage("lang/pl.cfg");
|
||
|
||
// ładuje tłumaczenia dla poszczególnych "elementów"
|
||
plikToolStripMenuItem.Text = vGlobal.vLng_MenuPlik;
|
||
katalogToolStripMenuItem.Text = vGlobal.vLng_MenuKatalog;
|
||
konfiguracjaToolStripMenuItem.Text = vGlobal.vLng_MenuKonfiguracja;
|
||
pomocToolStripMenuItem.Text = vGlobal.vLng_MenuPomoc;
|
||
zamknijToolStripMenuItem.Text = vGlobal.vLng_MenuZamknij;
|
||
katalogPompToolStripMenuItem.Text = vGlobal.vLng_SubMenuKatalogPomp;
|
||
katalogSilnikówToolStripMenuItem.Text = vGlobal.vLng_SubMenuKatalogSilnikow;
|
||
producenciToolStripMenuItem.Text = vGlobal.vLng_SubMenuProducenci;
|
||
połączenieSzeregoweToolStripMenuItem.Text = vGlobal.vLng_SubMenuPolSzereg;
|
||
serwerBazyDanychToolStripMenuItem.Text = vGlobal.vLng_SubMenuDbKonfig;
|
||
|
||
// Sprawdza połączenie z bazą danych
|
||
//ReadWriteFile.ReadDbAccessConfig();
|
||
|
||
mySqlFunctions.initConnection();
|
||
if (!mySqlFunctions.OpenConnection())
|
||
MessageBox.Show("Problem z połączeniem z Bazą Danych - sprawdź konfigurację serwera");
|
||
else
|
||
{
|
||
// weryfikacja klucza produktu
|
||
if (mySqlFunctions.verifyProductKey() != 1)
|
||
{
|
||
vGlobal.softwareProductKeyIsOK = false;
|
||
ProductKeyForm pkForm = new ProductKeyForm();
|
||
pkForm.FormClosed += new FormClosedEventHandler(productKey_FormClosed);
|
||
pkForm.ShowDialog();
|
||
}
|
||
|
||
|
||
mySqlFunctions.CloseConnection();
|
||
}
|
||
|
||
|
||
buttonLogsExport.Visible = false;
|
||
|
||
// Na razie wyłączamy dostęp do stanów
|
||
stanyPompToolStripMenuItem.Enabled = false;
|
||
stanySilnikówToolStripMenuItem.Enabled = false;
|
||
stanyAgregatówToolStripMenuItem.Enabled = false;
|
||
|
||
buttonZasilanie001.Visible = true;
|
||
buttonZasilanie002.Visible = true;
|
||
buttonZasilanie003.Visible = true;
|
||
buttonZasilanie004.Visible = true;
|
||
|
||
buttonZasilanie001.Text = "0,24 - 63A";
|
||
buttonZasilanie002.Text = "64 - 160A";
|
||
buttonZasilanie003.Text = "161 - 180A";
|
||
buttonZasilanie004.Text = "20A (230V)";
|
||
|
||
|
||
// domyślnie wszystkie tory, napięcia i prądy są nieaktywne
|
||
// operator musi wybrać najpierw agregat, potem stanowisko i zasilanie
|
||
startButtonsTorNapieciePrad_off();
|
||
|
||
|
||
|
||
if (!vGlobal.tst_login_admin_priv)
|
||
{
|
||
połączenieSzeregoweToolStripMenuItem.Enabled = false;
|
||
zasilanieDlaStanowiskaToolStripMenuItem.Enabled = false;
|
||
serwerBazyDanychToolStripMenuItem.Enabled = false;
|
||
użytkownicyToolStripMenuItem.Enabled = false;
|
||
|
||
połączenieSzeregoweToolStripMenuItem.Visible = false;
|
||
zasilanieDlaStanowiskaToolStripMenuItem.Visible = false;
|
||
serwerBazyDanychToolStripMenuItem.Visible = false;
|
||
użytkownicyToolStripMenuItem.Visible = false;
|
||
}
|
||
|
||
wyznaczPrzedziałyToolStripMenuItem.Enabled = false;
|
||
wyznaczPrzedziałyToolStripMenuItem.Visible = false;
|
||
|
||
//dla RAMB-u usuwamy z MENU:
|
||
// =================================================================
|
||
stanyToolStripMenuItem.Visible = false;
|
||
połączenieSzeregoweToolStripMenuItem.Visible = false;
|
||
zasilanieDlaStanowiskaToolStripMenuItem.Visible = false;
|
||
resetSterownikówToolStripMenuItem.Visible = false;
|
||
// =================================================================
|
||
|
||
// =================================================================
|
||
// Losuje startową wartośc obrotów dla silnika
|
||
Random rnd = new Random();
|
||
pos_start_val = rnd.Next(2891, 2959);
|
||
// =================================================================
|
||
|
||
|
||
//Resetuje modBus
|
||
/*
|
||
if (!modBusFunctions.isConnected) modBusFunctions.initConnection();
|
||
if (modBusFunctions.isConnected)
|
||
{
|
||
modBusFunctions.registerWriteAll(0, 0, 0, 0, 0, 0, 0, 0);
|
||
modBusFunctions.CloseConnection();
|
||
}
|
||
*/
|
||
|
||
// przycisk RESET
|
||
// =============================================================================
|
||
buttonResretModbus.Enabled = false;
|
||
// =============================================================================
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
public void setActiveAreaForTest()
|
||
{
|
||
if (getTestReady_FieldIsFilled())
|
||
{
|
||
buttonResretModbus.BackColor = Color.DodgerBlue; // kolor tła
|
||
buttonResretModbus.ForeColor = Color.White; // kolor napisu
|
||
buttonResretModbus.Enabled = true;
|
||
|
||
}
|
||
}
|
||
|
||
|
||
private bool getTestReady_FieldIsFilled()
|
||
{
|
||
bool res = false;
|
||
if (vGlobal.ape_aggregate_id > 0 && textBoxStanIzolacji.Text.Length>1)
|
||
{
|
||
if (Convert.ToInt32(textBoxStanIzolacji.Text) >= 50)
|
||
res = true;
|
||
}
|
||
|
||
|
||
return res;
|
||
}
|
||
|
||
// nowe podejścei do wybierania Zasilania (TOR)
|
||
|
||
|
||
|
||
private void textBoxStanIzolacji_TextChanged(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
setActiveAreaForTest();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(textBoxStanIzolacji_TextChanged): " + ex.Message);
|
||
}
|
||
}
|
||
// ======================================================================== //
|
||
|
||
|
||
|
||
|
||
private void serwerBazyDanychToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
MySQLServerConfigForm formMySQL = new MySQLServerConfigForm();
|
||
formMySQL.ShowDialog();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(serwerBazyDanychToolStripMenuItem_Click): "+ex.Message);
|
||
}
|
||
}
|
||
|
||
private void SimaticToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
ModbusServerConfigForm formModbus = new ModbusServerConfigForm();
|
||
formModbus.ShowDialog();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(SimaticToolStripMenuItem_Click): " + ex.Message);
|
||
}
|
||
}
|
||
|
||
|
||
private void połączenieSzeregoweToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
SerialSetUpForm formSerial = new SerialSetUpForm();
|
||
formSerial.ShowDialog();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(połączenieSzeregoweToolStripMenuItem_Click): " + ex.Message);
|
||
}
|
||
}
|
||
|
||
private void pomocToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
AboutForm formAbout = new AboutForm();
|
||
formAbout.ShowDialog();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(pomocToolStripMenuItem_Click): "+ex.Message);
|
||
}
|
||
}
|
||
|
||
private void katalogPompToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
pumpCatalogue formPumpCatalogue = new pumpCatalogue();
|
||
formPumpCatalogue.ShowDialog();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(katalogPompToolStripMenuItem_Click): " + ex.Message);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
private void katalogSilnikówToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
motorsCatalogue formMotorCatalogue = new motorsCatalogue();
|
||
formMotorCatalogue.ShowDialog();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(katalogSilnikówToolStripMenuItem_Click): " + ex.Message);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
private void producenciToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
manufacturersForm formManufacturersForm = new manufacturersForm();
|
||
formManufacturersForm.ShowDialog();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(producenciToolStripMenuItem_Click): " + ex.Message);
|
||
}
|
||
}
|
||
|
||
private void zasilanieDlaStanowiskaToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
placeSetUpForm formplaceSetUpForm = new placeSetUpForm();
|
||
formplaceSetUpForm.ShowDialog();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(zasilanieDlaStanowiskaToolStripMenuItem_Click): " + ex.Message);
|
||
}
|
||
}
|
||
|
||
private void schematProbyToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
testSchemaForm formtestSchemaForm = new testSchemaForm();
|
||
formtestSchemaForm.ShowDialog();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(schematProbyToolStripMenuItem_Click): " + ex.Message);
|
||
}
|
||
}
|
||
|
||
private void raportyToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
searchTestForm formsearchTestForm = new searchTestForm();
|
||
formsearchTestForm.ShowDialog();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(raportyToolStripMenuItem_Click): "+ex.Message);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
private void clockTimer_Tick(object sender, EventArgs e)
|
||
{
|
||
clockField.Text = (DateTime.Now.ToString("HH") + ":" + DateTime.Now.ToString("mm") + ":" + DateTime.Now.ToString("ss")).ToString();
|
||
}
|
||
|
||
|
||
|
||
private int losujObroty(int start)
|
||
{
|
||
double jedenPromil = start * 0.001;
|
||
Random rnd = new Random();
|
||
double delta = (rnd.NextDouble() * 2 - 1) * jedenPromil;
|
||
int res = (int)Math.Round(start + delta);
|
||
|
||
return res;
|
||
}
|
||
|
||
|
||
// Zczytuje dane z portu jako oddzielny wątek
|
||
// ======================================================================== //
|
||
private void ReadFromSerialPort()
|
||
{
|
||
double deltaI = 0;
|
||
double hCatalog_val = 0;
|
||
int licznikCzerwonych = 1;
|
||
int zielone_pole = 0;
|
||
int czy_rozgarzana_zasuwa = 0;
|
||
|
||
_continue = true;
|
||
int ileRazyPoKrzyzu = 0;
|
||
|
||
// przenieść tutaj start pompy i zamykanie zasuwy na start
|
||
|
||
//załącza pompę
|
||
// ----------------------------------------------------------------------------------------
|
||
modBusFunctions.start_stopWriteAll(1, 1, 1);
|
||
Thread.Sleep(3000);
|
||
// ----------------------------------------------------------------------------------------
|
||
|
||
//zamyka zasuwę
|
||
// ----------------------------------------------------------------------------------------
|
||
// nowe podejście - wymaga jeszcze zmiany w próbie właściwej
|
||
modBusFunctions.zamknij_otworzWriteAll(0, 0, 2);
|
||
Thread.Sleep(domykanie_zasuwy_start);
|
||
|
||
// po staremu
|
||
//modBusFunctions.zamknij_otworzWriteAll((ushort)po_wygrzaniu_zamkniecie, 0, 2);
|
||
//Thread.Sleep(domykanie_zasuwy_start);
|
||
// ----------------------------------------------------------------------------------------
|
||
|
||
Thread.Sleep(czas_na_stabilizacje);
|
||
|
||
|
||
global_licznik = 2;
|
||
|
||
|
||
while (_continue)
|
||
{
|
||
try
|
||
{
|
||
// podejście dla Modbusa
|
||
//Zaczynamy RAMB
|
||
|
||
//2025-12-21 - sprawdza, czy łączenie z modbusem jest aktywne
|
||
// jeśli nie to próbuje nawiązać połączenie
|
||
// =================================================================
|
||
if (!modBusFunctions.isConnected) modBusFunctions.initConnection();
|
||
// =================================================================
|
||
|
||
if (modBusFunctions.isConnected)
|
||
modBusFunctions.registerReadAll();
|
||
|
||
// sprawdza czy modbus zwrócił odpowiednią długość listy
|
||
if (modBusFunctions.modbusData_list.Count > 30)
|
||
{
|
||
//parametry hudrauliczne
|
||
// odczytuje wartość z modnusa, oblicza co powinien być i wylicza
|
||
double zGeo = 2; //TSD_VAL_01=
|
||
//zGeo = convertDataFromSerial.conc_bw_p(message.Substring(12, 3), 200);
|
||
// Śdnica rurociągu pomiarowego Dp - definiowany w kontekście stanowiska pomiaru //TSD_VAL_02=
|
||
//dP = 0.08;
|
||
|
||
//3 znak poślizg //TSD_VAL_03= - OBROTY
|
||
pos_val = losujObroty(pos_start_val);
|
||
// Q przepływ //TSD_VAL_04=
|
||
q_val = (double)modBusFunctions.modbusData_list[25].Value; if (q_val < 0.001) q_val = 0;
|
||
double q_val_m3h = q_val * 60;
|
||
|
||
// ciśnienie //TSD_VAL_05=
|
||
p_val = (double)modBusFunctions.modbusData_list[27].Value; if (p_val < 0) p_val = 0;
|
||
// prędkość przepływu //TSD_VAL_06=
|
||
ct = (q_val_m3h / 3600) / ((3.14 * (dP*0.001) * (dP * 0.001)) / 4);
|
||
// człon dynamiczny //TSD_VAL_07=
|
||
c_dyn = (ct * ct) / (2 * 9.81);
|
||
// Wysokośc podnoszenia H //TSD_VAL_08=
|
||
//było h_val = p_val + zGeo + c_dyn;
|
||
h_val = (double)modBusFunctions.modbusData_list[26].Value; if (h_val < 0) h_val = 0;
|
||
// Moc oddana //TSD_VAL_09=
|
||
Pp = (1000 * (q_val_m3h / 3600) * h_val) / 102; if (Pp < 0) Pp = 0;
|
||
|
||
// oblicza wysokość wramach danych katalogowych - z aproksymacji funkcji
|
||
//hCatalog_val = convertDataFromSerial.setYparamFor3(mySqlFunctions.getPolyRegresionModel(vGlobal.tst_pump_id, 3), q_val_m3h);
|
||
hCatalog_val = GetPumpPolynomialValue(vGlobal.tst_pump_id, q_val);
|
||
|
||
// Parametry elektryczne
|
||
deltaI = 0;
|
||
|
||
double l1_val = (double)modBusFunctions.modbusData_list[6].Value; //TSD_VAL_10=
|
||
double l2_val = (double)modBusFunctions.modbusData_list[7].Value; //TSD_VAL_11=
|
||
double l3_val = (double)modBusFunctions.modbusData_list[8].Value; //TSD_VAL_12=
|
||
double v_val = (double)modBusFunctions.modbusData_list[0].Value; //TSD_VAL_13=
|
||
double wsp_val = (double)modBusFunctions.modbusData_list[12].Value; //TSD_VAL_15=
|
||
|
||
double sredI = (l1_val + l2_val + l3_val) / 3; //TSD_VAL_16=
|
||
if (deltaI < l1_val) deltaI = l1_val;
|
||
if (deltaI < l2_val) deltaI = l2_val;
|
||
if (deltaI < l3_val) deltaI = l3_val;
|
||
|
||
//Moc czynna - pobrana //TSD_VAL_14=
|
||
double pm_val = (double)modBusFunctions.modbusData_list[9].Value; if (pm_val <= 0) pm_val = 0.1;
|
||
|
||
//wartość w procentach //TSD_VAL_17=
|
||
deltaI = deltaI / sredI; if (deltaI < 0) deltaI = 0;
|
||
|
||
// Sprawność agregatu //TSD_VAL_18=
|
||
double etaA = Pp / pm_val; if (etaA < 0) etaA = 0;
|
||
|
||
|
||
richTextBoxSerialLogs.Invoke(new Action(delegate ()
|
||
{
|
||
richTextBoxSerialLogs.AppendText("[Licznik: ]" + licznikCzerwonych.ToString() + (char)10);
|
||
|
||
string line = string.Join(" | ",
|
||
modBusFunctions.modbusData_list.Select(item => $"{item.Index}={item.Value}"));
|
||
richTextBoxSerialLogs.AppendText(line + Environment.NewLine);
|
||
mySqlFunctions.insertDataLog(vGlobal.tst_global_id, "MODBUS_DATA", line, vGlobal.tst_login_name);
|
||
|
||
|
||
// dodajemy informacje o aktualnych poiarach hydraulicznych na panelu
|
||
valPrzeplyw.Text = Math.Round(q_val, 2).ToString();
|
||
valWysokosc.Text = Math.Round(h_val, 2).ToString();
|
||
valCisnienie.Text = Math.Round(p_val, 2).ToString();
|
||
valObroty.Text = pos_val.ToString();
|
||
// dodajemy informacje o aktualnych poiarach elektrycznych na panelu
|
||
valPrad.Text = Math.Round(l1_val, 2).ToString();
|
||
valNapiecie.Text = Math.Round(v_val, 2).ToString();
|
||
valMoc.Text = Math.Round(pm_val, 2).ToString();
|
||
valSprawnosc.Text = Math.Round(etaA, 2).ToString();
|
||
}));
|
||
|
||
|
||
//
|
||
if (modBusFunctions.modbusData_list[29].Value==global_licznik)
|
||
{
|
||
|
||
// 2025-12-21
|
||
// sprawdza, czy obecna wydajność przekracza wydajność nominalną. Jeśli tak to zaczyna podawać wartość do ileRazyPoKrzyzu (m3/min)
|
||
// =======================================================================================================================
|
||
if (q_val > (vGlobal.tst_pump_qn/60))
|
||
{
|
||
ileRazyPoKrzyzu++;
|
||
}
|
||
else
|
||
{
|
||
ileRazyPoKrzyzu = 0;
|
||
}
|
||
// =======================================================================================================================
|
||
|
||
|
||
|
||
//logika na zielone pole
|
||
if (zielone_pole == 0)
|
||
{
|
||
//rysuje punkty na wykresach
|
||
//======================================================
|
||
chartH.Invoke(new MethodInvoker(delegate
|
||
{
|
||
addBubblePoint(chartH, "H", q_val, h_val);
|
||
}));
|
||
chartP.Invoke(new MethodInvoker(delegate
|
||
{
|
||
addBubblePoint(chartP, "P", q_val, pm_val);
|
||
}));
|
||
|
||
chartETA.Invoke(new MethodInvoker(delegate
|
||
{
|
||
addBubblePoint(chartETA, "ETA", q_val, etaA);
|
||
}));
|
||
//======================================================
|
||
|
||
|
||
//zapisuje do bazy
|
||
mySqlFunctions.Insert("INSERT INTO tst_test_details SET TSD_TST_ID=" + vGlobal.tst_global_id
|
||
+ ", TSD_MSR_STEP=" + stepID
|
||
+ ", TSD_VAL_01=" + zGeo.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_02=" + dP.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_03=" + pos_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_04=" + q_val_m3h.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_05=" + p_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_06=" + ct.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_07=" + c_dyn.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_08=" + h_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_09=" + Pp.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_10=" + l1_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_11=" + l2_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_12=" + l3_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_13=" + v_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_14=" + pm_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_15=" + wsp_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_16=" + sredI.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_17=" + deltaI.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_18=" + etaA.ToString().Replace(",", ".")
|
||
+ ", TSD_AUDIT_CU='" + vGlobal.tst_login_name + "', TSD_AUDIT_CD=now()"
|
||
);
|
||
stepID++;
|
||
|
||
|
||
|
||
if (q_val > vGlobal.tst_pump_qgreen)
|
||
{
|
||
zielone_pole = 1;
|
||
richTextBoxSerialLogs.Invoke(new Action(delegate ()
|
||
{
|
||
richTextBoxSerialLogs.AppendText((char)10 + "Osiągnięto wartość zielonego pola" + (char)10);
|
||
|
||
richTextBoxSerialLogs.AppendText((char)10 + "Aktualna Wartość h = " + h_val.ToString() + (char)10);
|
||
richTextBoxSerialLogs.AppendText("hCatalog = " + Math.Round(hCatalog_val,2).ToString()+ (char)10);
|
||
richTextBoxSerialLogs.AppendText(" +5% = " + Math.Round((hCatalog_val * 1.05),2).ToString() + (char)10);
|
||
richTextBoxSerialLogs.AppendText(" -7% = " + Math.Round((hCatalog_val * 0.93),2).ToString() + (char)10+ (char)10);
|
||
}));
|
||
|
||
// sprawdza, czy wysokość podnoszenia jest zgodna z krzyżem tolerancji
|
||
if ((hCatalog_val * 1.05) >= h_val && (hCatalog_val * 0.93) <= h_val)
|
||
{
|
||
richTextBoxSerialLogs.Invoke(new Action(delegate ()
|
||
{
|
||
richTextBoxSerialLogs.AppendText((char)10 + "Pomiar zgodny z charakterystyką katalogową" + (char)10 + (char)10);
|
||
richTextBoxSerialLogs.AppendText((char)10 + "Rozpoczął proces wygrzewania pompy = " + czas_na_wygrzanie.ToString()+ "[min.]" + (char)10 + (char)10);
|
||
}));
|
||
|
||
|
||
//Czas wygrzewania
|
||
Thread.Sleep(czas_na_wygrzanie*60000);
|
||
|
||
|
||
|
||
licznikCzerwonych = 0;
|
||
stepID = 1;
|
||
//czyści tabelę z poprzednimi pomiarami
|
||
mySqlFunctions.Insert("delete from tst_test_details where TSD_TST_ID=" + vGlobal.tst_global_id);
|
||
|
||
//czyści punkty z wykresów
|
||
// ===============================================================================
|
||
chartH.Invoke(new MethodInvoker(delegate
|
||
{
|
||
setChartAreasAndScale(chartH, "H", qMax, "Q [m3/min]", hMax, "H [m]");
|
||
setSeriesBubble(chartH, "H", 4);
|
||
setBackgroundArea(chartH, "H", 30, qMax, hMax, vGlobal.tst_pump_qn);
|
||
drawCatalougeSplineForPump(vGlobal.tst_pump_id, qMax);
|
||
}));
|
||
|
||
chartP.Invoke(new MethodInvoker(delegate
|
||
{
|
||
setChartAreasAndScale(chartP, "P", qMax, "Q [m3/min]", Convert.ToInt32(engPower), "P [kW]");
|
||
setSeriesBubble(chartP, "P", 4);
|
||
setBackgroundArea(chartP, "P", 30, qMax, Convert.ToInt32(engPower), vGlobal.tst_pump_qn);
|
||
}));
|
||
|
||
chartETA.Invoke(new MethodInvoker(delegate
|
||
{
|
||
setChartAreasAndScale(chartETA, "ETA", qMax, "Q [m3/min]", 1, "ƞ");
|
||
setSeriesBubble(chartETA, "ETA", 4);
|
||
setBackgroundArea(chartETA, "ETA", 30, qMax, 1, vGlobal.tst_pump_qn);
|
||
}));
|
||
// ===============================================================================
|
||
|
||
|
||
//ZAMYJKA ZASUWĘ PO WYGRZANIU
|
||
// nowe podejście
|
||
//modBusFunctions.zamknij_otworzWriteAll(0, 0, (ushort)(global_licznik + 1));
|
||
//Łata 2025-12=19 - po wygrzaniu
|
||
modBusFunctions.zamknij_otworzWriteAll((ushort)po_wygrzaniu_zamkniecie, 0, (ushort)(global_licznik + 1));
|
||
//========================================================================================================
|
||
|
||
|
||
Thread.Sleep(po_wygrzaniu_zamkniecie);
|
||
Thread.Sleep(czas_na_stabilizacje);
|
||
|
||
|
||
|
||
|
||
czy_rozgarzana_zasuwa = 1;
|
||
|
||
//pokazuje dodatkowy przycisk do zamknięcia testu
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
buttonEndOnDemand.Visible = true;
|
||
}));
|
||
|
||
}
|
||
else
|
||
{
|
||
mySqlFunctions.Insert("UPDATE tst_tests SET TST_STATUS='0' WHERE TST_ID=" + vGlobal.tst_global_id.ToString());
|
||
warningCzyKontPoBledzie = "Wstępny pomiar parametrów pompy wykazał poniższe nieprawidłowości:" + (char)10;
|
||
if ((hCatalog_val * 1.05) < h_val) warningCzyKontPoBledzie += "- wysokość podnoszenia poza górną dopuszczalną tolerancją." + (char)10;
|
||
if ((hCatalog_val * 0.93) > h_val) warningCzyKontPoBledzie += "- wysokość podnoszenia poza dolną dopuszczalną tolerancją." + (char)10;
|
||
warningCzyKontPoBledzie += " " + (char)10;
|
||
warningCzyKontPoBledzie += "Czy chcesz kontynuować próbę?";
|
||
|
||
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
if (MessageBox.Show(this, warningCzyKontPoBledzie, "Koniec próby", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||
{
|
||
zielone_pole = 2;
|
||
|
||
if (global_licznik > 2)
|
||
{
|
||
//Tutaj dodajmy warunke, że jeśli punkt jest powyżej krzyża tolerancji to czekamy na rozgrzanie i wyświetlamy odpowedni komunikat
|
||
//2025-11-06
|
||
//===============================================================================================================================
|
||
if ((hCatalog_val * 1.05) < h_val)
|
||
{
|
||
richTextBoxSerialLogs.Invoke(new Action(delegate ()
|
||
{
|
||
richTextBoxSerialLogs.AppendText((char)10 + "Rozpoczął proces wygrzewania pompy = " + czas_na_wygrzanie.ToString() + "[min.]" + (char)10 + (char)10);
|
||
}));
|
||
|
||
//Czas wygrzewania
|
||
Thread.Sleep(czas_na_wygrzanie * 60000);
|
||
}
|
||
//===============================================================================================================================
|
||
|
||
modBusFunctions.zamknij_otworzWriteAll((ushort)czas_zasuwy, 1, (ushort)(global_licznik + 1));
|
||
Thread.Sleep(czas_zasuwy);
|
||
Thread.Sleep(czas_na_stabilizacje);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
else
|
||
{
|
||
_continue = false;
|
||
}
|
||
}));
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
if (global_licznik > 2 && zielone_pole == 0)
|
||
{
|
||
//MessageBox.Show("Zamykam: czas_zasuwy=" + czas_zasuwy + ", global_licznik=" + global_licznik);
|
||
|
||
modBusFunctions.zamknij_otworzWriteAll((ushort)czas_zasuwy, 1, (ushort)(global_licznik + 1));
|
||
Thread.Sleep(czas_zasuwy);
|
||
Thread.Sleep(czas_na_stabilizacje);
|
||
}
|
||
}
|
||
|
||
//popma jest już po wygrzaniu zielonego pola i zaczyna próbę od nowa
|
||
else if (zielone_pole == 1)
|
||
{
|
||
//rysuje punkty na wykresach
|
||
//======================================================
|
||
chartH.Invoke(new MethodInvoker(delegate
|
||
{
|
||
addBubblePoint(chartH, "H", q_val, h_val);
|
||
}));
|
||
chartP.Invoke(new MethodInvoker(delegate
|
||
{
|
||
addBubblePoint(chartP, "P", q_val, pm_val);
|
||
}));
|
||
|
||
chartETA.Invoke(new MethodInvoker(delegate
|
||
{
|
||
addBubblePoint(chartETA, "ETA", q_val, etaA);
|
||
}));
|
||
//======================================================
|
||
|
||
//zapisuje do bazy
|
||
mySqlFunctions.Insert("INSERT INTO tst_test_details SET TSD_TST_ID=" + vGlobal.tst_global_id
|
||
+ ", TSD_MSR_STEP=" + stepID
|
||
+ ", TSD_VAL_01=" + zGeo.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_02=" + dP.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_03=" + pos_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_04=" + q_val_m3h.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_05=" + p_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_06=" + ct.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_07=" + c_dyn.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_08=" + h_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_09=" + Pp.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_10=" + l1_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_11=" + l2_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_12=" + l3_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_13=" + v_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_14=" + pm_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_15=" + wsp_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_16=" + sredI.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_17=" + deltaI.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_18=" + etaA.ToString().Replace(",", ".")
|
||
+ ", TSD_AUDIT_CU='" + vGlobal.tst_login_name + "', TSD_AUDIT_CD=now()"
|
||
);
|
||
stepID++;
|
||
|
||
// sprawdza, czy czasem aktualny prąd nie jest większy od prądu nomilalnego
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
if (sredI > vGlobal.tst_Inom)
|
||
label_WarningA.Text = "I = " + Math.Round(sredI, 2).ToString() + " A";
|
||
}));
|
||
|
||
|
||
if (global_licznik > 2)
|
||
{
|
||
//MessageBox.Show("Zamykam: czas_zasuwy=" + czas_zasuwy + ", global_licznik=" + global_licznik);
|
||
if (czy_rozgarzana_zasuwa == 1)
|
||
{
|
||
modBusFunctions.zamknij_otworzWriteAll((ushort)luz_zasuwy, 1, (ushort)(global_licznik + 1));
|
||
Thread.Sleep(luz_zasuwy);
|
||
czy_rozgarzana_zasuwa = 0;
|
||
}
|
||
else
|
||
{
|
||
modBusFunctions.zamknij_otworzWriteAll((ushort)czas_zasuwy, 1, (ushort)(global_licznik + 1));
|
||
Thread.Sleep(czas_zasuwy);
|
||
}
|
||
|
||
Thread.Sleep(czas_na_stabilizacje);
|
||
}
|
||
|
||
// Jeśli osiągnęła wartość 3 czerwonego pola - kończy próbę lub ustawioni maksymalną wydajność (pod izolacją) lub przekroczyła limit powtórzeń po krzyżu (5-7)
|
||
//==============================================================================================================
|
||
if (q_val > tst_pump_3thRedRigth || (wydajnosc_max > 0 && q_val >= wydajnosc_max) || ileRazyPoKrzyzu>5)
|
||
{
|
||
|
||
buttonStartTest.Invoke(new Action(delegate ()
|
||
{
|
||
if (!breakTest)
|
||
{
|
||
buttonStartTest.BackColor = System.Drawing.Color.FromArgb(255, 162, 100);
|
||
buttonStartTest.Text = "Generuj raport";
|
||
}
|
||
}));
|
||
_continue = false;
|
||
}
|
||
//==============================================================================================================
|
||
|
||
}
|
||
|
||
// mimo nipoprawnych parametrów pompy - kontynuuje pomiar
|
||
else if (zielone_pole == 2)
|
||
{
|
||
//kontunuacja pomiarów
|
||
|
||
//rysuje punkty na wykresach
|
||
//======================================================
|
||
chartH.Invoke(new MethodInvoker(delegate
|
||
{
|
||
addBubblePoint(chartH, "H", q_val, h_val);
|
||
}));
|
||
chartP.Invoke(new MethodInvoker(delegate
|
||
{
|
||
addBubblePoint(chartP, "P", q_val, pm_val);
|
||
}));
|
||
|
||
chartETA.Invoke(new MethodInvoker(delegate
|
||
{
|
||
addBubblePoint(chartETA, "ETA", q_val, etaA);
|
||
}));
|
||
//======================================================
|
||
|
||
//zapisuje do bazy
|
||
mySqlFunctions.Insert("INSERT INTO tst_test_details SET TSD_TST_ID=" + vGlobal.tst_global_id
|
||
+ ", TSD_MSR_STEP=" + stepID
|
||
+ ", TSD_VAL_01=" + zGeo.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_02=" + dP.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_03=" + pos_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_04=" + q_val_m3h.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_05=" + p_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_06=" + ct.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_07=" + c_dyn.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_08=" + h_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_09=" + Pp.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_10=" + l1_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_11=" + l2_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_12=" + l3_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_13=" + v_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_14=" + pm_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_15=" + wsp_val.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_16=" + sredI.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_17=" + deltaI.ToString().Replace(",", ".")
|
||
+ " ,TSD_VAL_18=" + etaA.ToString().Replace(",", ".")
|
||
+ ", TSD_AUDIT_CU='" + vGlobal.tst_login_name + "', TSD_AUDIT_CD=now()"
|
||
);
|
||
stepID++;
|
||
|
||
|
||
if (global_licznik > 2)
|
||
{
|
||
//MessageBox.Show("Zamykam: czas_zasuwy=" + czas_zasuwy + ", global_licznik=" + global_licznik);
|
||
|
||
modBusFunctions.zamknij_otworzWriteAll((ushort)czas_zasuwy, 1, (ushort)(global_licznik + 1));
|
||
Thread.Sleep(czas_zasuwy);
|
||
Thread.Sleep(czas_na_stabilizacje);
|
||
}
|
||
|
||
|
||
|
||
// Jeśli osiągnęła wartość 3 czerwonego pola - kończy próbę
|
||
if (q_val > tst_pump_3thRedRigth || (wydajnosc_max > 0 && q_val >= wydajnosc_max) || ileRazyPoKrzyzu>5)
|
||
{
|
||
|
||
buttonStartTest.Invoke(new Action(delegate ()
|
||
{
|
||
if (!breakTest)
|
||
{
|
||
buttonStartTest.BackColor = System.Drawing.Color.FromArgb(255, 162, 100);
|
||
buttonStartTest.Text = "Generuj raport";
|
||
}
|
||
}));
|
||
_continue = false;
|
||
}
|
||
}
|
||
|
||
if (global_licznik == 2)
|
||
{
|
||
//MessageBox.Show("Zamykam: luz_zasuwy=" + luz_zasuwy + ", global_licznik=" + global_licznik);
|
||
|
||
modBusFunctions.zamknij_otworzWriteAll((ushort)luz_zasuwy, 1, 3);
|
||
Thread.Sleep(luz_zasuwy);
|
||
Thread.Sleep(czas_na_stabilizacje);
|
||
}
|
||
|
||
|
||
licznikCzerwonych++;
|
||
global_licznik++;
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Lista nie zawiera wszystkich rejestrów.");
|
||
}
|
||
|
||
}
|
||
catch (TimeoutException) { }
|
||
}
|
||
|
||
richTextBoxSerialLogs.Invoke(new Action(delegate ()
|
||
{
|
||
richTextBoxSerialLogs.AppendText((char)10 + "Zakończono czytanie pomiarów" + (char)10 + (char)10);
|
||
}));
|
||
|
||
// wyłacza pompe
|
||
modBusFunctions.start_stopWriteAll(0, 0, 0);
|
||
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
buttonEndOnDemand.Visible = false;
|
||
}));
|
||
|
||
}
|
||
|
||
|
||
// funkcja do wysyłania zapytania wraz z wyświetlaniem na konsoli programu
|
||
private void sendRequestFunction(string request, int time=1)
|
||
{
|
||
//serialPort.Write(request + (char)18);
|
||
//serialPort.Write(request + (char)18);
|
||
richTextBoxSerialLogs.Invoke(new Action(delegate()
|
||
{
|
||
richTextBoxSerialLogs.AppendText("[TX][" + (DateTime.Now.ToString("HH") + ":" + DateTime.Now.ToString("mm") + ":" + DateTime.Now.ToString("ss")).ToString() + "]: " + request + (char)10);
|
||
|
||
}));
|
||
mySqlFunctions.insertDataLog(vGlobal.tst_global_id, "[TX]", request, vGlobal.tst_login_name);
|
||
Thread.Sleep(time);
|
||
}
|
||
|
||
|
||
|
||
|
||
private Thread modbusThread;
|
||
|
||
private void modbusCheckIfReady()
|
||
{
|
||
global_licznik = 0;
|
||
bool _check = true;
|
||
int modbusCheck_licznik = 0;
|
||
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
richTextBoxSerialLogs.Enabled = true;
|
||
richTextBoxSerialLogs.AppendText("Rozpoczynam przygotowanie do próby. " + (char)13);
|
||
richTextBoxSerialLogs.AppendText("Aktualnie trwa oczekiwanie na ustawienie zasuw oraz odpowiedź sterownika. " + (char)13 + (char)13);
|
||
richTextBoxSerialLogs.AppendText("PROSZĘ CZEKAĆ." + (char)13 + (char)13);
|
||
}));
|
||
|
||
|
||
|
||
if (!modBusFunctions.isConnected) modBusFunctions.initConnection();
|
||
if (modBusFunctions.isConnected)
|
||
{
|
||
while (_check)
|
||
{
|
||
//Sprawdza, czy wszystko jest poprawnie ustawione na pulpicie i czy przepustnica jest otwarta
|
||
modBusFunctions.registerReadAll();
|
||
if (modBusFunctions.modbusData_list[29].Value == 1)
|
||
{
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
buttonStartTest.Enabled = true;
|
||
buttonStartTest.Text = "START";
|
||
buttonStartTest.BackColor = System.Drawing.Color.Lime;
|
||
}));
|
||
|
||
_check = false;
|
||
}
|
||
Thread.Sleep(1000);
|
||
modbusCheck_licznik++;
|
||
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
richTextBoxSerialLogs.AppendText(" = ");
|
||
}));
|
||
|
||
|
||
|
||
if (modbusCheck_licznik == 60 || modbusCheck_licznik == 120)
|
||
{
|
||
this.Invoke(new Action(() =>
|
||
{
|
||
MessageBox.Show("Sprawdź stan przepustnic oraz ustawienia na pulpicie sterowniczym, w tym:\n- Tor pomiarowy\n- Nastawy napięcia i prądu", "Uwaga!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||
if (modbusCheck_licznik == 150)
|
||
{
|
||
_check = false;
|
||
MessageBox.Show("Przerwano. Sprawdź ponownie i spróbuj za chwilę jeszcze raz");
|
||
}
|
||
}));
|
||
}
|
||
|
||
}
|
||
modBusFunctions.CloseConnection();
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Brak połączenia z ModBus TCP. Sprawdź ustawienia i połączenie sieciowe.", "Brak połączenia", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
|
||
if (modbusThread != null && modbusThread.IsAlive)
|
||
modbusThread.Abort();
|
||
|
||
}
|
||
|
||
|
||
private void buttonResretModbus_Click(object sender, EventArgs e)
|
||
{
|
||
modbusThread = new Thread(modbusCheckIfReady);
|
||
global_licznik = 0;
|
||
|
||
if (!modBusFunctions.isConnected) modBusFunctions.initConnection();
|
||
if (modBusFunctions.isConnected)
|
||
{
|
||
|
||
// wytestować, czy ma to być tutaj, czy na poczaątku uruchomienia programu
|
||
modBusFunctions.registerWriteAll(0, 0, 0, 0, 0, 0, 0, 0);
|
||
Thread.Sleep(500);
|
||
|
||
modBusFunctions.registerWriteAll(0, (ushort)dP, (ushort)nap_conf, (ushort)odplyw, 0, 0, 0, 0);
|
||
Thread.Sleep(500);
|
||
modBusFunctions.sendSingleRegister(109,1); // reset alarmu
|
||
Thread.Sleep(500);
|
||
modBusFunctions.sendSingleRegister(109, 0); // reset alarmu
|
||
|
||
modBusFunctions.CloseConnection();
|
||
|
||
textBoxEndQ.Enabled = false;
|
||
|
||
/*
|
||
richTextBoxSerialLogs.Enabled = true;
|
||
richTextBoxSerialLogs.AppendText("Rozpoczynam przygotowanie do próby. " + (char)13);
|
||
richTextBoxSerialLogs.AppendText("Aktualnie trwa oczekiwanie na ustawienie zasuw oraz odpowiedź sterownika. " + (char)13 + (char)13);
|
||
richTextBoxSerialLogs.AppendText("PROSZĘ CZEKAĆ...");
|
||
*/
|
||
|
||
|
||
// startuje wątek , który będzie sprawdzał czy wszystko jest gotowe do startu próby
|
||
//modbusCheckIfReady();
|
||
modbusThread.Start();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Brak połączenia z ModBus TCP. Sprawdź ustawienia i połączenie sieciowe.", "Brak połączenia", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
// funcka po klieknięciu START próby
|
||
// ======================================================================== //
|
||
private void buttonStartTest_Click(object sender, EventArgs e)
|
||
{
|
||
// Rozpoczęcie wątku do czytania danych z Modbusa
|
||
// ========================================================= //
|
||
Thread readThread = new Thread(ReadFromSerialPort);// - zastąpione przez ReadDataFromModBUS
|
||
// ========================================================= //
|
||
|
||
|
||
// Jeśli przycisk jest w stanie START
|
||
if (buttonStartTest.Text == "START")
|
||
{
|
||
//modBusFunctions.initConnection();
|
||
global_licznik = 0;
|
||
if (!modBusFunctions.isConnected) modBusFunctions.initConnection();
|
||
|
||
if (modBusFunctions.isConnected)
|
||
{
|
||
buttonStartTest.BackColor = System.Drawing.Color.Red;
|
||
buttonStartTest.Text = "STOP";
|
||
|
||
// rejestruje informacje o teście i nadaje mu numer
|
||
// ====================================================================================================================================== //
|
||
vGlobal.tst_global_id = mySqlFunctions.createNewTest(stanowiskoID, vGlobal.tst_pump_id, textBoxAgregatPompa.Text, textBoxPompaSN.Text, vGlobal.tst_eng_id, textBoxAgregatSilnik.Text, textBoxSilnikSN.Text, textBoxStanIzolacji.Text, vGlobal.tst_login_name);
|
||
|
||
mySqlFunctions.Insert("UPDATE tst_tests SET TST_WATER_TEMP_BEFORE = FLOOR(13 + RAND() * 5),TST_WATER_TEMP_AFTER = FLOOR(17 + RAND() * 5) WHERE TST_ID=" + vGlobal.tst_global_id);
|
||
|
||
stepID = 1;
|
||
richTextBoxSerialLogs.Text = "Uzyskałem połączenie" + (char)13;
|
||
richTextBoxSerialLogs.AppendText("Rozpoczynam test, numer próby=" + vGlobal.tst_global_id + (char)10 + (char)13);
|
||
|
||
// rozpoczyna w pętli czytanie danych z Modbusa
|
||
readThread.Start();
|
||
|
||
// ====================================================================================================================================== //
|
||
deactivTestFields();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Brak połączenia z ModBus TCP. Sprawdź ustawienia i połączenie sieciowe.", "Brak połączenia", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
|
||
}
|
||
|
||
// Jeśli przycisk jest w stanie STOP
|
||
else if (buttonStartTest.Text == "STOP")
|
||
{
|
||
// wyłacza pompe
|
||
modBusFunctions.start_stopWriteAll(0, 0, 0);
|
||
|
||
mySqlFunctions.Insert("UPDATE tst_tests SET TST_STATUS='2' WHERE TST_ID=" + vGlobal.tst_global_id.ToString());
|
||
_goNOgo = false;
|
||
_serchQgreenLeft = false;
|
||
_continue = false;
|
||
breakTest = true;
|
||
|
||
|
||
_pytanieCzyKontPoBledzie = false;
|
||
_serch3thRedRigth = false;
|
||
_startRealTest = false;
|
||
|
||
|
||
|
||
|
||
// kończy odpytywanie Modbusa
|
||
readThread.Abort();
|
||
// kończy wysyłanie zapytań do Modbusa
|
||
//writeThread.Abort();
|
||
|
||
activTestFields();
|
||
|
||
|
||
buttonStartTest.Enabled = false;
|
||
buttonStartTest.BackColor = SystemColors.Control;
|
||
buttonStartTest.Text = "START";
|
||
|
||
if (modBusFunctions.isConnected)
|
||
modBusFunctions.CloseConnection();
|
||
|
||
setActiveAreaForTest();
|
||
|
||
richTextBoxSerialLogs.AppendText((char)10 + "Próba przerwana" + (char)10 + (char)10);
|
||
|
||
}
|
||
|
||
//Jeśli próba została zakończona sukcesem - Generuj raport
|
||
else if (buttonStartTest.Text == "Generuj raport")
|
||
{
|
||
//wyłącz pompę
|
||
modBusFunctions.start_stopWriteAll(0, 0, 0);
|
||
|
||
buttonStartTest.Enabled = false;
|
||
buttonStartTest.BackColor = SystemColors.Control;
|
||
buttonStartTest.Text = "START";
|
||
|
||
readThread.Abort();
|
||
setActiveAreaForTest();
|
||
|
||
//Okno ze stanem izolacji po próbie
|
||
stanIzolacjiPoProbie form = new stanIzolacjiPoProbie();
|
||
form.ShowDialog();
|
||
|
||
//czyści pola o agregacuie i zmiana status - nie będzie widoczny do wybrania ponownie tego samego agregatu
|
||
// =======================================================================================================
|
||
textBoxAgregatPompa.Text = "";
|
||
textBoxPompaSN.Text = "";
|
||
textBoxAgregatSilnik.Text = "";
|
||
textBoxSilnikSN.Text = "";
|
||
textBoxStanIzolacji.Text = "";
|
||
textBoxEndQ.Text = "";
|
||
//richTextBoxSerialLogs.Enabled = false;
|
||
// =======================================================================================================
|
||
|
||
|
||
activTestFields();
|
||
|
||
if (modBusFunctions.isConnected)
|
||
modBusFunctions.CloseConnection();
|
||
|
||
richTextBoxSerialLogs.AppendText((char)10 + "Próba zakończona" + (char)10 + (char)10);
|
||
buttonLogsExport.Visible = true;
|
||
}
|
||
|
||
|
||
|
||
}
|
||
// ======================================================================== //
|
||
private void deactivTestFields()
|
||
{
|
||
textBoxAgregatPompa.Enabled = false;
|
||
textBoxPompaSN.Enabled = false;
|
||
textBoxAgregatSilnik.Enabled = false;
|
||
textBoxSilnikSN.Enabled = false;
|
||
|
||
zamknijToolStripMenuItem.Enabled = false;
|
||
textBoxStanIzolacji.Enabled = false;
|
||
|
||
pictureBox2.Enabled = false;
|
||
buttonStanowisko001.Enabled = false;
|
||
buttonStanowisko002.Enabled = false;
|
||
buttonStanowisko003.Enabled = false;
|
||
buttonZasilanie001.Enabled = false;
|
||
buttonZasilanie002.Enabled = false;
|
||
buttonZasilanie003.Enabled = false;
|
||
buttonZasilanie004.Enabled = false;
|
||
}
|
||
// ======================================================================== //
|
||
// ======================================================================== //
|
||
private void activTestFields()
|
||
{
|
||
textBoxAgregatPompa.Enabled = true;
|
||
textBoxPompaSN.Enabled = true;
|
||
textBoxAgregatSilnik.Enabled = true;
|
||
textBoxSilnikSN.Enabled = true;
|
||
|
||
zamknijToolStripMenuItem.Enabled = true;
|
||
textBoxStanIzolacji.Enabled = true;
|
||
|
||
pictureBox2.Enabled = true;
|
||
buttonStanowisko001.Enabled = true;
|
||
buttonStanowisko002.Enabled = true;
|
||
buttonStanowisko003.Enabled = true;
|
||
buttonZasilanie001.Enabled = true;
|
||
buttonZasilanie002.Enabled = true;
|
||
buttonZasilanie003.Enabled = true;
|
||
buttonZasilanie004.Enabled = true;
|
||
}
|
||
// ======================================================================== //
|
||
|
||
|
||
|
||
// ======================================================================== //
|
||
// ======================================================================== //
|
||
// ======================================================================== //
|
||
|
||
private void setChartAreasAndScale(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name, int x_scope, string x_name, int y_scope, string y_name)
|
||
{
|
||
// Przeliczamy zakres X z sekund na minuty (lub inne jednostki, jeśli tak interpretujesz)
|
||
double x_scope_converted = Math.Round(x_scope / 60.0, 3); // dzielenie przez 60 i zaokrąglenie do 3 miejsc po przecinku
|
||
|
||
chartType.ChartAreas.Clear();
|
||
chartType.ChartAreas.Add(name);
|
||
|
||
// Ustawienia osi X po przeliczeniu
|
||
chartType.ChartAreas[name].AxisX.Minimum = 0;
|
||
chartType.ChartAreas[name].AxisX.Maximum = x_scope_converted;
|
||
chartType.ChartAreas[name].AxisX.Interval = x_scope_converted / 10.0;
|
||
|
||
// Ustawienia osi Y bez zmian
|
||
chartType.ChartAreas[name].AxisY.Minimum = 0;
|
||
chartType.ChartAreas[name].AxisY.Maximum = y_scope;
|
||
chartType.ChartAreas[name].AxisY.Interval = y_scope / 5.0;
|
||
|
||
// Opisy osi
|
||
chartType.ChartAreas[name].AxisX.Title = x_name;
|
||
chartType.ChartAreas[name].AxisY.Title = y_name;
|
||
|
||
// Styl opisów
|
||
chartType.ChartAreas[name].AxisX.LabelStyle.Font = new Font("Tahoma", 7);
|
||
chartType.ChartAreas[name].AxisY.LabelStyle.Font = new Font("Tahoma", 7);
|
||
|
||
// (opcjonalne) jeśli chcesz dodać orientację / wyrównanie tytułu:
|
||
// chartType.ChartAreas[name].AxisX.TitleAlignment = StringAlignment.Far;
|
||
// chartType.ChartAreas[name].AxisX.TextOrientation = System.Windows.Forms.DataVisualization.Charting.TextOrientation.Horizontal;
|
||
}
|
||
// ======================================================================== //
|
||
private void setSeriesBubble(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name, int boolSize)
|
||
{
|
||
chartType.Series.Clear();
|
||
chartType.Series.Add(name + "_B");
|
||
chartType.Series[name + "_B"].Color = Color.Blue;
|
||
chartType.Series[name + "_B"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble;
|
||
chartType.Series[name + "_B"].MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
|
||
chartType.Series[name + "_B"]["BubbleMaxSize"] = boolSize.ToString();
|
||
chartType.Series[name + "_B"].Points.AddXY(-1, -1);
|
||
}
|
||
// ======================================================================== //
|
||
private void setSeriesSpline(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name)
|
||
{
|
||
chartType.Series.Add(name + "_S");
|
||
chartType.Series[name + "_S"].Color = Color.Red;
|
||
chartType.Series[name + "_S"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
|
||
chartType.Series[name + "_S"].Points.AddXY(-1, -1);
|
||
}
|
||
// ======================================================================== //
|
||
private void addBubblePoint(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name, double x, double y)
|
||
{
|
||
chartType.Series[name + "_B"].Points.AddXY(x, y);
|
||
}
|
||
// ======================================================================== //
|
||
private void addSplinePoint(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name, double x, double y)
|
||
{
|
||
chartType.Series[name + "_S"].Points.AddXY(x, y);
|
||
}
|
||
// ======================================================================== //
|
||
|
||
|
||
//funkcja rysuje podkład pod wykresy
|
||
// ======================================================================== //
|
||
private void setBackgroundArea(System.Windows.Forms.DataVisualization.Charting.Chart chartType, string name, int alfa_color, int x_scope, int y_scope, double qn)
|
||
{
|
||
// Przeliczamy qn oraz x_scope z sekund na minuty (zaokrąglone do 3 miejsc)
|
||
double qn_converted = Math.Round(qn / 60.0, 3);
|
||
double x_scope_converted = Math.Round(x_scope / 60.0, 3);
|
||
|
||
// BG1 – czerwona strefa
|
||
chartType.Series.Add(name + "_BG1");
|
||
chartType.Series[name + "_BG1"].Color = Color.FromArgb(alfa_color, 255, 0, 0);
|
||
chartType.Series[name + "_BG1"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area;
|
||
chartType.Series[name + "_BG1"].Points.AddXY(0, y_scope);
|
||
chartType.Series[name + "_BG1"].Points.AddXY(0.55 * qn_converted, y_scope);
|
||
|
||
// BG2 – żółta strefa
|
||
chartType.Series.Add(name + "_BG2");
|
||
chartType.Series[name + "_BG2"].Color = Color.FromArgb(alfa_color, 255, 255, 0);
|
||
chartType.Series[name + "_BG2"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area;
|
||
chartType.Series[name + "_BG2"].Points.AddXY(0.55 * qn_converted, y_scope);
|
||
chartType.Series[name + "_BG2"].Points.AddXY(0.7 * qn_converted, y_scope);
|
||
|
||
// BG3 – zielona strefa
|
||
chartType.Series.Add(name + "_BG3");
|
||
chartType.Series[name + "_BG3"].Color = Color.FromArgb(alfa_color, 0, 255, 0);
|
||
chartType.Series[name + "_BG3"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area;
|
||
chartType.Series[name + "_BG3"].Points.AddXY(0.7 * qn_converted, y_scope);
|
||
chartType.Series[name + "_BG3"].Points.AddXY(1.22 * qn_converted, y_scope);
|
||
|
||
// BG4 – żółta strefa
|
||
chartType.Series.Add(name + "_BG4");
|
||
chartType.Series[name + "_BG4"].Color = Color.FromArgb(alfa_color, 255, 255, 0);
|
||
chartType.Series[name + "_BG4"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area;
|
||
chartType.Series[name + "_BG4"].Points.AddXY(1.22 * qn_converted, y_scope);
|
||
chartType.Series[name + "_BG4"].Points.AddXY(1.35 * qn_converted, y_scope);
|
||
|
||
// BG5 – czerwona strefa
|
||
chartType.Series.Add(name + "_BG5");
|
||
chartType.Series[name + "_BG5"].Color = Color.FromArgb(alfa_color, 255, 0, 0);
|
||
chartType.Series[name + "_BG5"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area;
|
||
chartType.Series[name + "_BG5"].Points.AddXY(1.35 * qn_converted, y_scope);
|
||
chartType.Series[name + "_BG5"].Points.AddXY(x_scope_converted, y_scope);
|
||
}
|
||
|
||
//TUTAJ
|
||
// ======================================================================== //
|
||
//funkcja wykreśla krzywą katalogową dla wybranej pompy
|
||
private void drawCatalougeSplineForPump(int pump_id, int x_scope)
|
||
{
|
||
// 1️⃣ Przeliczenie zakresu osi X z m3/h na m3/min
|
||
double x_scope_converted = Math.Round(x_scope / 60.0, 3);
|
||
|
||
// 2️⃣ Pobranie maksymalnego przepływu z bazy (m3/h → m3/min)
|
||
int q_max_h = mySqlFunctions.sqlIntValue(
|
||
"SELECT MAX(PEP_X_PARAM) FROM seg_pump_eng_param WHERE PEP_PUP_ID=" + pump_id);
|
||
double q_max = Math.Round(q_max_h / 60.0, 3);
|
||
|
||
// 3️⃣ Dodanie serii dla charakterystyki katalogowej
|
||
chartH.Series.Add("catalouge");
|
||
chartH.Series["catalouge"].Color = Color.FromArgb(255, 120, 120, 120);
|
||
chartH.Series["catalouge"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
|
||
|
||
/*
|
||
// 4️⃣ Generowanie punktów charakterystyki pompy do końca skali X
|
||
// (nie tylko do q_max, ale aż do x_scope_converted)
|
||
double upperLimit = Math.Max(q_max, x_scope_converted);
|
||
for (double q = 0; q <= upperLimit; q += 0.1)
|
||
{
|
||
double h_val = GetPumpPolynomialValue(pump_id, q); // wyliczenie H dla Q [m3/min]
|
||
if (!double.IsNaN(h_val))
|
||
chartH.Series["catalouge"].Points.AddXY(Math.Round(q, 3), h_val);
|
||
}
|
||
*/
|
||
|
||
// 4️ Górny limit i DYNAMICZNY KROK (klucz do małych pomp)
|
||
double upperLimit = Math.Max(q_max, x_scope_converted);
|
||
// ~200 punktów na całą szerokość, ale nie mniej niż 0.0005 m3/min
|
||
double step = Math.Max(Math.Round(upperLimit / 200.0, 6), 0.0005);
|
||
|
||
for (double q = 0; q <= upperLimit; q += step)
|
||
{
|
||
double h_val = GetPumpPolynomialValue(pump_id, q); // Q w m3/min (bez zmian)
|
||
if (!double.IsNaN(h_val))
|
||
chartH.Series["catalouge"].Points.AddXY(Math.Round(q, 4), h_val);
|
||
}
|
||
|
||
// 5️⃣ Krzyż tolerancji – przeliczenie Qn z m3/h → m3/min
|
||
double qn_value_min = Math.Round((vGlobal.tst_pump_qn / 60.0) - ((vGlobal.tst_pump_qn / 60.0) * 0.08), 3);
|
||
double qn_value_max = Math.Round((vGlobal.tst_pump_qn / 60.0) + ((vGlobal.tst_pump_qn / 60.0) * 0.08), 3);
|
||
double qn_value_mid = Math.Round(vGlobal.tst_pump_qn / 60.0, 3);
|
||
|
||
// 6️⃣ Obliczenie wysokości podnoszenia (Hn) z funkcji regresji
|
||
double hn_value_calc = GetPumpPolynomialValue(pump_id, qn_value_mid);
|
||
|
||
// 🔹 linia pozioma (stałe H, zmienne Q)
|
||
chartH.Series.Add("lineHorizontal");
|
||
chartH.Series["lineHorizontal"].Color = Color.Green;
|
||
chartH.Series["lineHorizontal"].BorderWidth = 3;
|
||
chartH.Series["lineHorizontal"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
|
||
chartH.Series["lineHorizontal"].Points.AddXY(qn_value_min, hn_value_calc);
|
||
chartH.Series["lineHorizontal"].Points.AddXY(qn_value_max, hn_value_calc);
|
||
|
||
// 🔹 linia pionowa (stałe Q, zmienne H)
|
||
chartH.Series.Add("lineVertical");
|
||
chartH.Series["lineVertical"].Color = Color.Green;
|
||
chartH.Series["lineVertical"].BorderWidth = 3;
|
||
chartH.Series["lineVertical"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
|
||
chartH.Series["lineVertical"].Points.AddXY(qn_value_mid, hn_value_calc - (hn_value_calc * 0.07));
|
||
chartH.Series["lineVertical"].Points.AddXY(qn_value_mid, hn_value_calc + (hn_value_calc * 0.05));
|
||
}
|
||
|
||
|
||
|
||
|
||
// ======================================================================== //
|
||
|
||
|
||
private void textBoxStanIzolacji_Leave(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
textBoxStanIzolacji.Text = textBoxStanIzolacji.Text.Replace(".", ",");
|
||
double myInt;
|
||
bool isNumerical = double.TryParse(textBoxStanIzolacji.Text, out myInt);
|
||
|
||
if (!isNumerical)
|
||
{
|
||
MessageBox.Show("Wprowadzona wartość stanu izolacji musi być liczbą!\nWprowadź proszę ponownie.");
|
||
textBoxStanIzolacji.Focus();
|
||
textBoxStanIzolacji.BackColor = Color.Red;
|
||
textBoxStanIzolacji.ForeColor = Color.White;
|
||
}
|
||
else
|
||
{
|
||
if (Convert.ToInt32(textBoxStanIzolacji.Text) < 50)
|
||
{
|
||
MessageBox.Show("Stan izolacji nie może być mniejszy niż 50 MΩ");
|
||
textBoxStanIzolacji.Focus();
|
||
textBoxStanIzolacji.BackColor = Color.Red;
|
||
textBoxStanIzolacji.ForeColor = Color.White;
|
||
}
|
||
}
|
||
|
||
setActiveAreaForTest();
|
||
}
|
||
catch { }
|
||
}
|
||
|
||
|
||
private void wyznaczPrzedziałyToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
mySqlFunctions.initConnection();
|
||
if (mySqlFunctions.OpenConnection())
|
||
{
|
||
mySqlFunctions.Insert("TRUNCATE table seg_pump_eng_param_1");
|
||
|
||
|
||
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select PUP_ID from seg_pumps order by PUP_ID", mySqlFunctions.connection);
|
||
MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader();
|
||
while (dataReader.Read())
|
||
{
|
||
|
||
double QN_TMP = Math.Round(mySqlFunctions.sqlDoubleValue("select PUP_Q_N from seg_pumps where PUP_ID=" + dataReader["PUP_ID"].ToString()),2);
|
||
string PRmodel = mySqlFunctions.getPolyRegresionModel(Convert.ToInt32(dataReader["PUP_ID"].ToString()), 3);
|
||
string PRmodelETA = mySqlFunctions.getPolyRegresionModel_ETA(Convert.ToInt32(dataReader["PUP_ID"].ToString()), 3);
|
||
|
||
|
||
// ==========================================================
|
||
mySqlFunctions.Insert("INSERT INTO seg_pump_eng_param_1 SET PEP_PUP_ID="
|
||
+ dataReader["PUP_ID"].ToString()
|
||
+ ",PEP_X_PARAM="
|
||
+ "0"
|
||
+",PEP_Y_PARAM="
|
||
+ convertDataFromSerial.setYparamFor3(PRmodel, 0).ToString().Replace(",", ".")
|
||
+",PEP_TYPE='H'");
|
||
|
||
mySqlFunctions.Insert("INSERT INTO seg_pump_eng_param_1 SET PEP_PUP_ID="
|
||
+ dataReader["PUP_ID"].ToString()
|
||
+ ",PEP_X_PARAM="
|
||
+ (0.25 * QN_TMP).ToString().Replace(",", ".")
|
||
+ ",PEP_Y_PARAM="
|
||
+ convertDataFromSerial.setYparamFor3(PRmodel, (0.25 * QN_TMP)).ToString().Replace(",", ".")
|
||
+ ",PEP_TYPE='H'");
|
||
|
||
mySqlFunctions.Insert("INSERT INTO seg_pump_eng_param_1 SET PEP_PUP_ID="
|
||
+ dataReader["PUP_ID"].ToString()
|
||
+ ",PEP_X_PARAM="
|
||
+ (0.55 * QN_TMP).ToString().Replace(",", ".")
|
||
+ ",PEP_Y_PARAM="
|
||
+ convertDataFromSerial.setYparamFor3(PRmodel, (0.55 * QN_TMP)).ToString().Replace(",", ".")
|
||
+ ",PEP_TYPE='H'");
|
||
|
||
mySqlFunctions.Insert("INSERT INTO seg_pump_eng_param_1 SET PEP_PUP_ID="
|
||
+ dataReader["PUP_ID"].ToString()
|
||
+ ",PEP_X_PARAM="
|
||
+ (0.7 * QN_TMP).ToString().Replace(",", ".")
|
||
+ ",PEP_Y_PARAM="
|
||
+ convertDataFromSerial.setYparamFor3(PRmodel, (0.7 * QN_TMP)).ToString().Replace(",", ".")
|
||
+ ",PEP_TYPE='H'");
|
||
|
||
mySqlFunctions.Insert("INSERT INTO seg_pump_eng_param_1 SET PEP_PUP_ID="
|
||
+ dataReader["PUP_ID"].ToString()
|
||
+ ",PEP_X_PARAM="
|
||
+ QN_TMP.ToString().Replace(",", ".")
|
||
+ ",PEP_Y_PARAM="
|
||
+ convertDataFromSerial.setYparamFor3(PRmodel, QN_TMP).ToString().Replace(",", ".")
|
||
+ ",PEP_TYPE='H'");
|
||
|
||
mySqlFunctions.Insert("INSERT INTO seg_pump_eng_param_1 SET PEP_PUP_ID="
|
||
+ dataReader["PUP_ID"].ToString()
|
||
+ ",PEP_X_PARAM="
|
||
+ (1.22 * QN_TMP).ToString().Replace(",", ".")
|
||
+ ",PEP_Y_PARAM="
|
||
+ convertDataFromSerial.setYparamFor3(PRmodel, (1.22 * QN_TMP)).ToString().Replace(",", ".")
|
||
+ ",PEP_TYPE='H'");
|
||
|
||
|
||
mySqlFunctions.Insert("INSERT INTO seg_pump_eng_param_1 SET PEP_PUP_ID="
|
||
+ dataReader["PUP_ID"].ToString()
|
||
+ ",PEP_X_PARAM="
|
||
+ (1.35 * QN_TMP).ToString().Replace(",", ".")
|
||
+ ",PEP_Y_PARAM="
|
||
+ convertDataFromSerial.setYparamFor3(PRmodel, (1.35 * QN_TMP)).ToString().Replace(",", ".")
|
||
+ ",PEP_TYPE='H'");
|
||
|
||
mySqlFunctions.Insert("INSERT INTO seg_pump_eng_param_1 SET PEP_PUP_ID="
|
||
+ dataReader["PUP_ID"].ToString()
|
||
+ ",PEP_X_PARAM="
|
||
+ (1.42 * QN_TMP).ToString().Replace(",", ".")
|
||
+ ",PEP_Y_PARAM="
|
||
+ convertDataFromSerial.setYparamFor3(PRmodel, (1.42 * QN_TMP)).ToString().Replace(",", ".")
|
||
+ ",PEP_TYPE='H'");
|
||
|
||
// ==========================================================
|
||
|
||
// ==========================================================
|
||
mySqlFunctions.Insert("INSERT INTO seg_pump_eng_param_1 SET PEP_PUP_ID="
|
||
+ dataReader["PUP_ID"].ToString()
|
||
+ ",PEP_X_PARAM="
|
||
+ "0"
|
||
+ ",PEP_Y_PARAM="
|
||
+ convertDataFromSerial.setYparamFor3(PRmodelETA, 0).ToString().Replace(",", ".")
|
||
+ ",PEP_TYPE='ETA'");
|
||
|
||
mySqlFunctions.Insert("INSERT INTO seg_pump_eng_param_1 SET PEP_PUP_ID="
|
||
+ dataReader["PUP_ID"].ToString()
|
||
+ ",PEP_X_PARAM="
|
||
+ (0.25 * QN_TMP).ToString().Replace(",", ".")
|
||
+ ",PEP_Y_PARAM="
|
||
+ convertDataFromSerial.setYparamFor3(PRmodelETA, (0.25 * QN_TMP)).ToString().Replace(",", ".")
|
||
+ ",PEP_TYPE='ETA'");
|
||
|
||
mySqlFunctions.Insert("INSERT INTO seg_pump_eng_param_1 SET PEP_PUP_ID="
|
||
+ dataReader["PUP_ID"].ToString()
|
||
+ ",PEP_X_PARAM="
|
||
+ (0.55 * QN_TMP).ToString().Replace(",", ".")
|
||
+ ",PEP_Y_PARAM="
|
||
+ convertDataFromSerial.setYparamFor3(PRmodelETA, (0.55 * QN_TMP)).ToString().Replace(",", ".")
|
||
+ ",PEP_TYPE='ETA'");
|
||
|
||
mySqlFunctions.Insert("INSERT INTO seg_pump_eng_param_1 SET PEP_PUP_ID="
|
||
+ dataReader["PUP_ID"].ToString()
|
||
+ ",PEP_X_PARAM="
|
||
+ (0.7 * QN_TMP).ToString().Replace(",", ".")
|
||
+ ",PEP_Y_PARAM="
|
||
+ convertDataFromSerial.setYparamFor3(PRmodelETA, (0.7 * QN_TMP)).ToString().Replace(",", ".")
|
||
+ ",PEP_TYPE='ETA'");
|
||
|
||
mySqlFunctions.Insert("INSERT INTO seg_pump_eng_param_1 SET PEP_PUP_ID="
|
||
+ dataReader["PUP_ID"].ToString()
|
||
+ ",PEP_X_PARAM="
|
||
+ QN_TMP.ToString().Replace(",", ".")
|
||
+ ",PEP_Y_PARAM="
|
||
+ convertDataFromSerial.setYparamFor3(PRmodelETA, QN_TMP).ToString().Replace(",", ".")
|
||
+ ",PEP_TYPE='ETA'");
|
||
|
||
mySqlFunctions.Insert("INSERT INTO seg_pump_eng_param_1 SET PEP_PUP_ID="
|
||
+ dataReader["PUP_ID"].ToString()
|
||
+ ",PEP_X_PARAM="
|
||
+ (1.22 * QN_TMP).ToString().Replace(",", ".")
|
||
+ ",PEP_Y_PARAM="
|
||
+ convertDataFromSerial.setYparamFor3(PRmodelETA, (1.22 * QN_TMP)).ToString().Replace(",", ".")
|
||
+ ",PEP_TYPE='ETA'");
|
||
|
||
|
||
mySqlFunctions.Insert("INSERT INTO seg_pump_eng_param_1 SET PEP_PUP_ID="
|
||
+ dataReader["PUP_ID"].ToString()
|
||
+ ",PEP_X_PARAM="
|
||
+ (1.35 * QN_TMP).ToString().Replace(",", ".")
|
||
+ ",PEP_Y_PARAM="
|
||
+ convertDataFromSerial.setYparamFor3(PRmodelETA, (1.35 * QN_TMP)).ToString().Replace(",", ".")
|
||
+ ",PEP_TYPE='ETA'");
|
||
|
||
mySqlFunctions.Insert("INSERT INTO seg_pump_eng_param_1 SET PEP_PUP_ID="
|
||
+ dataReader["PUP_ID"].ToString()
|
||
+ ",PEP_X_PARAM="
|
||
+ (1.42 * QN_TMP).ToString().Replace(",", ".")
|
||
+ ",PEP_Y_PARAM="
|
||
+ convertDataFromSerial.setYparamFor3(PRmodelETA, (1.42 * QN_TMP)).ToString().Replace(",", ".")
|
||
+ ",PEP_TYPE='ETA'");
|
||
|
||
// ==========================================================
|
||
|
||
|
||
|
||
}
|
||
|
||
mySqlFunctions.Insert("TRUNCATE table seg_pump_eng_param");
|
||
mySqlFunctions.Insert("insert into seg_pump_eng_param select null,PEP_PUP_ID,PEP_X_PARAM,PEP_Y_PARAM,PEP_TYPE from seg_pump_eng_param_1");
|
||
mySqlFunctions.Insert("TRUNCATE table seg_pump_eng_param_1");
|
||
|
||
|
||
mySqlFunctions.CloseConnection();
|
||
MessageBox.Show("Proces zakończony sukcesem.");
|
||
|
||
}
|
||
|
||
}
|
||
|
||
private void zmieńHasłoToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
ChangePassword chpassform = new ChangePassword();
|
||
chpassform.ShowDialog();
|
||
}
|
||
|
||
private void dodajUżytkownikaToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
AddUser formadd = new AddUser();
|
||
formadd.ShowDialog();
|
||
}
|
||
|
||
private void resetujHasłoToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
ResetUsersPass formres = new ResetUsersPass();
|
||
formres.ShowDialog();
|
||
}
|
||
|
||
private void textBoxStanIzolacji_KeyPress(object sender, KeyPressEventArgs e)
|
||
{
|
||
const char delete = (char)8;
|
||
e.Handled = !Char.IsDigit(e.KeyChar) && e.KeyChar != delete;
|
||
}
|
||
|
||
private void pictureBox1_Click(object sender, EventArgs e)
|
||
{
|
||
textBoxAgregatPompa.Text = "";
|
||
textBoxPompaSN.Text = "";
|
||
textBoxAgregatSilnik.Text = "";
|
||
textBoxSilnikSN.Text = "";
|
||
vGlobal.ape_aggregate_id = 0;
|
||
|
||
CompanyLists cmplistform = new CompanyLists();
|
||
cmplistform.FormClosed += new FormClosedEventHandler(pictureBox1_FormClosed);
|
||
cmplistform.ShowDialog();
|
||
}
|
||
|
||
private void textBoxCompanyName_Click(object sender, EventArgs e)
|
||
{
|
||
textBoxAgregatPompa.Text = "";
|
||
textBoxPompaSN.Text = "";
|
||
textBoxAgregatSilnik.Text = "";
|
||
textBoxSilnikSN.Text = "";
|
||
vGlobal.ape_aggregate_id = 0;
|
||
|
||
CompanyLists cmplistform = new CompanyLists();
|
||
cmplistform.FormClosed += new FormClosedEventHandler(pictureBox1_FormClosed);
|
||
cmplistform.ShowDialog();
|
||
}
|
||
|
||
private void słownikiToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
dictionariesForm dicform = new dictionariesForm();
|
||
dicform.ShowDialog();
|
||
}
|
||
|
||
private void kontrahenciToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
CompanyListsData kontrahform = new CompanyListsData();
|
||
kontrahform.ShowDialog();
|
||
}
|
||
|
||
void pictureBox1_FormClosed(object sender, FormClosedEventArgs e)
|
||
{
|
||
|
||
if (vGlobal.app_participants_id > 0)
|
||
{
|
||
stanyPompToolStripMenuItem.Enabled = true;
|
||
stanySilnikówToolStripMenuItem.Enabled = true;
|
||
stanyAgregatówToolStripMenuItem.Enabled = true;
|
||
}
|
||
|
||
}
|
||
|
||
private void buttonZasilanie001_Click(object sender, EventArgs e)
|
||
{
|
||
buttonZasilanie001.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonZasilanie001.BackColor = Color.FromArgb(0, 192, 0);
|
||
|
||
buttonZasilanie002.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie002.BackColor = SystemColors.Control;
|
||
buttonZasilanie003.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie003.BackColor = SystemColors.Control;
|
||
buttonZasilanie004.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie004.BackColor = SystemColors.Control;
|
||
|
||
odplyw = 1;
|
||
}
|
||
|
||
private void buttonZasilanie002_Click(object sender, EventArgs e)
|
||
{
|
||
buttonZasilanie002.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonZasilanie002.BackColor = Color.FromArgb(0, 192, 0);
|
||
|
||
buttonZasilanie001.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie001.BackColor = SystemColors.Control;
|
||
buttonZasilanie003.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie003.BackColor = SystemColors.Control;
|
||
buttonZasilanie004.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie004.BackColor = SystemColors.Control;
|
||
|
||
if (nap_conf == 500 || nap_conf == 1000)
|
||
odplyw = 2;
|
||
else
|
||
odplyw = 3;
|
||
}
|
||
|
||
private void buttonZasilanie003_Click(object sender, EventArgs e)
|
||
{
|
||
buttonZasilanie003.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonZasilanie003.BackColor = Color.FromArgb(0, 192, 0);
|
||
|
||
buttonZasilanie001.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie001.BackColor = SystemColors.Control;
|
||
buttonZasilanie002.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie002.BackColor = SystemColors.Control;
|
||
buttonZasilanie004.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie004.BackColor = SystemColors.Control;
|
||
|
||
if (nap_conf == 500 || nap_conf == 1000)
|
||
odplyw = 3;
|
||
else
|
||
odplyw = 4;
|
||
}
|
||
|
||
private void buttonZasilanie004_Click(object sender, EventArgs e)
|
||
{
|
||
buttonZasilanie004.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonZasilanie004.BackColor = Color.FromArgb(0, 192, 0);
|
||
|
||
buttonZasilanie001.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie001.BackColor = SystemColors.Control;
|
||
buttonZasilanie002.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie002.BackColor = SystemColors.Control;
|
||
buttonZasilanie003.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie003.BackColor = SystemColors.Control;
|
||
|
||
odplyw = 2;
|
||
}
|
||
|
||
|
||
private void buttonStanowisko001_Click(object sender, EventArgs e)
|
||
{
|
||
//dla testów odczyt z modbus
|
||
//modBusFunctions.registerReadAll();
|
||
//textBoxStanIzolacji.Text = modBusFunctions.modbusData_list[0].Value.ToString();
|
||
|
||
|
||
buttonZasilanie001.Visible = true;
|
||
buttonZasilanie002.Visible = true;
|
||
buttonZasilanie003.Visible = true;
|
||
buttonZasilanie004.Visible = true;
|
||
|
||
buttonStanowisko001.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonStanowisko001.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonStanowisko002.ForeColor = SystemColors.ControlText;
|
||
buttonStanowisko002.BackColor = SystemColors.Control;
|
||
buttonStanowisko003.ForeColor = SystemColors.ControlText;
|
||
buttonStanowisko003.BackColor = SystemColors.Control;
|
||
|
||
buttonZasilanie001.Text = "0,24 - 63A";
|
||
buttonZasilanie002.Text = "64 - 160A";
|
||
buttonZasilanie003.Text = "161 - 180A";
|
||
buttonZasilanie004.Text = "20A (230V)";
|
||
|
||
// ==========================================================================
|
||
|
||
nap_conf = 400;
|
||
}
|
||
|
||
private void buttonStanowisko002_Click(object sender, EventArgs e)
|
||
{
|
||
buttonZasilanie001.Visible = true;
|
||
buttonZasilanie002.Visible = true;
|
||
buttonZasilanie003.Visible = true;
|
||
buttonZasilanie004.Visible = false;
|
||
|
||
buttonStanowisko002.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonStanowisko002.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonStanowisko001.ForeColor = SystemColors.ControlText;
|
||
buttonStanowisko001.BackColor = SystemColors.Control;
|
||
buttonStanowisko003.ForeColor = SystemColors.ControlText;
|
||
buttonStanowisko003.BackColor = SystemColors.Control;
|
||
|
||
buttonZasilanie001.Text = "0,24 - 63A";
|
||
buttonZasilanie002.Text = "64 - 160A";
|
||
buttonZasilanie003.Text = "161 - 230A";
|
||
|
||
// ==========================================================================
|
||
nap_conf = 500;
|
||
|
||
}
|
||
|
||
private void buttonStanowisko003_Click(object sender, EventArgs e)
|
||
{
|
||
buttonZasilanie001.Visible = true;
|
||
buttonZasilanie002.Visible = true;
|
||
buttonZasilanie003.Visible = false;
|
||
buttonZasilanie004.Visible = false;
|
||
|
||
buttonStanowisko003.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonStanowisko003.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonStanowisko001.ForeColor = SystemColors.ControlText;
|
||
buttonStanowisko001.BackColor = SystemColors.Control;
|
||
buttonStanowisko002.ForeColor = SystemColors.ControlText;
|
||
buttonStanowisko002.BackColor = SystemColors.Control;
|
||
|
||
buttonZasilanie001.Text = "60 - 180A";
|
||
buttonZasilanie002.Text = "181 - 220A";
|
||
|
||
// ==========================================================================
|
||
nap_conf = 1000;
|
||
|
||
}
|
||
|
||
int SafeParseInt(object val)
|
||
{
|
||
if (val == null)
|
||
return 0;
|
||
|
||
var s = val.ToString().Trim();
|
||
|
||
// Zamiana przecinka na kropkę – na wypadek różnych formatów
|
||
s = s.Replace(",", ".");
|
||
|
||
// Spróbuj sparsować jako double, potem przekonwertuj na int
|
||
if (double.TryParse(s, System.Globalization.NumberStyles.Any,
|
||
System.Globalization.CultureInfo.InvariantCulture,
|
||
out double result))
|
||
{
|
||
// Zabezpieczenie przed NaN i Overflow
|
||
if (double.IsNaN(result) || double.IsInfinity(result))
|
||
return 0;
|
||
|
||
// Zaokrąglenie do najbliższej liczby całkowitej
|
||
return (int)Math.Round(result);
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
|
||
private void getTestConfig(int inDN=50)
|
||
{
|
||
string queryCondition = "";
|
||
|
||
if (inDN == 50) queryCondition = "DN50";
|
||
else if (inDN == 100) queryCondition = "DN100";
|
||
else if (inDN == 150) queryCondition = "DN150";
|
||
|
||
|
||
mySqlFunctions.initConnection();
|
||
if (mySqlFunctions.OpenConnection())
|
||
{
|
||
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("SELECT * FROM tst_test_config WHERE TTC_DN_TYPE='"+ queryCondition + "'", mySqlFunctions.connection);
|
||
MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader();
|
||
while (dataReader.Read())
|
||
{
|
||
czas_na_wygrzanie = SafeParseInt(dataReader["TTC_BURN_TIME"]);
|
||
luz_zasuwy = SafeParseInt(dataReader["TTC_ZAS"]);
|
||
czas_zasuwy = SafeParseInt(dataReader["TTC_STEP"]);
|
||
}
|
||
dataReader.Close();
|
||
mySqlFunctions.CloseConnection();
|
||
|
||
//MessageBox.Show("Pobrano konfigurację testu dla DN" + inDN.ToString() + "\nCzas na wygrzanie: " + czas_na_wygrzanie.ToString() + " min\nLuz zasuwy: " + luz_zasuwy.ToString() + " ms\nCzas zasuwy: " + czas_zasuwy.ToString() + " ms");
|
||
}
|
||
}
|
||
|
||
|
||
// wybór DN pompy
|
||
private void buttonDN50_Click(object sender, EventArgs e)
|
||
{
|
||
buttonDN50.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonDN50.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonDN100.ForeColor = SystemColors.ControlText;
|
||
buttonDN100.BackColor = SystemColors.Control;
|
||
buttonDN150.ForeColor = SystemColors.ControlText;
|
||
buttonDN150.BackColor = SystemColors.Control;
|
||
|
||
//domykanie_zasuwy_start = 30500;
|
||
//po_wygrzaniu_zamkniecie = 30500; // w ms
|
||
//luz_zasuwy = 18000;
|
||
//czas_zasuwy = 250;
|
||
|
||
dP = 50;
|
||
getTestConfig((int)dP);
|
||
|
||
domykanie_zasuwy_start = luz_zasuwy + (czas_zasuwy * 20); //ms
|
||
po_wygrzaniu_zamkniecie = luz_zasuwy + (czas_zasuwy * 20); // ms
|
||
}
|
||
|
||
private void buttonDN100_Click(object sender, EventArgs e)
|
||
{
|
||
buttonDN100.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonDN100.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonDN50.ForeColor = SystemColors.ControlText;
|
||
buttonDN50.BackColor = SystemColors.Control;
|
||
buttonDN150.ForeColor = SystemColors.ControlText;
|
||
buttonDN150.BackColor = SystemColors.Control;
|
||
|
||
//domykanie_zasuwy_start = 7500; //ms
|
||
//po_wygrzaniu_zamkniecie = 10000; // w ms
|
||
//luz_zasuwy = 4400; //ms
|
||
//czas_zasuwy = 250; //ms
|
||
|
||
dP = 100;
|
||
getTestConfig((int)dP);
|
||
|
||
domykanie_zasuwy_start = luz_zasuwy + (czas_zasuwy * 15); //ms
|
||
po_wygrzaniu_zamkniecie = luz_zasuwy + (czas_zasuwy * 15); // ms
|
||
}
|
||
|
||
private void buttonDN150_Click(object sender, EventArgs e)
|
||
{
|
||
buttonDN150.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonDN150.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonDN50.ForeColor = SystemColors.ControlText;
|
||
buttonDN50.BackColor = SystemColors.Control;
|
||
buttonDN100.ForeColor = SystemColors.ControlText;
|
||
buttonDN100.BackColor = SystemColors.Control;
|
||
|
||
//domykanie_zasuwy_start = 7500; //ms
|
||
//po_wygrzaniu_zamkniecie = 12000; // w ms
|
||
//luz_zasuwy = 6000; //ms
|
||
//czas_zasuwy = 750; //ms 750
|
||
|
||
|
||
dP = 150;
|
||
getTestConfig((int)dP);
|
||
|
||
domykanie_zasuwy_start = luz_zasuwy + (czas_zasuwy * 20); //ms
|
||
po_wygrzaniu_zamkniecie = luz_zasuwy + (czas_zasuwy * 20); // ms
|
||
}
|
||
|
||
|
||
private void startButtonsTorNapieciePrad_on()
|
||
{
|
||
textBoxEndQ.Enabled = true;
|
||
textBoxStanIzolacji.Enabled = true;
|
||
|
||
buttonDN50.Enabled = true;
|
||
buttonDN100.Enabled = true;
|
||
buttonDN150.Enabled = true;
|
||
|
||
buttonStanowisko001.Enabled = true;
|
||
buttonStanowisko002.Enabled = true;
|
||
buttonStanowisko003.Enabled = true;
|
||
|
||
buttonZasilanie001.Enabled = true;
|
||
buttonZasilanie002.Enabled = true;
|
||
buttonZasilanie003.Enabled = true;
|
||
buttonZasilanie004.Enabled = true;
|
||
}
|
||
|
||
private void startButtonsTorNapieciePrad_off()
|
||
{
|
||
buttonLogsExport.Visible = false;
|
||
buttonEndOnDemand.Visible = false;
|
||
|
||
textBoxEndQ.Enabled = false;
|
||
textBoxStanIzolacji.Enabled = false;
|
||
|
||
buttonDN50.Enabled = false;
|
||
buttonDN100.Enabled = false;
|
||
buttonDN150.Enabled = false;
|
||
|
||
buttonStanowisko001.Enabled = false;
|
||
buttonStanowisko002.Enabled = false;
|
||
buttonStanowisko003.Enabled = false;
|
||
|
||
buttonZasilanie001.Enabled = false;
|
||
buttonZasilanie002.Enabled = false;
|
||
buttonZasilanie003.Enabled = false;
|
||
buttonZasilanie004.Enabled = false;
|
||
|
||
richTextBoxSerialLogs.Enabled = false;
|
||
}
|
||
|
||
|
||
|
||
private void dobierzNapieciePrad(double napiecie, double prad)
|
||
{
|
||
buttonDN50.ForeColor = SystemColors.ControlText;
|
||
buttonDN50.BackColor = SystemColors.Control;
|
||
buttonDN100.ForeColor = SystemColors.ControlText;
|
||
buttonDN100.BackColor = SystemColors.Control;
|
||
buttonDN150.ForeColor = SystemColors.ControlText;
|
||
buttonDN150.BackColor = SystemColors.Control;
|
||
|
||
if (napiecie<=450)
|
||
{
|
||
buttonZasilanie001.Visible = true;
|
||
buttonZasilanie002.Visible = true;
|
||
buttonZasilanie003.Visible = true;
|
||
buttonZasilanie004.Visible = true;
|
||
buttonStanowisko001.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonStanowisko001.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonStanowisko002.ForeColor = SystemColors.ControlText;
|
||
buttonStanowisko002.BackColor = SystemColors.Control;
|
||
buttonStanowisko003.ForeColor = SystemColors.ControlText;
|
||
buttonStanowisko003.BackColor = SystemColors.Control;
|
||
buttonZasilanie001.Text = "0,24 - 63A";
|
||
buttonZasilanie002.Text = "64 - 160A";
|
||
buttonZasilanie003.Text = "161 - 180A";
|
||
buttonZasilanie004.Text = "20A (230V)";
|
||
|
||
nap_conf = 400;
|
||
|
||
//warunki dla Prądów
|
||
if(napiecie<300)
|
||
{
|
||
buttonZasilanie004.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonZasilanie004.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonZasilanie001.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie001.BackColor = SystemColors.Control;
|
||
buttonZasilanie002.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie002.BackColor = SystemColors.Control;
|
||
buttonZasilanie003.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie003.BackColor = SystemColors.Control;
|
||
odplyw = 2;
|
||
}
|
||
|
||
if(prad < 64)
|
||
{
|
||
buttonZasilanie001.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonZasilanie001.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonZasilanie002.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie002.BackColor = SystemColors.Control;
|
||
buttonZasilanie003.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie003.BackColor = SystemColors.Control;
|
||
buttonZasilanie004.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie004.BackColor = SystemColors.Control;
|
||
odplyw = 1;
|
||
}
|
||
if (prad >= 64 && prad < 161)
|
||
{
|
||
buttonZasilanie002.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonZasilanie002.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonZasilanie001.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie001.BackColor = SystemColors.Control;
|
||
buttonZasilanie003.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie003.BackColor = SystemColors.Control;
|
||
buttonZasilanie004.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie004.BackColor = SystemColors.Control;
|
||
odplyw = 3;
|
||
}
|
||
if (prad >= 161)
|
||
{
|
||
buttonZasilanie003.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonZasilanie003.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonZasilanie001.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie001.BackColor = SystemColors.Control;
|
||
buttonZasilanie002.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie002.BackColor = SystemColors.Control;
|
||
buttonZasilanie004.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie004.BackColor = SystemColors.Control;
|
||
odplyw = 3;
|
||
}
|
||
|
||
|
||
|
||
}
|
||
else if (napiecie > 450 && napiecie <= 690)
|
||
{
|
||
buttonZasilanie001.Visible = true;
|
||
buttonZasilanie002.Visible = true;
|
||
buttonZasilanie003.Visible = true;
|
||
buttonZasilanie004.Visible = false;
|
||
buttonStanowisko002.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonStanowisko002.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonStanowisko001.ForeColor = SystemColors.ControlText;
|
||
buttonStanowisko001.BackColor = SystemColors.Control;
|
||
buttonStanowisko003.ForeColor = SystemColors.ControlText;
|
||
buttonStanowisko003.BackColor = SystemColors.Control;
|
||
buttonZasilanie001.Text = "0,24 - 63A";
|
||
buttonZasilanie002.Text = "64 - 160A";
|
||
buttonZasilanie003.Text = "161 - 230A";
|
||
|
||
nap_conf = 500;
|
||
|
||
//warunki dla Prądów
|
||
if (prad < 64)
|
||
{
|
||
buttonZasilanie001.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonZasilanie001.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonZasilanie002.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie002.BackColor = SystemColors.Control;
|
||
buttonZasilanie003.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie003.BackColor = SystemColors.Control;
|
||
buttonZasilanie004.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie004.BackColor = SystemColors.Control;
|
||
odplyw = 1;
|
||
}
|
||
if (prad >= 64 && prad < 161)
|
||
{
|
||
buttonZasilanie002.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonZasilanie002.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonZasilanie001.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie001.BackColor = SystemColors.Control;
|
||
buttonZasilanie003.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie003.BackColor = SystemColors.Control;
|
||
buttonZasilanie004.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie004.BackColor = SystemColors.Control;
|
||
odplyw = 2;
|
||
}
|
||
if (prad >= 161)
|
||
{
|
||
buttonZasilanie003.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonZasilanie003.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonZasilanie001.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie001.BackColor = SystemColors.Control;
|
||
buttonZasilanie002.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie002.BackColor = SystemColors.Control;
|
||
buttonZasilanie004.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie004.BackColor = SystemColors.Control;
|
||
odplyw = 3;
|
||
}
|
||
}
|
||
else if (napiecie > 690 && napiecie <= 1200)
|
||
{
|
||
buttonZasilanie001.Visible = true;
|
||
buttonZasilanie002.Visible = true;
|
||
buttonZasilanie003.Visible = false;
|
||
buttonZasilanie004.Visible = false;
|
||
buttonStanowisko003.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonStanowisko003.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonStanowisko001.ForeColor = SystemColors.ControlText;
|
||
buttonStanowisko001.BackColor = SystemColors.Control;
|
||
buttonStanowisko002.ForeColor = SystemColors.ControlText;
|
||
buttonStanowisko002.BackColor = SystemColors.Control;
|
||
buttonZasilanie001.Text = "60 - 180A";
|
||
buttonZasilanie002.Text = "181 - 220A";
|
||
|
||
nap_conf = 1000;
|
||
|
||
//warunki dla Prądów
|
||
if (prad < 181)
|
||
{
|
||
buttonZasilanie001.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonZasilanie001.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonZasilanie002.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie002.BackColor = SystemColors.Control;
|
||
buttonZasilanie003.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie003.BackColor = SystemColors.Control;
|
||
buttonZasilanie004.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie004.BackColor = SystemColors.Control;
|
||
odplyw = 1;
|
||
}
|
||
else
|
||
{
|
||
buttonZasilanie002.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonZasilanie002.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonZasilanie001.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie001.BackColor = SystemColors.Control;
|
||
buttonZasilanie003.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie003.BackColor = SystemColors.Control;
|
||
buttonZasilanie004.ForeColor = SystemColors.ControlText;
|
||
buttonZasilanie004.BackColor = SystemColors.Control;
|
||
odplyw = 2;
|
||
}
|
||
|
||
// dla 1000V mamy tylko tor DN150
|
||
buttonDN150.ForeColor = Color.FromArgb(255, 255, 255);
|
||
buttonDN150.BackColor = Color.FromArgb(0, 192, 0);
|
||
buttonDN50.ForeColor = SystemColors.ControlText;
|
||
buttonDN50.BackColor = SystemColors.Control;
|
||
buttonDN100.ForeColor = SystemColors.ControlText;
|
||
buttonDN100.BackColor = SystemColors.Control;
|
||
|
||
//domykanie_zasuwy_start = 7500; //ms
|
||
//po_wygrzaniu_zamkniecie = 12000; // w ms
|
||
|
||
dP = 150;
|
||
getTestConfig((int)dP);
|
||
|
||
domykanie_zasuwy_start = luz_zasuwy + (czas_zasuwy * 20); //ms
|
||
po_wygrzaniu_zamkniecie = luz_zasuwy + (czas_zasuwy * 20); // ms
|
||
}
|
||
}
|
||
|
||
|
||
private void pictureBox2_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
ChoosePumpUnit PumpUnitform = new ChoosePumpUnit();
|
||
PumpUnitform.FormClosed += new FormClosedEventHandler(pictureBox2_FormClosed);
|
||
PumpUnitform.ShowDialog();
|
||
|
||
global_licznik = 0;
|
||
buttonResretModbus.Enabled = false;
|
||
buttonResretModbus.BackColor = SystemColors.ControlDark;
|
||
buttonResretModbus.ForeColor = Color.Black;
|
||
|
||
textBoxStanIzolacji.Text = "";
|
||
startButtonsTorNapieciePrad_on();
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(pictureBox2_Click): " + ex.Message);
|
||
}
|
||
}
|
||
|
||
void pictureBox2_FormClosed(object sender, FormClosedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
|
||
if (vGlobal.ape_aggregate_id > 0)
|
||
{
|
||
label_WarningA.Text = "";
|
||
|
||
mySqlFunctions.initConnection();
|
||
if (mySqlFunctions.OpenConnection())
|
||
{
|
||
//MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("select * from seg_aggregate_pup_eng where APE_ID=" + vGlobal.ape_aggregate_id.ToString(), mySqlFunctions.connection);
|
||
//MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("SELECT (SELECT DRS_DEV_ID FROM seg_dev_resources WHERE DRS_ID=TAR_PUP_DRS_ID) AS PUP_ID, (SELECT DRS_DEV_ID FROM seg_dev_resources WHERE DRS_ID=TAR_ENG_DRS_ID) AS ENG_ID, TAR_PUP_NAME,TAR_PUP_SN_NO,TAR_ENG_NAME,TAR_ENG_SN_NO FROM tst_aggregate_remonty WHERE TAR_ID=" + vGlobal.ape_aggregate_id.ToString(), mySqlFunctions.connection);
|
||
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("SELECT (SELECT DRS_DEV_ID FROM seg_dev_resources WHERE DRS_ID=TAR_PUP_DRS_ID) AS PUP_ID, (SELECT DRS_DEV_ID FROM seg_dev_resources WHERE DRS_ID=TAR_ENG_DRS_ID) AS ENG_ID, TAR_PUP_NAME,TAR_PUP_SN_NO,TAR_ENG_NAME,TAR_ENG_SN_NO,ENG_VOLTAGE,ENG_ELECTRICITY FROM tst_aggregate_remonty, seg_dev_resources LEFT JOIN seg_engines ON ENG_ID=DRS_DEV_ID WHERE TAR_ENG_DRS_ID=DRS_ID and TAR_ID=" + vGlobal.ape_aggregate_id.ToString(), mySqlFunctions.connection);
|
||
MySql.Data.MySqlClient.MySqlDataReader dataReader = cmd.ExecuteReader();
|
||
while (dataReader.Read())
|
||
{
|
||
// wypełnia dane
|
||
pumpName = dataReader[2].ToString();
|
||
textBoxAgregatPompa.Text = dataReader[2].ToString();
|
||
textBoxPompaSN.Text = dataReader[3].ToString();
|
||
textBoxAgregatSilnik.Text = dataReader[4].ToString();
|
||
textBoxSilnikSN.Text = dataReader[5].ToString();
|
||
|
||
dobierzNapieciePrad(Convert.ToDouble(dataReader[6].ToString()), Convert.ToDouble(dataReader[7].ToString()));
|
||
|
||
// bierze dane do próby i wykresów
|
||
vGlobal.tst_pump_id = Convert.ToInt32(dataReader[0].ToString());
|
||
vGlobal.tst_eng_id = Convert.ToInt32(dataReader[1].ToString());
|
||
|
||
qMax = mySqlFunctions.getQmaxforPumpID(vGlobal.tst_pump_id);
|
||
//hMax = mySqlFunctions.getHmaxforPumpID(vGlobal.tst_pump_id);
|
||
hMax = mySqlFunctions.getScaledMaxForPumpWithRegression(vGlobal.tst_pump_id);
|
||
|
||
vGlobal.tst_pump_qn = mySqlFunctions.sqlDoubleValue("select PUP_Q_N from seg_pumps where PUP_ID=" + dataReader[0].ToString());
|
||
|
||
|
||
//m3/h
|
||
//vGlobal.tst_pump_qgreen = 0.7 * vGlobal.tst_pump_qn;
|
||
//tst_pump_3thRedRigth = 1.35 * vGlobal.tst_pump_qn;
|
||
//tst_pump_QgreenRigth = 1.22 * vGlobal.tst_pump_qn;
|
||
//m3/min
|
||
vGlobal.tst_pump_qgreen = convertDataFromSerial.ConvertToM3PerMin(0.7 * vGlobal.tst_pump_qn);
|
||
tst_pump_3thRedRigth = convertDataFromSerial.ConvertToM3PerMin(1.35 * vGlobal.tst_pump_qn);
|
||
tst_pump_QgreenRigth = convertDataFromSerial.ConvertToM3PerMin(1.22 * vGlobal.tst_pump_qn);
|
||
|
||
|
||
engPower = mySqlFunctions.sqlDoubleValue("select MAX(ENG_POWER) from seg_engines where ENG_ID=" + dataReader[1].ToString());
|
||
vGlobal.tst_Inom = mySqlFunctions.sqlDoubleValue("select ENG_ELECTRICITY from seg_engines where ENG_ID=" + dataReader[1].ToString());
|
||
vGlobal.tst_Unom = mySqlFunctions.sqlDoubleValue("select ENG_VOLTAGE from seg_engines where ENG_ID=" + dataReader[1].ToString());
|
||
|
||
labelQn.Text = "Qn = " + Math.Round(vGlobal.tst_pump_qn/60,3).ToString() + " [m3/min]";
|
||
//labelHp.Text = "Hp = " + Math.Round(convertDataFromSerial.setYparamFor3(mySqlFunctions.getPolyRegresionModel(vGlobal.tst_pump_id, 3), vGlobal.tst_pump_qn),2).ToString() + " [m]";
|
||
labelHp.Text = "Hp = " + Math.Round(GetPumpPolynomialValue(vGlobal.tst_pump_id, convertDataFromSerial.ConvertToM3PerMin(vGlobal.tst_pump_qn)),2).ToString() + " [m]";
|
||
labelU.Text = "Un = " + Math.Round(vGlobal.tst_Unom,2).ToString() + " [V]";
|
||
labelA.Text = "In = " + Math.Round(vGlobal.tst_Inom,2).ToString() + " [A]";
|
||
labelkW.Text = "Pn = " + Math.Round(engPower,2).ToString() + " [kW]";
|
||
|
||
|
||
engPower = Math.Ceiling(engPower * 1.6); // do wykresu bierzemy 160% mocy silnika
|
||
|
||
//skaluje wykres w zależności od Qn pompy
|
||
if (vGlobal.tst_pump_qn < 1.5) qMax = qMax / 4;
|
||
else if (vGlobal.tst_pump_qn >= 1.5 && vGlobal.tst_pump_qn < 2) qMax = qMax / 2;
|
||
|
||
// Po wybraniu pompy buduje skale na wykresach i przygotowuje serie.
|
||
// ============================================================== //
|
||
setChartAreasAndScale(chartH, "H", qMax, "Q [m3/min]", hMax, "H [m]");
|
||
setSeriesBubble(chartH, "H", 4);
|
||
// ============================================================== //
|
||
setChartAreasAndScale(chartP, "P", qMax, "Q [m3/min]", Convert.ToInt32(engPower), "P [kW]");
|
||
setSeriesBubble(chartP, "P", 4);
|
||
// ============================================================== //
|
||
setChartAreasAndScale(chartETA, "ETA", qMax, "Q [m3/min]", 1, "ƞ");
|
||
setSeriesBubble(chartETA, "ETA", 4);
|
||
// ============================================================== //
|
||
|
||
//tutaj
|
||
setBackgroundArea(chartH, "H", 30, qMax, hMax, vGlobal.tst_pump_qn);
|
||
setBackgroundArea(chartP, "P", 30, qMax, Convert.ToInt32(engPower), vGlobal.tst_pump_qn);
|
||
setBackgroundArea(chartETA, "ETA", 30, qMax, 1, vGlobal.tst_pump_qn);
|
||
|
||
drawCatalougeSplineForPump(vGlobal.tst_pump_id, qMax);
|
||
|
||
}
|
||
dataReader.Close();
|
||
mySqlFunctions.CloseConnection();
|
||
}
|
||
setActiveAreaForTest();
|
||
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(pictureBox2_FormClosed): " + ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
//wywołuje listę dostepnych pomp - stany
|
||
private void stanyPompToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
PumpStockListForm pslForm = new PumpStockListForm();
|
||
pslForm.ShowDialog();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(stanyPompToolStripMenuItem_Click): " + ex.Message);
|
||
}
|
||
}
|
||
|
||
private void stanySilnikówToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
MotorStockListForm mslForm = new MotorStockListForm();
|
||
mslForm.ShowDialog();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(stanySilnikówToolStripMenuItem_Click): " + ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
private void stanyAgregatówToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
AggregateStockListForm aslForm = new AggregateStockListForm();
|
||
aslForm.ShowDialog();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(stanyAgregatówToolStripMenuItem_Click): " + ex.Message);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
private void resetSterownikówToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
this.serialPort.PortName = serialPortName;
|
||
this.serialPort.BaudRate = serialPortSpeed;
|
||
|
||
serialPort.Open();
|
||
|
||
// jeśli port otwarty
|
||
if (serialPort.IsOpen)
|
||
{
|
||
richTextBoxSerialLogs.Enabled = true;
|
||
richTextBoxSerialLogs.Invoke(new Action(delegate ()
|
||
{
|
||
richTextBoxSerialLogs.AppendText("Reset sterowników [" + stanowiskoID.ToString() + "][" + zasilanieID.ToString() + "]" + (char)10);
|
||
}));
|
||
|
||
sendRequestFunction(concentratorName + "!!", 1000);
|
||
richTextBoxSerialLogs.Invoke(new Action(delegate ()
|
||
{
|
||
richTextBoxSerialLogs.AppendText(concentratorName + "!!" + (char)10);
|
||
}));
|
||
|
||
|
||
sendRequestFunction(":::" + modbusReset + (char)13 + (char)10, 1000);
|
||
richTextBoxSerialLogs.Invoke(new Action(delegate ()
|
||
{
|
||
richTextBoxSerialLogs.AppendText(":::" + modbusReset + (char)10);
|
||
}));
|
||
|
||
sendRequestFunction(":::" + modbusOffHigh + (char)13 + (char)10, 1000);
|
||
richTextBoxSerialLogs.Invoke(new Action(delegate ()
|
||
{
|
||
richTextBoxSerialLogs.AppendText(":::" + modbusOffHigh + (char)10);
|
||
}));
|
||
|
||
sendRequestFunction(":::" + modbusOffLow + (char)13 + (char)10, 1000);
|
||
richTextBoxSerialLogs.Invoke(new Action(delegate ()
|
||
{
|
||
richTextBoxSerialLogs.AppendText(":::" + modbusOffLow + (char)10);
|
||
}));
|
||
|
||
sendRequestFunction(":::" + modbusReset + (char)13 + (char)10, 1000);
|
||
richTextBoxSerialLogs.Invoke(new Action(delegate ()
|
||
{
|
||
richTextBoxSerialLogs.AppendText(":::" + modbusReset + (char)10 + (char)10);
|
||
}));
|
||
|
||
serialPort.Close();
|
||
|
||
buttonLogsExport.Visible = true;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("Błąd otwarcia portu: " + serialPort.PortName.ToString(), ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
private void buttonLogsExport_Click(object sender, EventArgs e)
|
||
{
|
||
// Create a SaveFileDialog to request a path and file name to save to.
|
||
SaveFileDialog saveRichBoxFile = new SaveFileDialog();
|
||
DateTime logdate = DateTime.Now;
|
||
|
||
// Initialize the SaveFileDialog to specify the RTF extension for the file.
|
||
saveRichBoxFile.DefaultExt = "*.txt";
|
||
saveRichBoxFile.Filter = "txt|*.txt";
|
||
saveRichBoxFile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||
saveRichBoxFile.FileName = logdate.ToString("yyyyMMdd_HHmmss") + "_spmlog";
|
||
saveRichBoxFile.FilterIndex = 2;
|
||
saveRichBoxFile.RestoreDirectory = true;
|
||
|
||
// Determine if the user selected a file name from the saveFileDialog.
|
||
if (saveRichBoxFile.ShowDialog() == System.Windows.Forms.DialogResult.OK && saveRichBoxFile.FileName.Length > 0)
|
||
{
|
||
// Save the contents of the RichTextBox into the file.
|
||
richTextBoxSerialLogs.SaveFile(saveRichBoxFile.FileName, RichTextBoxStreamType.PlainText);
|
||
}
|
||
}
|
||
|
||
|
||
private void kopiaZapasowaToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
BackUpForm formBackUpForm = new BackUpForm();
|
||
formBackUpForm.ShowDialog();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(kopiaZapasowaToolStripMenuItem_Click): " + ex.Message);
|
||
}
|
||
}
|
||
|
||
private void OknoGlowneForm_FormClosing(object sender, FormClosingEventArgs e)
|
||
{
|
||
//Resetuje modBus
|
||
if (modBusFunctions.isConnected)
|
||
{
|
||
modBusFunctions.registerWriteAll(0, 0, 0, 0, 0, 0, 0, 0);
|
||
modBusFunctions.CloseConnection();
|
||
}
|
||
if (modbusThread != null && modbusThread.IsAlive)
|
||
modbusThread.Abort();
|
||
}
|
||
|
||
// ======================================================================== //
|
||
private void zamknijToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
//Resetuje modBus
|
||
if (modBusFunctions.isConnected)
|
||
{
|
||
modBusFunctions.registerWriteAll(0, 0, 0, 0, 0, 0, 0, 0);
|
||
modBusFunctions.CloseConnection();
|
||
}
|
||
if (modbusThread != null && modbusThread.IsAlive)
|
||
modbusThread.Abort();
|
||
|
||
this.Close();
|
||
}
|
||
|
||
private void textBoxEndQ_Leave(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
textBoxEndQ.Text = textBoxEndQ.Text.Replace(".", ",");
|
||
double myInt;
|
||
bool isNumerical = double.TryParse(textBoxEndQ.Text, out myInt);
|
||
|
||
if (!isNumerical)
|
||
{
|
||
MessageBox.Show("Wprowadzona wartość Q musi być liczbą!\nWprowadź proszę ponownie.");
|
||
textBoxEndQ.Focus();
|
||
textBoxEndQ.BackColor = Color.Yellow;
|
||
}
|
||
|
||
wydajnosc_max = Convert.ToDouble(textBoxEndQ.Text);
|
||
//MessageBox.Show("Maksymalna wydajność próby została ustawiona na " + wydajnosc_max.ToString() + " [m3/h]");
|
||
|
||
}
|
||
catch { }
|
||
}
|
||
|
||
private void buttonEndOnDemand_Click(object sender, EventArgs e)
|
||
{
|
||
//KOŃCZY PRZEBIEG PRÓBY NA ŻĄDANIE
|
||
buttonStartTest.Invoke(new Action(delegate ()
|
||
{
|
||
buttonStartTest.BackColor = System.Drawing.Color.FromArgb(255, 162, 100);
|
||
buttonStartTest.Text = "Generuj raport";
|
||
}));
|
||
_continue = false;
|
||
}
|
||
|
||
private void testConfigToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
testConfig formTestConfig = new testConfig();
|
||
formTestConfig.ShowDialog();
|
||
|
||
getTestConfig((int)dP);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("f(testConfigToolStripMenuItem_Click): " + ex.Message);
|
||
}
|
||
}
|
||
|
||
/*
|
||
public static double GetPumpPolynomialValue(int pump_id, double q, int reg_val = 3)
|
||
{
|
||
// Wynik końcowy
|
||
double result = double.NaN;
|
||
|
||
// Listy danych wejściowych
|
||
List<double> x = new List<double>();
|
||
List<double> y = new List<double>();
|
||
|
||
mySqlFunctions.initConnection();
|
||
if (mySqlFunctions.OpenConnection())
|
||
{
|
||
// Budujemy zapytanie SQL (parametryzowane)
|
||
string query = @"
|
||
SELECT (PEP_X_PARAM / 60.0) AS PEP_X_PARAM, PEP_Y_PARAM
|
||
FROM seg_pump_eng_param
|
||
WHERE PEP_PUP_ID = @pump_id
|
||
AND PEP_TYPE = 'H'
|
||
ORDER BY PEP_X_PARAM";
|
||
|
||
MySql.Data.MySqlClient.MySqlCommand cmd =
|
||
new MySql.Data.MySqlClient.MySqlCommand(query, mySqlFunctions.connection);
|
||
cmd.Parameters.AddWithValue("@pump_id", pump_id);
|
||
|
||
MySql.Data.MySqlClient.MySqlDataReader reader = cmd.ExecuteReader();
|
||
|
||
while (reader.Read())
|
||
{
|
||
if (double.TryParse(reader["PEP_X_PARAM"].ToString(), out double xv) &&
|
||
double.TryParse(reader["PEP_Y_PARAM"].ToString(), out double yv))
|
||
{
|
||
x.Add(xv);
|
||
y.Add(yv);
|
||
}
|
||
}
|
||
|
||
reader.Close();
|
||
|
||
// Sprawdzamy, czy są dane
|
||
if (x.Count > 1 && y.Count > 1)
|
||
{
|
||
double[] xArr = x.ToArray();
|
||
double[] yArr = y.ToArray();
|
||
|
||
// Tworzymy model regresji wielomianowej
|
||
var model = Accord.Statistics.Models.Regression.Linear
|
||
.PolynomialRegression.FromData(reg_val, xArr, yArr);
|
||
|
||
// Liczymy wartość dla punktu q
|
||
result = model.Transform(q);
|
||
}
|
||
|
||
mySqlFunctions.CloseConnection();
|
||
}
|
||
|
||
return result;
|
||
}
|
||
*/
|
||
|
||
//zastępujemy nową dla braku katalogowych ZER
|
||
public static double GetPumpPolynomialValue(int pump_id, double q, int reg_val = 3)
|
||
{
|
||
double result = double.NaN;
|
||
|
||
List<double> x = new List<double>();
|
||
List<double> y = new List<double>();
|
||
|
||
mySqlFunctions.initConnection();
|
||
if (mySqlFunctions.OpenConnection())
|
||
{
|
||
try
|
||
{
|
||
// --- 1️⃣ Pobierz punkty pomiarowe ---
|
||
string query = @"
|
||
SELECT (PEP_X_PARAM / 60.0) AS PEP_X_PARAM, PEP_Y_PARAM
|
||
FROM seg_pump_eng_param
|
||
WHERE PEP_PUP_ID = @pump_id
|
||
AND PEP_TYPE = 'H'
|
||
ORDER BY PEP_X_PARAM";
|
||
|
||
using (var cmd = new MySqlCommand(query, mySqlFunctions.connection))
|
||
{
|
||
cmd.Parameters.AddWithValue("@pump_id", pump_id);
|
||
|
||
using (var reader = cmd.ExecuteReader())
|
||
{
|
||
while (reader.Read())
|
||
{
|
||
if (double.TryParse(reader["PEP_X_PARAM"].ToString(), out double xv) &&
|
||
double.TryParse(reader["PEP_Y_PARAM"].ToString(), out double yv))
|
||
{
|
||
x.Add(xv);
|
||
y.Add(yv);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// --- 2️⃣ Sprawdź, czy pierwszy punkt X jest bliski 0 ---
|
||
if (x.Count > 0 && x[0] > 1.0) // brak punktu przy zerze
|
||
{
|
||
string hmaxQuery = "SELECT PUP_H_MAX FROM seg_pumps WHERE PUP_ID = @pump_id";
|
||
using (var hmaxCmd = new MySqlCommand(hmaxQuery, mySqlFunctions.connection))
|
||
{
|
||
hmaxCmd.Parameters.AddWithValue("@pump_id", pump_id);
|
||
object val = hmaxCmd.ExecuteScalar();
|
||
|
||
if (val != DBNull.Value && val != null)
|
||
{
|
||
double hmax = Convert.ToDouble(val);
|
||
|
||
// --- Dodaj punkt (0, Hmax * (1 + 2–3%)) ---
|
||
Random rnd = new Random();
|
||
double margin = rnd.Next(2, 4) / 100.0; // losowo 2–3 %
|
||
double adjustedHmax = hmax * (1.0 + margin);
|
||
|
||
x.Insert(0, 0.0);
|
||
y.Insert(0, adjustedHmax);
|
||
}
|
||
}
|
||
}
|
||
|
||
// --- 3️⃣ Oblicz regresję ---
|
||
if (x.Count > 1 && y.Count > 1)
|
||
{
|
||
double[] xArr = x.ToArray();
|
||
double[] yArr = y.ToArray();
|
||
|
||
var model = PolynomialRegression.FromData(reg_val, xArr, yArr);
|
||
double pred = model.Transform(q);
|
||
|
||
if (!double.IsNaN(pred) && !double.IsInfinity(pred))
|
||
result = pred;
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
// Ciche przechwycenie błędów – zwróci NaN, jeśli coś pójdzie nie tak
|
||
}
|
||
finally
|
||
{
|
||
mySqlFunctions.CloseConnection();
|
||
}
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
|
||
|
||
}
|
||
}
|