KA 합산 값을 1000 배하여 Indicator 로 전송

This commit is contained in:
shark219-hub
2024-11-28 17:31:14 +09:00
parent 1ff549ed75
commit c4319f52d0
6 changed files with 27 additions and 42 deletions

View File

@@ -65,8 +65,8 @@ namespace DigitalIndicator
dev.DataBits = 8; // 데이터 비트 dev.DataBits = 8; // 데이터 비트
dev.Parity = System.IO.Ports.Parity.None; dev.Parity = System.IO.Ports.Parity.None;
dev.StopBits = System.IO.Ports.StopBits.One; dev.StopBits = System.IO.Ports.StopBits.One;
dev.ReadTimeout = 2000; dev.ReadTimeout = 1500;
dev.WriteTimeout = 2000; dev.WriteTimeout = 1500;
try try
{ {
@@ -81,10 +81,6 @@ namespace DigitalIndicator
// Modbus 마스터 생성 // Modbus 마스터 생성
modbus = ModbusSerialMaster.CreateRtu(dev); modbus = ModbusSerialMaster.CreateRtu(dev);
} }
} }
private void timer1_Tick(object sender, EventArgs e) private void timer1_Tick(object sender, EventArgs e)

View File

@@ -37,6 +37,13 @@ namespace vmsnet
return WriteValue(buffer); return WriteValue(buffer);
} }
UInt16[] splitI32(Int32 value)
{
var hValue = (UInt16)(value >> 16);
var lValue = (UInt16)(value & 0xFFFF);
return new ushort[] { hValue, lValue };
}
public bool WriteValue(UInt16[] values) public bool WriteValue(UInt16[] values)
{ {
if (IsOpen == false) if (IsOpen == false)
@@ -49,6 +56,7 @@ namespace vmsnet
ErrorMessage = "모드버스가 초기화 되지 않았습니다"; ErrorMessage = "모드버스가 초기화 되지 않았습니다";
return false; return false;
} }
try try
{ {
master.WriteMultipleRegisters(this.SlaveID, 0, values); master.WriteMultipleRegisters(this.SlaveID, 0, values);
@@ -61,12 +69,5 @@ namespace vmsnet
} }
} }
UInt16[] splitI32(Int32 value)
{
var hValue = (UInt16)(value >> 16);
var lValue = (UInt16)(value & 0xFFFF);
return new ushort[] { hValue, lValue };
}
} }
} }

View File

@@ -1450,23 +1450,6 @@ namespace vmsnet.HMI
String Kaunit = grp._ampunit;// +grp._ampidx.ToString() + "/" + grp._ampdecpos.ToString(); String Kaunit = grp._ampunit;// +grp._ampidx.ToString() + "/" + grp._ampdecpos.ToString();
String MaxKA = grp._amp.ToString("#0.00"); String MaxKA = grp._amp.ToString("#0.00");
//Console.WriteLine($"{grp.이름} : {MaxKA} {grp._ampunit}"); //Console.WriteLine($"{grp.이름} : {MaxKA} {grp._ampunit}");
//if (grp.이름 == "EL2500E") MaxKA = "0.01";
/**************************************************************************************/
/* 작성자: 이재웅, 작성일: 2024-11-19, 작성내용: 8개 전해조의 합산 전류량[KA] Modbus 전송 부분 */
/**************************************************************************************/
//using (var client = new JdModbus("COM3", new RtuConfigure() { BaudRate = 115200 }))
//{
// client.Connect();
// ushort[] grpKA = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; // 전력량 배열 (예시)
// byte slaveaddr = 3;
// client.WriteHoldingRegisters(RelayControl.mKA, grpKA, slaveaddr);
//}
/**************************************************************************************/
Fontsize = g.MeasureString(MaxKA, FONT_KA); Fontsize = g.MeasureString(MaxKA, FONT_KA);
SizeF FontSizeu = g.MeasureString(Kaunit, FONT_KU); SizeF FontSizeu = g.MeasureString(Kaunit, FONT_KU);

View File

@@ -55,9 +55,15 @@ namespace vmsnet
//데이터를 요청하고 처리하는 코드 필요 //데이터를 요청하고 처리하는 코드 필요
RUN_GETDATA(); RUN_GETDATA();
/* 데이터형식 : PUB.Values[mc, unit, ch-1]
* 전해조A [CH2] : PUB.Values[0, 0, 2-1] : 3002
* [CH2] 실제값 : 3.002
*/
//인디케이터 디스플레이 //인디케이터 디스플레이
if (PUB.indicator.IsOpen) if (PUB.indicator.IsOpen)
{ {
var _ampdecpos = 3;
PUB.KA1_SUM = 0f; PUB.KA1_SUM = 0f;
foreach(var item in PUB.KA1_IndexList) foreach(var item in PUB.KA1_IndexList)
{ {
@@ -68,13 +74,9 @@ namespace vmsnet
try try
{ {
var _ampdecpos = 3;
PUB.KA1_SUM += (float)(PUB.Values[di1, di2, di3 - 1] / (Math.Pow(10, _ampdecpos))); PUB.KA1_SUM += (float)(PUB.Values[di1, di2, di3 - 1] / (Math.Pow(10, _ampdecpos)));
} }
catch catch { }
{
}
} }
PUB.KA2_SUM = 0f; PUB.KA2_SUM = 0f;
@@ -87,15 +89,14 @@ namespace vmsnet
try try
{ {
var _ampdecpos = 3;
PUB.KA2_SUM += (float)(PUB.Values[di1, di2, di3 - 1] / (Math.Pow(10, _ampdecpos))); PUB.KA2_SUM += (float)(PUB.Values[di1, di2, di3 - 1] / (Math.Pow(10, _ampdecpos)));
} }
catch catch { }
{
}
} }
var SUMKA = PUB.KA1_SUM + PUB.KA2_SUM;
// '9.000 × 1,000 = 9,000' 식처럼 1000 배 만든다.
var SUMKA = (PUB.KA1_SUM + PUB.KA2_SUM) * (Math.Pow(10, _ampdecpos));
// '9,000'을 전송한 후 Indicator 에서 왼쪽으로 소수점을 '3' 칸 이동시켜서 Display 하는 작업이 필요
PUB.indicator.SetKA((Int32)SUMKA); PUB.indicator.SetKA((Int32)SUMKA);
} }
return StepResult.Wait; return StepResult.Wait;

View File

@@ -1467,6 +1467,7 @@ namespace vmsnet
// //
this.BindingNavigatorPositionItem.AccessibleName = "위치"; this.BindingNavigatorPositionItem.AccessibleName = "위치";
this.BindingNavigatorPositionItem.AutoSize = false; this.BindingNavigatorPositionItem.AutoSize = false;
this.BindingNavigatorPositionItem.Font = new System.Drawing.Font("맑은 고딕", 9F);
this.BindingNavigatorPositionItem.Name = "BindingNavigatorPositionItem"; this.BindingNavigatorPositionItem.Name = "BindingNavigatorPositionItem";
this.BindingNavigatorPositionItem.Size = new System.Drawing.Size(70, 31); this.BindingNavigatorPositionItem.Size = new System.Drawing.Size(70, 31);
this.BindingNavigatorPositionItem.Text = "0"; this.BindingNavigatorPositionItem.Text = "0";
@@ -1727,6 +1728,7 @@ namespace vmsnet
// //
this.ToolStripTextBox3.AccessibleName = "위치"; this.ToolStripTextBox3.AccessibleName = "위치";
this.ToolStripTextBox3.AutoSize = false; this.ToolStripTextBox3.AutoSize = false;
this.ToolStripTextBox3.Font = new System.Drawing.Font("맑은 고딕", 9F);
this.ToolStripTextBox3.Name = "ToolStripTextBox3"; this.ToolStripTextBox3.Name = "ToolStripTextBox3";
this.ToolStripTextBox3.Size = new System.Drawing.Size(70, 31); this.ToolStripTextBox3.Size = new System.Drawing.Size(70, 31);
this.ToolStripTextBox3.Text = "0"; this.ToolStripTextBox3.Text = "0";
@@ -2247,6 +2249,7 @@ namespace vmsnet
// //
this.ToolStripTextBox2.AccessibleName = "위치"; this.ToolStripTextBox2.AccessibleName = "위치";
this.ToolStripTextBox2.AutoSize = false; this.ToolStripTextBox2.AutoSize = false;
this.ToolStripTextBox2.Font = new System.Drawing.Font("맑은 고딕", 9F);
this.ToolStripTextBox2.Name = "ToolStripTextBox2"; this.ToolStripTextBox2.Name = "ToolStripTextBox2";
this.ToolStripTextBox2.Size = new System.Drawing.Size(70, 31); this.ToolStripTextBox2.Size = new System.Drawing.Size(70, 31);
this.ToolStripTextBox2.Text = "0"; this.ToolStripTextBox2.Text = "0";
@@ -2674,6 +2677,7 @@ namespace vmsnet
// //
this.ToolStripTextBox1.AccessibleName = "위치"; this.ToolStripTextBox1.AccessibleName = "위치";
this.ToolStripTextBox1.AutoSize = false; this.ToolStripTextBox1.AutoSize = false;
this.ToolStripTextBox1.Font = new System.Drawing.Font("맑은 고딕", 9F);
this.ToolStripTextBox1.Name = "ToolStripTextBox1"; this.ToolStripTextBox1.Name = "ToolStripTextBox1";
this.ToolStripTextBox1.Size = new System.Drawing.Size(70, 31); this.ToolStripTextBox1.Size = new System.Drawing.Size(70, 31);
this.ToolStripTextBox1.Text = "0"; this.ToolStripTextBox1.Text = "0";

View File

@@ -1022,7 +1022,7 @@ namespace vmsnet
} }
private void button3_Click(object sender, EventArgs e) private void button3_Click(object sender, EventArgs e)
{ { // KA indicator 테스트
var valuebuffer = new ushort[20]; var valuebuffer = new ushort[20];
valuebuffer[0] = 100; valuebuffer[0] = 100;
for (int i = 1; i < valuebuffer.Length; i++) valuebuffer[i] = 0; for (int i = 1; i < valuebuffer.Length; i++) valuebuffer[i] = 0;