initial commit
This commit is contained in:
439
Cs_HMI/Project/PUB.cs
Normal file
439
Cs_HMI/Project/PUB.cs
Normal file
@@ -0,0 +1,439 @@
|
||||
using Microsoft.Speech.Synthesis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Media;
|
||||
using COMM;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net;
|
||||
using System.Management;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
|
||||
namespace Project
|
||||
{
|
||||
public static class PUB
|
||||
{
|
||||
//public static Device.CFlag flag;
|
||||
public static bool bShutdown = false;
|
||||
public static bool Automodeonreboot = false;
|
||||
public static bool AutRebootAlreay = false;
|
||||
public static bool DriveSpeed = false;
|
||||
|
||||
#region "Hardware"
|
||||
|
||||
/// <summary>
|
||||
/// 읽기/쓰기용이며 구동모터 와 비상정지가 연결됨(USB-ATMEGA 2560)
|
||||
/// </summary>
|
||||
public static arDev.FakePLC PLC;
|
||||
|
||||
///// <summary>
|
||||
///// 읽기전용이며 Z축 모터와 외부 버튼이 연결됨(USB-ATMEGA 2560)
|
||||
///// </summary>
|
||||
//public static Device.PLC2 plcS;
|
||||
|
||||
/// <summary>
|
||||
/// XBEE 통신(USB-TTL)
|
||||
/// </summary>
|
||||
public static Device.Xbee XBE;
|
||||
|
||||
/// <summary>
|
||||
/// 배터리 잔량 확인(COM2 : RS232C - TTL)
|
||||
/// </summary>
|
||||
// public static arDevice.BMS bms;
|
||||
|
||||
/// <summary>
|
||||
/// RFID READER (COM1 : RS232C)
|
||||
/// </summary>
|
||||
public static arDev.Narumi AGV;
|
||||
|
||||
public static arDev.BMS BMS;
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 디버그모니터용 소켓(데이터를 전송만 한다)
|
||||
/// </summary>
|
||||
public static Device.Socket sock_debug;
|
||||
|
||||
private static SpeechSynthesizer voice;
|
||||
public static MediaPlayer mplayer;
|
||||
|
||||
|
||||
public static bool CheckPassword()
|
||||
{
|
||||
var f = new Dialog.fPassword();
|
||||
if (f.ShowDialog() != System.Windows.Forms.DialogResult.OK) return false;
|
||||
var pass = f.tbInput.Text.Trim();
|
||||
var passok = DateTime.Now.ToString("ddMM");
|
||||
if (pass.Equals(passok)) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
public static void Speak(string m, Boolean force = false, bool addlog = true)
|
||||
{
|
||||
if (force == false && PUB.setting.Enable_Speak == false) return;
|
||||
if (force)
|
||||
voice.SpeakAsyncCancelAll();
|
||||
if (voice.State == SynthesizerState.Ready)
|
||||
voice.SpeakAsync(m);
|
||||
if (addlog) PUB.log.Add("SPEAK",m);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 콜을 받을 수 있는 상황인가?
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static bool IsCanCALL()
|
||||
{
|
||||
//콜가능여부도 전송한다
|
||||
if (VAR.BOOL[eVarBool.FLAG_AUTORUN] &&
|
||||
VAR.BOOL[eVarBool.FLAG_CHARGEONM] == false &&
|
||||
PUB.BMS.Current_Level > PUB.setting.ChargeEmergencyLevel &&
|
||||
PUB.sm.RunStep != StateMachine.ERunStep.GOUP &&
|
||||
VAR.BOOL[eVarBool.WAIT_COVER_DOWN] == false &&
|
||||
VAR.BOOL[eVarBool.WAIT_COVER_UP] == false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
public static CounterSetting counter;
|
||||
|
||||
/// <summary>
|
||||
/// popup message window
|
||||
/// </summary>
|
||||
public static MessageWindow popup;
|
||||
|
||||
/// <summary>
|
||||
/// database manager
|
||||
/// </summary>
|
||||
public static Manager.DatabaseManager dbm;
|
||||
|
||||
/// <summary>
|
||||
/// 설정정보
|
||||
/// </summary>
|
||||
public static CSetting setting;
|
||||
|
||||
/// <summary>
|
||||
/// 시스템로그
|
||||
/// </summary>
|
||||
public static arUtil.Log log, logagv, logplc, logbms, logcal;
|
||||
|
||||
public static Boolean bPlayMusic = false;
|
||||
|
||||
/// <summary>
|
||||
/// 사용자 인풋 감지 시간
|
||||
/// </summary>
|
||||
public static DateTime LastInputTime = DateTime.Now;
|
||||
|
||||
public static CResult Result;
|
||||
|
||||
public static string PatchVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 상태머신
|
||||
/// </summary>
|
||||
public static StateMachine sm; //상태머신분리 190529
|
||||
|
||||
public static System.IO.DirectoryInfo path;
|
||||
|
||||
|
||||
public static void initCore()
|
||||
{
|
||||
//setting
|
||||
setting = new CSetting();
|
||||
setting.Load();
|
||||
|
||||
//counter setting
|
||||
counter = new CounterSetting();
|
||||
counter.Load();
|
||||
|
||||
//log
|
||||
log = new arUtil.Log();
|
||||
logagv = new arUtil.Log();
|
||||
logplc = new arUtil.Log();
|
||||
logbms = new arUtil.Log();
|
||||
logcal = new arUtil.Log();
|
||||
|
||||
logagv.FileNameFormat = "{yyyyMMdd}_agv";
|
||||
logplc.FileNameFormat = "{yyyyMMdd}_plc";
|
||||
logbms.FileNameFormat = "{yyyyMMdd}_bms";
|
||||
logcal.FileNameFormat = "{yyyyMMdd}_cal";
|
||||
|
||||
//popupmessage
|
||||
popup = new MessageWindow();
|
||||
|
||||
Result = new CResult();
|
||||
Result.Clear();
|
||||
}
|
||||
|
||||
public static void init()
|
||||
{
|
||||
Result = new CResult();
|
||||
|
||||
//state machine
|
||||
sm = new StateMachine();
|
||||
|
||||
path = new System.IO.DirectoryInfo(Util.CurrentPath);
|
||||
|
||||
|
||||
|
||||
mplayer = new MediaPlayer
|
||||
{
|
||||
Volume = PUB.setting.musicvol / 100.0
|
||||
};
|
||||
if (PUB.setting.musicfile.isEmpty() == false)
|
||||
if (System.IO.File.Exists(PUB.setting.musicfile))
|
||||
PUB.mplayer.Open(new Uri(PUB.setting.musicfile));
|
||||
|
||||
voice = new SpeechSynthesizer();
|
||||
voice.SelectVoice("Microsoft Server Speech Text to Speech Voice (ko-KR, Heami)");
|
||||
voice.SetOutputToDefaultAudioDevice();
|
||||
|
||||
var file_version = System.IO.Path.Combine(Util.CurrentPath, "version.txt");
|
||||
if (System.IO.File.Exists(file_version))
|
||||
{
|
||||
PUB.PatchVersion = System.IO.File.ReadAllText(file_version, System.Text.Encoding.UTF8);
|
||||
}
|
||||
else PUB.PatchVersion = string.Empty;
|
||||
}
|
||||
|
||||
public static Boolean CheckManualChargeMode(bool Prompt = true )
|
||||
{
|
||||
if (VAR.BOOL[eVarBool.FLAG_CHARGEONM] == true)
|
||||
{
|
||||
string msg = "수동 충전 상태이므로 진행 할 수 없습니다";
|
||||
PUB.Speak(msg);
|
||||
if(Prompt)
|
||||
Util.MsgE(msg);
|
||||
return false;
|
||||
}
|
||||
else return true;
|
||||
}
|
||||
|
||||
public static double GetFreeSpace(string driveletter)
|
||||
{
|
||||
try
|
||||
{
|
||||
var di = new System.IO.DriveInfo(driveletter);
|
||||
var freespace = di.TotalFreeSpace;
|
||||
var totalspace = di.TotalSize;
|
||||
var freeSpaceRate = (freespace * 1.0 / totalspace) * 100.0;
|
||||
return freeSpaceRate;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 100.0;
|
||||
}
|
||||
}
|
||||
|
||||
public static double GetFreeSpace()
|
||||
{
|
||||
double retval = 100.0;
|
||||
string savePath1 = path.FullName;
|
||||
if (savePath1 != "" && System.IO.Directory.Exists(savePath1))
|
||||
{
|
||||
//이폴더를 사용
|
||||
if (savePath1.StartsWith("\\") == false)
|
||||
{
|
||||
//남은잔량을 체크한다.
|
||||
retval = GetFreeSpace(savePath1.Substring(0, 1));
|
||||
//if (freespace1 >= Pub.setting.AutoDeleteThreshold) return savePath1;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 장치에 오류가 있는지?
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Boolean HasHWError()
|
||||
{
|
||||
if (PUB.PLC.IsValid == false) return true;
|
||||
if (PUB.AGV.IsOpen == false) return true;
|
||||
if (PUB.XBE.IsOpen == false) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//public static void AddStatusSQL(StateMachine.eSMStep status, string remark, DateTime wdate)
|
||||
//{
|
||||
// VAR.TIME[eVarTime.StatusReporttime] = DateTime.Now;
|
||||
// try
|
||||
// {
|
||||
// var state = 0;
|
||||
// if (status == StateMachine.eSMStep.RUN) state = 1;
|
||||
// else if (status == StateMachine.eSMStep.ERROR || status == StateMachine.eSMStep.EMERGENCY) state = 2;
|
||||
// if (string.IsNullOrEmpty(remark)) remark = status.ToString();
|
||||
// var mcid = PUB.setting.MCID;
|
||||
// var path = System.IO.Path.Combine(Util.CurrentPath, "Status");
|
||||
// var file = System.IO.Path.Combine(path, $"{DateTime.Now.ToString("HHmmssfff")}_{status}.sql");
|
||||
// var sql = "insert into MCMonitor_Rawdata(Model,status,remark,ip,mac,time) values('{0}','{1}','{2}','{3}','{4}','{5}')";
|
||||
// sql = string.Format(sql, mcid, state, remark, IP, MAC, wdate.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
// System.IO.File.WriteAllText(file, sql, System.Text.Encoding.Default);
|
||||
|
||||
// //만들어진지 3분이 지난 파일은 삭제한다.
|
||||
// //var di = new System.IO.DirectoryInfo(path);
|
||||
// //var fi = di.GetFiles("*.sql", System.IO.SearchOption.TopDirectoryOnly).Where(t => t.LastWriteTime < DateTime.Now.AddMinutes(-3)).FirstOrDefault();
|
||||
// //if (fi != null) fi.Delete();
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// PUB.log.AddE(ex.Message);
|
||||
// }
|
||||
//}
|
||||
|
||||
public static void AddEEDB(string remark)
|
||||
{
|
||||
var step = PUB.sm.Step.ToString();
|
||||
var rtep = PUB.sm.RunStep.ToString();
|
||||
var mcid = PUB.setting.MCID;
|
||||
var path = System.IO.Path.Combine(Util.CurrentPath, "Status");
|
||||
var file = System.IO.Path.Combine(path, $"{DateTime.Now.ToString("HHmmssfff")}_{step}_{rtep}.sql");
|
||||
var wdate = DateTime.Now;
|
||||
try
|
||||
{
|
||||
var sql = "insert into AGV_History(mcid,step,runstep,remark,ip,wdate) values('{0}','{1}','{2}','{3}','{4}','{5}')";
|
||||
sql = string.Format(sql, mcid, step, rtep, remark,IP,wdate.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
System.IO.File.WriteAllText(file, sql, System.Text.Encoding.Default);
|
||||
|
||||
//만들어진지 3분이 지난 파일은 삭제한다.
|
||||
//var di = new System.IO.DirectoryInfo(path);
|
||||
//var fi = di.GetFiles("*.sql", System.IO.SearchOption.TopDirectoryOnly).Where(t => t.LastWriteTime < DateTime.Now.AddMinutes(-3)).FirstOrDefault();
|
||||
//if (fi != null) fi.Delete();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
PUB.log.AddE(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static string IP { get; set; }
|
||||
public static string MAC { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 프로그램 사용기록 추가
|
||||
/// </summary>
|
||||
/// <param name="prgmName"></param>
|
||||
/// <param name="develop"></param>
|
||||
/// <param name="prgmVersion"></param>
|
||||
public static void CheckNRegister3(string prgmName, string develop, string prgmVersion)
|
||||
{
|
||||
if (prgmName.Length > 50) prgmName = prgmName.Substring(0, 50); //길이제한
|
||||
var task = Task.Factory.StartNew(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
string ip = "";
|
||||
string mac = "";
|
||||
// string prgmName = Application.ProductName;
|
||||
|
||||
var nif = NetworkInterface.GetAllNetworkInterfaces();
|
||||
var host = Dns.GetHostEntry(Dns.GetHostName());
|
||||
string fullname = System.Net.Dns.GetHostEntry("").HostName;
|
||||
foreach (IPAddress r in host.AddressList)
|
||||
{
|
||||
string str = r.ToString();
|
||||
|
||||
if (str != "" && str.Substring(0, 3) == "10.")
|
||||
{
|
||||
ip = str;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string rtn = string.Empty;
|
||||
ObjectQuery oq = new System.Management.ObjectQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled='TRUE'");
|
||||
ManagementObjectSearcher query1 = new ManagementObjectSearcher(oq);
|
||||
foreach (ManagementObject mo in query1.Get())
|
||||
{
|
||||
string[] address = (string[])mo["IPAddress"];
|
||||
if (address[0] == ip && mo["MACAddress"] != null)
|
||||
{
|
||||
mac = mo["MACAddress"].ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ip == "" || mac == "")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SqlConnection conn = new SqlConnection("Data Source=10.131.15.18;Initial Catalog=EE;Persist Security Info=True;User ID=eeuser;Password=Amkor123!");
|
||||
conn.Open();
|
||||
string ProcName = "AddPrgmUser3";
|
||||
SqlCommand cmd = new SqlCommand(ProcName, conn)
|
||||
{
|
||||
CommandType = CommandType.StoredProcedure
|
||||
};
|
||||
|
||||
SqlParameter param = cmd.Parameters.Add("@mac", SqlDbType.NVarChar, 50);
|
||||
param.Value = mac;
|
||||
|
||||
param = cmd.Parameters.Add("@ip", SqlDbType.NVarChar, 50);
|
||||
param.Value = ip;
|
||||
|
||||
param = cmd.Parameters.Add("@pgrm", SqlDbType.NVarChar, 50);
|
||||
param.Value = prgmName;
|
||||
|
||||
param = cmd.Parameters.Add("@develop", SqlDbType.NVarChar, 50);
|
||||
param.Value = develop;
|
||||
|
||||
param = cmd.Parameters.Add("@pgver", SqlDbType.NVarChar, 50);
|
||||
param.Value = prgmVersion;
|
||||
|
||||
param = cmd.Parameters.Add("@prgmLogin", SqlDbType.VarChar, 20);
|
||||
param.Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
param = cmd.Parameters.Add("@account", SqlDbType.NVarChar, 50);
|
||||
param.Value = System.Environment.UserName;
|
||||
|
||||
param = cmd.Parameters.Add("@hostname", SqlDbType.NVarChar, 100);
|
||||
param.Value = fullname;
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
conn.Close();
|
||||
|
||||
IP = ip;
|
||||
MAC = mac;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
PUB.log.AddE(ex.Message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static void ChangeUIPopup(System.Windows.Forms.NumericUpDown valueCtl)
|
||||
{
|
||||
var value = valueCtl.Value.ToString();
|
||||
var f = AR.UTIL.InputBox("input", value);// new Dialog.fInput(value);
|
||||
if (f.Item1)
|
||||
{
|
||||
var val = decimal.Parse(f.Item2);
|
||||
if (val < valueCtl.Minimum)
|
||||
{
|
||||
Util.MsgE(string.Format("최소 입력값은 {0} 입니다.", valueCtl.Minimum));
|
||||
val = valueCtl.Minimum;
|
||||
}
|
||||
if (val > valueCtl.Maximum)
|
||||
{
|
||||
Util.MsgE(string.Format("최대 입력값은 {0} 입니다.", valueCtl.Maximum));
|
||||
val = valueCtl.Maximum;
|
||||
}
|
||||
valueCtl.Value = val;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user