public override void TextChange() { TTime = DateTime.Now; ThreePhaseElectricMeter_Logs = MysqlMethod.Search_ThreePhaseElectricMeter_Log($"{TTime:yyyyMMdd000000}", $"{TTime:yyyyMMdd235959}", ElectricConfig.GatewayIndex, ElectricConfig.DeviceIndex); LinechartControl.DataSource = ThreePhaseElectricMeter_Logs; LinechartControl.Refresh(); var data = ElectricAbsProtocols.Single(g => g.GatewayIndex == ElectricConfig.GatewayIndex & g.DeviceIndex == ElectricConfig.DeviceIndex); if (data.ConnectFlag) { ElectricTypeEnum electricTypeEnum = (ElectricTypeEnum)data.ElectricTypeEnum; switch (electricTypeEnum) { case ElectricTypeEnum.BAW_4C: { ThreePhaseElectricMeterData threePhaseElectric = (ThreePhaseElectricMeterData)data; rsvlabelControl.Text = threePhaseElectric.rsv.ToString("F2"); stvlabelControl.Text = threePhaseElectric.stv.ToString("F2"); trvlabelControl.Text = threePhaseElectric.trv.ToString("F2"); ralabelControl.Text = threePhaseElectric.ra.ToString("F2"); salabelControl.Text = threePhaseElectric.sa.ToString("F2"); talabelControl.Text = threePhaseElectric.ta.ToString("F2"); pfelabelControl.Text = threePhaseElectric.pfe.ToString("F3"); hzlabelControl.Text = threePhaseElectric.hz.ToString("F2"); kwlabelControl.Text = threePhaseElectric.kw.ToString("F2"); kwhlabelControl.Text = threePhaseElectric.kwh.ToString("F2"); kvarlabelControl.Text = threePhaseElectric.kvar.ToString("F2"); kvarhlabelControl.Text = threePhaseElectric.kvarh.ToString("F2"); } break; } } }
protected override void AfterMyWorkStateChanged(object sender, EventArgs e) { if (myWorkState) { var ElectricConfig = MysqlMethod.Search_ElectricConfig(GatewayConfig.GatewayIndex); foreach (var item in ElectricConfig) { ElectricTypeEnum electricTypeEnum = (ElectricTypeEnum)item.ElectricTypeEnum; switch (electricTypeEnum) { case ElectricTypeEnum.BAW_4C: { BAW_4CProtocol protocol = new BAW_4CProtocol() { ID = (byte)item.DeviceID, GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ElectricTypeEnum = item.ElectricTypeEnum, LoopTypeEnum = item.LoopTypeEnum, PhaseTypeEnum = item.PhaseTypeEnum, PhaseAngleTypeEnum = item.PhaseAngleTypeEnum, MysqlMethod = MysqlMethod }; ElectricAbsProtocols.Add(protocol); } break; } } ComponentThread = new Thread(Analysis); ComponentThread.Start(); } else { if (ComponentThread != null) { ComponentThread.Abort(); } } }
protected override void AfterMyWorkStateChanged(object sender, EventArgs e) { if (myWorkState) { int Baudate = Convert.ToInt32(GatewayConfig.Rate.Split(',')[0]); int DataBits = Convert.ToInt32(GatewayConfig.Rate.Split(',')[1]); string parity = GatewayConfig.Rate.Split(',')[2]; int stopbits = Convert.ToInt32(GatewayConfig.Rate.Split(',')[3]); RS485 = new SerialPort(GatewayConfig.Location); RS485.BaudRate = Baudate; RS485.DataBits = DataBits; switch (parity) { case "N": { RS485.Parity = Parity.None; } break; case "O": { RS485.Parity = Parity.Odd; } break; case "E": { RS485.Parity = Parity.Even; } break; } RS485.StopBits = (StopBits)stopbits; var ElectricConfig = MysqlMethod.Search_ElectricConfig(GatewayConfig.GatewayIndex); foreach (var item in ElectricConfig) { ElectricTypeEnum electricTypeEnum = (ElectricTypeEnum)item.ElectricTypeEnum; switch (electricTypeEnum) { case ElectricTypeEnum.BAW_4C: { BAW_4CProtocol protocol = new BAW_4CProtocol() { ID = (byte)item.DeviceID, GatewayIndex = item.GatewayIndex, DeviceIndex = item.DeviceIndex, ElectricTypeEnum = item.ElectricTypeEnum, LoopTypeEnum = item.LoopTypeEnum, PhaseTypeEnum = item.PhaseTypeEnum, PhaseAngleTypeEnum = item.PhaseAngleTypeEnum, MysqlMethod = MysqlMethod }; ElectricAbsProtocols.Add(protocol); } break; } } ComponentThread = new Thread(Analysis); ComponentThread.Start(); } else { if (RS485.IsOpen) { RS485.Close(); } if (ComponentThread != null) { ComponentThread.Abort(); } } }