initial commit

This commit is contained in:
Arin(asus)
2024-11-26 20:15:16 +09:00
commit 973524ee77
435 changed files with 103766 additions and 0 deletions

View File

@@ -0,0 +1,175 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using COMM;
using AR;
namespace vmsnet
{
public partial class FMain
{
/// <summary>
/// 연결된 개체의 데이터를 수집합니다.
/// </summary>
void RUN_GETDATA()
{
var DAQS = PUB.DAQ.Where(t => t.isOn).ToList();
DateTime stiem = DateTime.Now;
var activecnt = 0;
var TotalRecvDatas = new List<NotifyData>();
foreach (GM10 m in DAQS)
{
if (m.isOn == false) continue;
if (PUB.CONFIG.synctime && m.opt_synctime == false)
{
PUB.workmsg("Sync DateTime");
PUB.StatusMSG("장치의 시간동기화");
if (!m.SyncDate())
{
PUB.log.AddE($"Device({m.title})의 시간동기화가 실패하였습니다.");
}
/* 작성자: 김치균, 작성일: 2024-10-11, 작성내용: 실패하더라도 1회만 동작 */
m.opt_synctime = true;
/*****************************************************************/
PUB.workmsg("");
}
else if (PUB.CONFIG.lsb && m.opt_lsb == false)
{
PUB.workmsg("Set : Binary Output LSB");
bool Rlt = m.SetBinaryLSB();
if (Rlt == false)
{
PUB.log.AddE($"Device({m.title})의 Binary Output Mode : LSB 설정 실패");
}
/* 작성자: 김치균, 작성일: 2024-10-11, 작성내용: 실패하더라도 1회만 동작 */
m.opt_lsb = true;
/*****************************************************************/
PUB.workmsg("");
}
else ////켜져잇다면
{
// PingMsg += " | CONN," + m.IP;
activecnt++;
UpdateConnectionDisplayLabel(m.idx, ConnState.Connected);
if (m.Disable)
{
PUB.RaiseRemoteCommandEvent(rCommand.EnableUIItems, m.idx);
m.Disable = false; ////켜졌다면 아이콘을 껏다는것을 취소한다. 이후 종료되었을때 다시 disable되도록
}
PUB.StatusMSG($"DAQ 데이터수집 중");
var RecvDatas = new List<NotifyData>();
var recv1 = PUB.GetMeasureData(m, PUB.CONFIG.meas_pri1, PUB.CONFIG.meas_pri2);
if (recv1.Any() == false)
{
////통신오류 혹은 데이터의 오류
UpdateConnectionDisplayLabel(m.idx, ConnState.Disconnected);
m.Disconnect();
m.Disable = false;
}
else
{
RecvDatas.AddRange(recv1);
//PUB.RaiseRemoteCommandEvent(rCommand.ValueUpdate, recv1);
//CONFIG.meas_2nd1 = 101~160
if (PUB.CONFIG.seconddata && (PUB.CONFIG.meas_sec1 > 0 && PUB.CONFIG.meas_sec2 > 0))
{
var recv2 = PUB.GetMeasureData(m, PUB.CONFIG.meas_sec1, PUB.CONFIG.meas_sec2);
if (recv2.Any() == true) RecvDatas.AddRange(recv2);
}
//CONFIG.meas_3rd1 = 201~260
if (PUB.CONFIG.thirddata && (PUB.CONFIG.meas_3rd1 > 0 && PUB.CONFIG.meas_3rd2 > 0))
{
var recv3 = PUB.GetMeasureData(m, PUB.CONFIG.meas_3rd1, PUB.CONFIG.meas_3rd2);
if (recv3.Any() == true) RecvDatas.AddRange(recv3);
}
//CONFIG.meas_4th1 = 301~360
if (PUB.CONFIG.getdata4 && (PUB.CONFIG.meas_4th1 > 0 && PUB.CONFIG.meas_4th2 > 0))
{
var recv4 = PUB.GetMeasureData(m, PUB.CONFIG.meas_4th1, PUB.CONFIG.meas_4th2);
if (recv4.Any() == true) RecvDatas.AddRange(recv4);
}
//update display control
if (RecvDatas.Any())
{
PUB.RaiseRemoteCommandEvent(rCommand.ValueUpdate, RecvDatas);
TotalRecvDatas.AddRange(RecvDatas);
}
}
}
}
////모든데이터를 DB에저장한다.
if (TotalRecvDatas.Any() && PUB.sm.Step == ESMStep.RUN)
{
try
{
RUN_SAVEDATA(TotalRecvDatas);
if (System.Diagnostics.Debugger.IsAttached) Console.WriteLine("save ok");
}
catch (Exception ex)
{
PUB.log.Add(AR.Log.ETYPE.ERROR, "Save Error" + ex.Message.ToString());
}
}
if (PUB.sleepoffset > 0)
{
System.Threading.Thread.Sleep(PUB.sleepoffset);
}
var TSLoop = DateTime.Now - stiem;
refreshinterval = (int)(TSLoop.TotalMilliseconds); //;// (tspan.Minutes * 60 * 1000) + (tspan.Seconds * 1000) + tspan.Milliseconds
this.DispCtrl1.Invalidate();
if (!DispCtrl1.FullScreen)
{
// BarGraph1.Refresh()
//'//트렌드뷰 초기화
//Dim Grp As DispCtrl.CGROUP = Me.DispCtrl1.GROUPS(DispCtrl1.ShowIndex)
//For Each item As DispCtrl.CITEM In Grp.Items
// TrendCtrlII1.CHInfo(item.idx - 1).Value.Add(item.value2)
//Next
//TrendCtrlII1.Time.Add(New TrendCtrlII.CTimeinfo(TrendCtrlII1.Time.Count, Now.ToFileTime))
//'TrendCtrlII1.Style.X2 = Now.ToFileTime
//TrendCtrlII1.Set_Refresh()
//TrendCtrlII1.Refresh()
}
var offsetvalue = (refreshinterval - PUB.CONFIG.threadlimit);
if(Math.Abs(offsetvalue) > 3)
{
if (offsetvalue < 0) //지연시간을 더 줘야 한다
{
if (offsetvalue < -50) PUB.sleepoffset += -offsetvalue; //50미만에서는 보정값 그대로 사용
else if (offsetvalue < -20) PUB.sleepoffset += 10; //50미만에서는 보정값 그대로 사용
else PUB.sleepoffset += 5; //50을 초과한 경우에는 10씩 조정되도록 한다
}
else
{
//너무 많이 지연되었다. 속도를 줄여야 한다
if (offsetvalue > 50) PUB.sleepoffset += -offsetvalue; //50미만에서는 보정값 그대로 사용
else if (offsetvalue > 20) PUB.sleepoffset -= 10;
else PUB.sleepoffset -= 5; //50을 초과한 경우에는 10씩 조정되도록 한다
}
}
}
}
}

View File

@@ -0,0 +1,307 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using COMM;
using AR;
using OpenTK.Graphics.ES11;
namespace vmsnet
{
public partial class FMain
{
DateTime lasterrortime = DateTime.Now.AddDays(-10);
DateTime lastsavetime = DateTime.Now.AddDays(-10); // VBConversions Note: Initial value cannot be assigned here since it is non-static. Assignment has been moved to the class constructors.
System.Text.StringBuilder SaveError;
int SaveCount = 0;
int SaveErrCount = 0;
/// <summary>
/// 데이터베이스에 자료를 저장한다.
/// </summary>
/// <remarks></remarks>
public void RUN_SAVEDATA(List<NotifyData> items)
{
//항목이 없다면 처리하지 않음
if (items.Any() == false) return;
var sorteditems = items.Where(t => t.use == true).OrderBy(t => t.chno).ToList();
if (sorteditems.Any() == false) return;
//시작 후 최소 몇 초동안은 저장하지 않는다(환경설정추가)
TimeSpan ts = DateTime.Now - PUB.StartupTime;
if (ts.TotalSeconds < PUB.CONFIG.Startup_DelayTime_Save) return;
SaveError = new System.Text.StringBuilder();
if (DateTime.Now.Minute % 30 == 0 && DateTime.Now.Second == 10) ////30분단위로 수행한다.
{
////구데이터삭제기능수행
PUB.CheckFreeSpace();
}
////첫번째데이터으 시간정보를 이용한다.
bool SaveOn = true;
int Time = -1; ////데이터저장시간(일기준TIck))
DateTime TimeDate = DateTime.Now;// default(DateTime); ////데이터저장시간(날짜)
string timestr = "";
bool[] USE = new bool[10];
bool[] ISNULLDATA = new bool[10];
System.Text.StringBuilder[] Buffer = new System.Text.StringBuilder[10];
for (int i = 0; i < USE.Length; i++)
{
USE[i] = false;
ISNULLDATA[i] = true;
Buffer[i] = new System.Text.StringBuilder();
}
//제공된 배열의 데이터를 추가한다.
foreach (var I in sorteditems)
{
////필수정보가 없는경우라면 넘어간다.
if (I.idx_c == -1 || I.idx_u == -1 || I.idx_m == -1) continue;
////처음저장데이터라면 패스한다.
if (PUB.ChfirstSave[I.idx_m, I.idx_u, I.idx_c] == false)
{
PUB.ChfirstSave[I.idx_m, I.idx_u, I.idx_c] = true;
continue;
}
//버퍼용인덱스계산 (인덱스값을가지고 버퍼를 찾는다. 버퍼는 160개가 최대이다)
var ValueIdx = PUB.ConvertChIndexToBufferIndex(I.chno);
//최초의 시간정보이다.
if (Time == -1)
{
timestr = sorteditems.First().time; // PUB.Times[I.idx_dev, I.idx_unit, I.idx_ch].Trim();
if (string.IsNullOrEmpty(timestr))
{
//빈데이터를 생성한다. 240729
Buffer[ValueIdx].Append("\t" + "");
continue;
}
TimeDate = DateTime.Parse(timestr);
Time = (int)(PUB.get_TimeNumber(TimeDate)); // dt.Day * 3600 * 24 + dt.Hour * 3600 + dt.Minute * 60 + dt.Second
}
////최종저장시간이랑 다르면 저장한다.
if (lastsavetime == TimeDate)
{
SaveOn = false;
}
else
{
var LastSaveTerm = TimeDate - lastsavetime;
if (LastSaveTerm.TotalSeconds < PUB.CONFIG.saveterm) ////저장주기확인
{
SaveOn = false;
}
}
////실제데이터를 저장한다. decpos*1000 + idx , value 각각 2byte 씩 총 4byte * 셀카운트
if (SaveOn)
{
float V = (float)((I.value / Math.Pow(10, I.decpos)) + I.offset);
////파라미터추가
USE[ValueIdx] = true;
if (ISNULLDATA[ValueIdx] && V != 0) ISNULLDATA[ValueIdx] = false;
Buffer[ValueIdx].Append("\t" + V.ToString());
}
}
////메인그룹 데이터 저장
//if (PUB.MainGroup != null && PUB.MainGroup.Any())
//{
// foreach (var G in PUB.MainGroup)
// {
// foreach (var I in G.Items)
// {
// ////필수정보가 없는경우라면 넘어간다.
// if (I.idx_ch == -1 || I.idx_dev == -1 || I.idx_unit == -1 || I.Onset == false || I.사용 == false)
// {
// continue;
// }
// ////처음저장데이터라면 패스한다.
// if (I.firstsave)
// {
// I.firstsave = false;
// continue;
// }
// //버퍼용인덱스계산 (인덱스값을가지고 버퍼를 찾는다. 버퍼는 160개가 최대이다)
// var ValueIdx = PUB.ConvertChIndexToBufferIndex(I.idx);
// if (Time == -1) ////최초의 시간정보이다.
// {
// timestr = PUB.Times[I.idx_dev, I.idx_unit, I.idx_ch].Trim();
// if (string.IsNullOrEmpty(timestr))
// {
// //빈데이터를 생성한다. 240729
// Buffer[ValueIdx].Append("\t" + "");
// continue;
// }
// TimeDate = DateTime.Parse(timestr);
// Time = (int)(PUB.get_TimeNumber(TimeDate)); // dt.Day * 3600 * 24 + dt.Hour * 3600 + dt.Minute * 60 + dt.Second
// }
// ////최종저장시간이랑 다르면 저장한다.
// if (lastsavetime == TimeDate)
// {
// SaveOn = false;
// }
// else
// {
// var LastSaveTerm = TimeDate - lastsavetime;
// if (LastSaveTerm.TotalSeconds < PUB.CONFIG.saveterm) ////저장주기확인
// {
// SaveOn = false;
// }
// }
// ////실제데이터를 저장한다. decpos*1000 + idx , value 각각 2byte 씩 총 4byte * 셀카운트
// if (SaveOn)
// {
// float V = (float)(I.value2 / Math.Pow(10, I.decpos));
// ////파라미터추가
// USE[ValueIdx] = true;
// if (ISNULLDATA[ValueIdx] && V != 0) ISNULLDATA[ValueIdx] = false;
// Buffer[ValueIdx].Append("\t" + V.ToString());
// }
// }
// }
//}
////보조그룹 데이터 저장
//if (PUB.SubGroup != null && PUB.SubGroup.Any()) ////subwindow가 켜졌다면 서브윈도우도 변경한다.
//{
// foreach (HMI.CGROUP G in PUB.SubGroup)
// {
// foreach (HMI.CITEM I in G.Items)
// {
// if (I.idx_ch == -1 || I.idx_dev == -1 || I.idx_unit == -1 || I.Onset == false || I.사용 == false) continue;
// if (I.firstsave)
// {
// I.firstsave = false; ////처음저장데이터라면 패스한다.
// continue;
// }
// if (Time == -1) ////최초의 시간정보이다.
// {
// timestr = PUB.Times[I.idx_dev, I.idx_unit, I.idx_ch].Trim();
// if (timestr.isEmpty()) continue;
// TimeDate = DateTime.Parse(timestr);
// Time = (int)(PUB.get_TimeNumber(TimeDate));
// }
// ////최종저장시간이랑 다르면 저장한다.
// if (lastsavetime == TimeDate) SaveOn = false;
// ////실제데이터를 저장한다. decpos*1000 + idx , value 각각 2byte 씩 총 4byte * 셀카운트
// if (SaveOn)
// {
// float V = (float)(I.value2 / Math.Pow(10, I.decpos));
// //버퍼용인덱스계산 (인덱스값을가지고 버퍼를 찾는다. 버퍼는 160개가 최대이다)
// var ValueIdx = PUB.ConvertChIndexToBufferIndex(I.idx);
// ////파라미터추가
// USE[ValueIdx] = true;
// if (ISNULLDATA[ValueIdx] && V != 0) ISNULLDATA[ValueIdx] = false;
// Buffer[ValueIdx].Append("\t" + V.ToString());
// }
// }
// }
//}
////최종저장시간을 저장한다.
var useCnt = USE.Where(t => t == true).Count();
if (useCnt > 0 && SaveOn && (TimeDate.Year > 2000) && (TimeDate.Year < 2050))
{
SaveErrCount = 0;
SaveCount = 0;
for (int i = 0; i < USE.Length; i++)
{
//데이터가있다면 저장한다.
if (USE[i] && ISNULLDATA[i] == false)
{
try
{
PUB.DB.InsertData(TimeDate, $"DATAB{i + 1}", Buffer[i]);
SaveCount++;
}
catch (Exception ex)
{
SaveErrCount++;
SaveError.AppendLine($"{i + 1}:" + ex.ToString());
}
}
}
////ka정보를 그룹별로 저장한다. 150310
System.Text.StringBuilder KaBuffer = new System.Text.StringBuilder();
System.Text.StringBuilder KaHeader = new System.Text.StringBuilder();
KaHeader.Append("\t" + "Time");
if (PUB.MainGroup != null && PUB.MainGroup.Any())
{
foreach (HMI.CGROUP G in PUB.MainGroup)
{
KaHeader.Append("\t" + G.);
KaBuffer.Append("\t" + G._amp.ToString());
}
}
if (PUB.SubGroup != null && PUB.SubGroup.Any())
{
foreach (HMI.CGROUP G in PUB.SubGroup)
{
KaHeader.Append("\t" + G.);
KaBuffer.Append("\t" + G._amp.ToString());
}
}
KaHeader.Append("\r\n");
PUB.KADB.InsertData(TimeDate, KaBuffer.ToString(), KaHeader);
if (SaveErrCount == 0)
{
lastsavetime = TimeDate; ////최종저장시간
//this.lb_Saved.Text = "<LastSaved(" + System.Convert.ToString(savcnt) + "):" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ">";
}
else
{
lasterrortime = DateTime.Now;
PUB.log.Add(AR.Log.ETYPE.ERROR, "Save Error Message=" + SaveError.ToString());
//this.lb_Saved.Text = "<Save Error-" + System.Convert.ToString(errcnt) + ">";
}
}
else { }
//log.Add(AR.Log.ETYPE.NORMAL, "No Save : " & SaveOn.ToString() & ", year = " + Year.ToString() & ", month=" & Month.ToString)
}
}
}