//using ConLink.ModBus; //using System; //using System.Collections.Generic; //using System.Linq; //using System.Text; //using static ConLink.BasicFramework.SoftBasic; //using System.Threading; //using System.Threading.Tasks; //using System.Data.SqlClient; ///// ///// ///// //namespace MesWork ///* // public float Ua = 0f; // public float Ub = 0f; // public float Uc = 0f; // public float Uab = 0f; // public float Ubc = 0f; // public float Uca = 0f; // public float Ia = 0f; // public float Ib = 0f; // public float Ic = 0f; // public float Pa = 0f; // public float Pb = 0f; // public float Pc = 0f; // public float P = 0f; // public float Qa = 0f; // public float Qb = 0f; // public float Qc = 0f; // public float Q = 0f; // public float Sa = 0f; // public float Sb = 0f; // public float Sc = 0f; // public float S = 0f; // public float PFa = 0f; // public float PFb = 0f; // public float PFc = 0f; // public float PF = 0f; // public float FR = 0f; // public float Ep1 = 0f; // public float Ep2 = 0f; // public float Eq1 = 0f; // public float Eq2 = 0f; // */ ///* // @Ua REAL = 0, // @Ub REAL = 0, // @Uc REAL = 0, // @Uab REAL = 0, // @Ubc REAL = 0, // @Uca REAL = 0, // @Ia REAL = 0, // @Ib REAL = 0, // @Ic REAL = 0, // @Pa REAL = 0, // @Pb REAL = 0, // @Pc REAL = 0, // @P REAL = 0, // @Qa REAL = 0, // @Qb REAL = 0, // @Qc REAL = 0, // @Q REAL = 0, // @Sa REAL = 0, // @Sb REAL = 0, // @Sc REAL = 0, // @S REAL = 0, // @PFa REAL = 0, // @PFb REAL = 0, // @PFc REAL = 0, // @PF REAL = 0, // @FR REAL = 0, // @Ep1 REAL = 0, // @Ep2 REAL = 0, // @Eq1 REAL = 0, // @Eq2 REAL = 0 // */ //{ // /// // /// // /// // public class ElectricEnergyMeter // { // /// // /// // /// // private string ip = ""; // /// // /// // /// // private int port = 0; // /// // /// / // /// // private byte station = 0; // /// // /// // /// // private string opName = ""; // /// // /// // /// // private int intervalRead = 1 * 1000; // /// // /// // /// // private int intervalUpdate = 5 * 1000; // /// // /// // /// // private int intervalInsert = 10 * 1000; // /// // /// // /// // private ModbusTcpNet mbt = null; // /// // /// // /// // private Thread tt = null; // /// // /// // /// // private Thread ttt = null; // /// // /// // /// // private Thread tttt = null; // /// // /// // /// // private string message = "00 00 00 00 00 06 01 03 00 00 00 3C"; // /// // /// // /// // private int offset = 18; // /// // /// // /// // private int index = 0; // /// // /// // /// // public float Ua = 0f; // /// // /// // /// // public float Ub = 0f; // /// // /// // /// // public float Uc = 0f; // /// // /// // /// // public float Uab = 0f; // /// // /// // /// // public float Ubc = 0f; // /// // /// // /// // public float Uca = 0f; // /// // /// // /// // public float Ia = 0f; // /// // /// // /// // public float Ib = 0f; // /// // /// // /// // public float Ic = 0f; // /// // /// // /// // public float Pa = 0f; // /// // /// // /// // public float Pb = 0f; // /// // /// // /// // public float Pc = 0f; // /// // /// // /// // public float P = 0f; // /// // /// // /// // public float Qa = 0f; // /// // /// // /// // public float Qb = 0f; // /// // /// // /// // public float Qc = 0f; // /// // /// // /// // public float Q = 0f; // /// // /// // /// // public float Sa = 0f; // /// // /// // /// // public float Sb = 0f; // /// // /// // /// // public float Sc = 0f; // /// // /// // /// // public float S = 0f; // /// // /// // /// // public float PFa = 0f; // /// // /// // /// // public float PFb = 0f; // /// // /// // /// // public float PFc = 0f; // /// // /// // /// // public float PF = 0f; // /// // /// // /// // public float FR = 0f; // /// // /// // /// // public float Ep1 = 0f; // /// // /// // /// // public float Ep2 = 0f; // /// // /// // /// // public float Eq1 = 0f; // /// // /// // /// // public float Eq2 = 0f; // /// // /// // /// // public void Start(string ip,int port,byte station,string opName,int intervalRead // , int intervalUpdate ,int intervalInsert) // { // this.ip = ip; // this.port = port; // this.station = station; // this.opName = opName; // this.intervalRead = intervalRead; // this.intervalUpdate = intervalUpdate; // this.intervalInsert = intervalInsert; // mbt = new ModbusTcpNet(ip, port, station); // mbt.AddressStartWithZero = true ; // mbt.SetLoginAccount("",""); // mbt.DataFormat = ConLink.Core.DataFormat.ABCD; // mbt.IsStringReverse = false; // var s = mbt.ConnectServer(); // var dfg = s.IsSuccess; // tt = new Thread(new ThreadStart(Read)); // tt.IsBackground = true; // tt.Start(); // ttt = new Thread(new ThreadStart(Update)); // ttt.IsBackground = true; // ttt.Start(); // tttt = new Thread(new ThreadStart(Insert)); // tttt.IsBackground = true; // tttt.Start(); // } // /// // /// // /// // private void Read() // { // while (true) // { // try // { // var read = mbt.ReadFromCoreServer(HexStringToBytes(this.message)); // if (read.IsSuccess) // { // var rc = read.Content; // var str = ByteToHexString(rc); // //str = "00000000001B010318199A435C199A435C199A435C199A435C199A435C199A435C"; // index = 0; // Ua = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4,4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 1; // Ub = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 2; // Uc = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 3; // Uab = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 4; // Ubc = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 5; // Uca = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 6; // Ia = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 7; // Ib = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 8; // Ic = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 9; // Pa = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 10; // Pb = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 11; // Pc = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 12; // P = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 13; // Qa = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 14; // Qb = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 15; // Qc = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 16; // Q = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 17; // Sa = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 18; // Sb = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 19; // Sc = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 20; // S = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 21; // PFa = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 22; // PFb = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 23; // PFc = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 24; // PF = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 25; // FR = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 26; // Ep1 = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 27; // Ep2 = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 28; // Eq1 = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // index = 29; // Eq2 = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToUInt32( // str.Substring(offset + index * 8 + 4, 4) + str.Substring(offset + index * 8 + 0, 4) // , 16)), 0); // } // else // { // Thread.Sleep(this.intervalRead * 3); // } // } // catch (Exception err) // { // } // Thread.Sleep(this.intervalRead); // } // } // /// // /// // /// // private void Update() // { // while (true) // { // try // { // ExecUpdate(); // } // catch (Exception err) // { // } // Thread.Sleep(this.intervalUpdate); // } // } // /// // /// // /// // private void Insert() // { // while (true) // { // try // { // ExecInsert(); // } // catch (Exception err) // { // } // Thread.Sleep(this.intervalInsert); // } // } // /// // /// // /// // private void ExecUpdate() // { // /* // public float Ua = 0f; // public float Ub = 0f; // public float Uc = 0f; // public float Uab = 0f; // public float Ubc = 0f; // public float Uca = 0f; // public float Ia = 0f; // public float Ib = 0f; // public float Ic = 0f; // public float Pa = 0f; // public float Pb = 0f; // public float Pc = 0f; // public float P = 0f; // public float Qa = 0f; // public float Qb = 0f; // public float Qc = 0f; // public float Q = 0f; // public float Sa = 0f; // public float Sb = 0f; // public float Sc = 0f; // public float S = 0f; // public float PFa = 0f; // public float PFb = 0f; // public float PFc = 0f; // public float PF = 0f; // public float FR = 0f; // public float Ep1 = 0f; // public float Ep2 = 0f; // public float Eq1 = 0f; // public float Eq2 = 0f; // */ // UpdateCurr(); // } // /// // /// // /// // private void ExecInsert() // { // /* // public float Ua = 0f; // public float Ub = 0f; // public float Uc = 0f; // public float Uab = 0f; // public float Ubc = 0f; // public float Uca = 0f; // public float Ia = 0f; // public float Ib = 0f; // public float Ic = 0f; // public float Pa = 0f; // public float Pb = 0f; // public float Pc = 0f; // public float P = 0f; // public float Qa = 0f; // public float Qb = 0f; // public float Qc = 0f; // public float Q = 0f; // public float Sa = 0f; // public float Sb = 0f; // public float Sc = 0f; // public float S = 0f; // public float PFa = 0f; // public float PFb = 0f; // public float PFc = 0f; // public float PF = 0f; // public float FR = 0f; // public float Ep1 = 0f; // public float Ep2 = 0f; // public float Eq1 = 0f; // public float Eq2 = 0f; // */ // InsertHis(); // } // private bool UpdateCurr() // { // /* // public float Ua = 0f; // public float Ub = 0f; // public float Uc = 0f; // public float Uab = 0f; // public float Ubc = 0f; // public float Uca = 0f; // public float Ia = 0f; // public float Ib = 0f; // public float Ic = 0f; // public float Pa = 0f; // public float Pb = 0f; // public float Pc = 0f; // public float P = 0f; // public float Qa = 0f; // public float Qb = 0f; // public float Qc = 0f; // public float Q = 0f; // public float Sa = 0f; // public float Sb = 0f; // public float Sc = 0f; // public float S = 0f; // public float PFa = 0f; // public float PFb = 0f; // public float PFc = 0f; // public float PF = 0f; // public float FR = 0f; // public float Ep1 = 0f; // public float Ep2 = 0f; // public float Eq1 = 0f; // public float Eq2 = 0f; // */ // var sqlParameter = new SqlParameter[] { // new SqlParameter("@StationName", opName), // new SqlParameter("@SlaveAddr", ip), // new SqlParameter("@Ua", Ua), // new SqlParameter("@Ub", Ub), // new SqlParameter("@Uc", Uc), // new SqlParameter("@Uab", Ua), // new SqlParameter("@Ubc", Ub), // new SqlParameter("@Uca", Uc), // new SqlParameter("@Ia", Ia), // new SqlParameter("@Ib", Ib), // new SqlParameter("@Ic", Ic), // new SqlParameter("@Pa", Pa), // new SqlParameter("@Pb", Pb), // new SqlParameter("@Pc", Pc), // new SqlParameter("@P", Pa), // new SqlParameter("@Qa", Qa), // new SqlParameter("@Qb", Qb), // new SqlParameter("@Qc", Qc), // new SqlParameter("@Q", Q), // new SqlParameter("@Sa", Sa), // new SqlParameter("@Sb", Sb), // new SqlParameter("@Sc", Sc), // new SqlParameter("@S", S), // new SqlParameter("@PFa", PFa), // new SqlParameter("@PFb", PFb), // new SqlParameter("@PFc", PFc), // new SqlParameter("@PF", PF), // new SqlParameter("@FR", FR), // new SqlParameter("@Ep1", Ep1), // new SqlParameter("@Ep2", Ep2), // new SqlParameter("@Eq1", Eq1), // new SqlParameter("@Eq2", Eq2) // }; // return DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("Event_Meter_Update",MesWorkForm.ConnectionString, ref sqlParameter, out string errorMessage); // } // private bool InsertHis() // { // /* // public float Ua = 0f; // public float Ub = 0f; // public float Uc = 0f; // public float Uab = 0f; // public float Ubc = 0f; // public float Uca = 0f; // public float Ia = 0f; // public float Ib = 0f; // public float Ic = 0f; // public float Pa = 0f; // public float Pb = 0f; // public float Pc = 0f; // public float P = 0f; // public float Qa = 0f; // public float Qb = 0f; // public float Qc = 0f; // public float Q = 0f; // public float Sa = 0f; // public float Sb = 0f; // public float Sc = 0f; // public float S = 0f; // public float PFa = 0f; // public float PFb = 0f; // public float PFc = 0f; // public float PF = 0f; // public float FR = 0f; // public float Ep1 = 0f; // public float Ep2 = 0f; // public float Eq1 = 0f; // public float Eq2 = 0f; // */ // var sqlParameter = new SqlParameter[] { // new SqlParameter("@StationName", opName), // new SqlParameter("@SlaveAddr", ip), // new SqlParameter("@Ua", Ua), // new SqlParameter("@Ub", Ub), // new SqlParameter("@Uc", Uc), // new SqlParameter("@Uab", Ua), // new SqlParameter("@Ubc", Ub), // new SqlParameter("@Uca", Uc), // new SqlParameter("@Ia", Ia), // new SqlParameter("@Ib", Ib), // new SqlParameter("@Ic", Ic), // new SqlParameter("@Pa", Pa), // new SqlParameter("@Pb", Pb), // new SqlParameter("@Pc", Pc), // new SqlParameter("@P", Pa), // new SqlParameter("@Qa", Qa), // new SqlParameter("@Qb", Qb), // new SqlParameter("@Qc", Qc), // new SqlParameter("@Q", Q), // new SqlParameter("@Sa", Sa), // new SqlParameter("@Sb", Sb), // new SqlParameter("@Sc", Sc), // new SqlParameter("@S", S), // new SqlParameter("@PFa", PFa), // new SqlParameter("@PFb", PFb), // new SqlParameter("@PFc", PFc), // new SqlParameter("@PF", PF), // new SqlParameter("@FR", FR), // new SqlParameter("@Ep1", Ep1), // new SqlParameter("@Ep2", Ep2), // new SqlParameter("@Eq1", Eq1), // new SqlParameter("@Eq2", Eq2) // }; // return DataLinkMesWork.SQLCommon.ExecuteStoredProcedure("Event_Meter_Insert", MesWorkForm.ConnectionString, ref sqlParameter, out string errorMessage); // } // } //}