Changed LaserStatus string arrays to string
This commit is contained in:
@@ -36,7 +36,12 @@
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Laser\LaserWebPanel.cs" />
|
||||
<Compile Include="Laser\CNCMode.cs" />
|
||||
<Compile Include="Laser\CNCRunStatus.cs" />
|
||||
<Compile Include="Laser\HighVoltage.cs" />
|
||||
<Compile Include="Laser\LaserMains.cs" />
|
||||
<Compile Include="Laser\LaserStatus.cs" />
|
||||
<Compile Include="Laser\LaserWebClient.cs" />
|
||||
<Compile Include="Laser\ProductLog.cs" />
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="PressBrake\LogDataParser.cs" />
|
||||
|
||||
@@ -159,5 +159,13 @@ namespace CincyLib
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
public static DateTime RoundDown(this DateTime dt, TimeSpan d)
|
||||
{
|
||||
var modTicks = dt.Ticks % d.Ticks;
|
||||
var delta = -modTicks;
|
||||
|
||||
return new DateTime(dt.Ticks + delta, dt.Kind);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
9
CincyLib/Laser/CNCMode.cs
Normal file
9
CincyLib/Laser/CNCMode.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace CincyLib.Laser
|
||||
{
|
||||
public enum CNCMode
|
||||
{
|
||||
Auto,
|
||||
Jog,
|
||||
Home
|
||||
}
|
||||
}
|
||||
16
CincyLib/Laser/CNCRunStatus.cs
Normal file
16
CincyLib/Laser/CNCRunStatus.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace CincyLib.Laser
|
||||
{
|
||||
public enum CNCRunStatus
|
||||
{
|
||||
[Description("No Program Loaded")]
|
||||
NoProgramLoaded,
|
||||
Stopped,
|
||||
[Description("Ready To Run")]
|
||||
ReadyToRun,
|
||||
Running,
|
||||
Finished,
|
||||
Unknown
|
||||
}
|
||||
}
|
||||
9
CincyLib/Laser/HighVoltage.cs
Normal file
9
CincyLib/Laser/HighVoltage.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace CincyLib.Laser
|
||||
{
|
||||
public enum HighVoltage
|
||||
{
|
||||
Locked,
|
||||
Off,
|
||||
On
|
||||
}
|
||||
}
|
||||
9
CincyLib/Laser/LaserMains.cs
Normal file
9
CincyLib/Laser/LaserMains.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace CincyLib.Laser
|
||||
{
|
||||
public enum LaserMains
|
||||
{
|
||||
Locked,
|
||||
Off,
|
||||
On
|
||||
}
|
||||
}
|
||||
57
CincyLib/Laser/LaserStatus.cs
Normal file
57
CincyLib/Laser/LaserStatus.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
|
||||
namespace CincyLib.Laser
|
||||
{
|
||||
public class LaserStatus
|
||||
{
|
||||
public DateTime DateTimeUTC { get; internal set; }
|
||||
|
||||
public string Program { get; internal set; }
|
||||
|
||||
public CNCMode CNCMode { get; internal set; }
|
||||
|
||||
public CNCRunStatus RunStatus { get; internal set; }
|
||||
|
||||
public LaserMains LaserMains { get; internal set; }
|
||||
|
||||
public HighVoltage HighVoltage { get; internal set; }
|
||||
|
||||
public string SystemAlarms { get; internal set; }
|
||||
|
||||
public string LaserAlarms { get; internal set; }
|
||||
|
||||
public string FYIMessages { get; internal set; }
|
||||
|
||||
public bool IsDifferentThan(LaserStatus laserStatus)
|
||||
{
|
||||
if (laserStatus == null)
|
||||
return true;
|
||||
|
||||
if (Program != laserStatus.Program)
|
||||
return true;
|
||||
|
||||
if (CNCMode != laserStatus.CNCMode)
|
||||
return true;
|
||||
|
||||
if (RunStatus != laserStatus.RunStatus)
|
||||
return true;
|
||||
|
||||
if (LaserMains != laserStatus.LaserMains)
|
||||
return true;
|
||||
|
||||
if (HighVoltage != laserStatus.HighVoltage)
|
||||
return true;
|
||||
|
||||
if (SystemAlarms != laserStatus.SystemAlarms)
|
||||
return true;
|
||||
|
||||
if (LaserAlarms != laserStatus.LaserAlarms)
|
||||
return true;
|
||||
|
||||
if (FYIMessages != laserStatus.FYIMessages)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
@@ -7,162 +6,16 @@ using System.Xml;
|
||||
|
||||
namespace CincyLib.Laser
|
||||
{
|
||||
public class LaserWebPanel
|
||||
public class LaserWebClient
|
||||
{
|
||||
public string CurrentProgram { get; set; }
|
||||
public readonly WebClient WebClient;
|
||||
|
||||
public CNCMode CurrentMode { get; set; }
|
||||
|
||||
public CNCRunStatus CurrentStatus { get; set; }
|
||||
|
||||
public LaserMains LaserMains { get; set; }
|
||||
|
||||
public HighVoltage HighVoltage { get; set; }
|
||||
|
||||
public string[] SystemAlarms { get; set; }
|
||||
|
||||
public string[] LaserAlarms { get; set; }
|
||||
|
||||
public string[] FYIMessages { get; set; }
|
||||
|
||||
public bool Update(Stream stream)
|
||||
private void ApplyCorrections(LaserStatus status)
|
||||
{
|
||||
try
|
||||
if (status.FYIMessages.ToLower().Contains("laser high voltage is off"))
|
||||
{
|
||||
var reader = new LaserWebPanelReader(this);
|
||||
return reader.Read(stream);
|
||||
status.HighVoltage = HighVoltage.Off;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Update(Uri uri)
|
||||
{
|
||||
try
|
||||
{
|
||||
var reader = new LaserWebPanelReader(this);
|
||||
return reader.Read(uri);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Update(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
var reader = new LaserWebPanelReader(this);
|
||||
return reader.Read(new Uri(url));
|
||||
}
|
||||
catch { }
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal class LaserWebPanelReader
|
||||
{
|
||||
public readonly LaserWebPanel LaserWebPanel;
|
||||
|
||||
public LaserWebPanelReader()
|
||||
{
|
||||
LaserWebPanel = new LaserWebPanel();
|
||||
}
|
||||
|
||||
public LaserWebPanelReader(LaserWebPanel lwp)
|
||||
{
|
||||
LaserWebPanel = lwp;
|
||||
}
|
||||
|
||||
public bool Read(Stream stream)
|
||||
{
|
||||
try
|
||||
{
|
||||
var reader = new StreamReader(stream);
|
||||
var responseString = reader.ReadToEnd();
|
||||
reader.Close();
|
||||
|
||||
var doc = new XmlDocument();
|
||||
doc.LoadXml(responseString);
|
||||
|
||||
LaserWebPanel.CurrentProgram = doc.DocumentElement.SelectSingleNode("/Refresh/ProgramName").InnerText;
|
||||
LaserWebPanel.SystemAlarms = doc.DocumentElement.SelectSingleNode("/Refresh/SystemAlarms").InnerText.Replace("\r", "").Split('\n');
|
||||
LaserWebPanel.LaserAlarms = doc.DocumentElement.SelectSingleNode("/Refresh/LaserAlarms").InnerText.Replace("\r", "").Split('\n');
|
||||
LaserWebPanel.FYIMessages = doc.DocumentElement.SelectSingleNode("/Refresh/FYIMessages").InnerText.Replace("\r", "").Split('\n');
|
||||
|
||||
int mode;
|
||||
var cncModeString = doc.DocumentElement.SelectSingleNode("/Refresh/CNCMode").InnerText;
|
||||
|
||||
if (int.TryParse(cncModeString, out mode))
|
||||
LaserWebPanel.CurrentMode = GetCNCMode(mode);
|
||||
|
||||
int status;
|
||||
var cncRunStatusString = doc.DocumentElement.SelectSingleNode("/Refresh/CNCRunStatus").InnerText;
|
||||
|
||||
if (int.TryParse(cncRunStatusString, out status))
|
||||
LaserWebPanel.CurrentStatus = GetCNCRunStatus(status);
|
||||
|
||||
int mains;
|
||||
var laserMainsString = doc.DocumentElement.SelectSingleNode("/Refresh/LaserMains").InnerText;
|
||||
|
||||
if (int.TryParse(laserMainsString, out mains))
|
||||
LaserWebPanel.LaserMains = GetLaserMains(mains);
|
||||
|
||||
int hv;
|
||||
var highVoltageString = doc.DocumentElement.SelectSingleNode("/Refresh/HighVoltage").InnerText;
|
||||
|
||||
if (int.TryParse(highVoltageString, out hv))
|
||||
LaserWebPanel.HighVoltage = GetHighVoltage(hv);
|
||||
|
||||
ApplyCorrections(LaserWebPanel);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
private void ApplyCorrections(LaserWebPanel lwp)
|
||||
{
|
||||
foreach (var msg in lwp.FYIMessages)
|
||||
{
|
||||
if (msg.ToLower().Contains("laser high voltage is off"))
|
||||
{
|
||||
lwp.HighVoltage = HighVoltage.Off;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Read(Uri uri)
|
||||
{
|
||||
try
|
||||
{
|
||||
var refreshUri = new Uri(uri, "refresh.aspx");
|
||||
var request = WebRequest.Create(refreshUri.ToString());
|
||||
request.Method = "POST";
|
||||
|
||||
using (var stream = request.GetRequestStream())
|
||||
{
|
||||
var postData = "<Refresh><CNCMode/><CNCRunStatus/><ProgramName/><SystemAlarms/><LaserAlarms/><FYIMessages/><LaserMains/><HighVoltage/></Refresh>";
|
||||
var byteData = Encoding.ASCII.GetBytes(postData);
|
||||
stream.Write(byteData, 0, byteData.Length);
|
||||
}
|
||||
|
||||
var response = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
return Read(response.GetResponseStream());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static CNCMode GetCNCMode(int i)
|
||||
@@ -211,38 +64,102 @@ namespace CincyLib.Laser
|
||||
default: return HighVoltage.Off;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum CNCMode
|
||||
{
|
||||
Auto,
|
||||
Jog,
|
||||
Home
|
||||
}
|
||||
private string URL = null;
|
||||
|
||||
public enum CNCRunStatus
|
||||
{
|
||||
[Description("No Program Loaded")]
|
||||
NoProgramLoaded,
|
||||
Stopped,
|
||||
[Description("Ready To Run")]
|
||||
ReadyToRun,
|
||||
Running,
|
||||
Finished,
|
||||
Unknown
|
||||
}
|
||||
public LaserStatus GetStatus(Stream stream)
|
||||
{
|
||||
try
|
||||
{
|
||||
var reader = new StreamReader(stream);
|
||||
var responseString = reader.ReadToEnd();
|
||||
reader.Close();
|
||||
|
||||
public enum LaserMains
|
||||
{
|
||||
Locked,
|
||||
Off,
|
||||
On
|
||||
}
|
||||
var status = new LaserStatus();
|
||||
status.DateTimeUTC = DateTime.UtcNow.RoundDown(TimeSpan.FromSeconds(1));
|
||||
|
||||
public enum HighVoltage
|
||||
{
|
||||
Locked,
|
||||
Off,
|
||||
On
|
||||
var doc = new XmlDocument();
|
||||
doc.LoadXml(responseString);
|
||||
|
||||
if (doc.InnerText.Contains("Access is denied"))
|
||||
return null;
|
||||
|
||||
status.Program = doc.DocumentElement.SelectSingleNode("/Refresh/ProgramName").InnerText;
|
||||
status.SystemAlarms = doc.DocumentElement.SelectSingleNode("/Refresh/SystemAlarms").InnerText;
|
||||
status.LaserAlarms = doc.DocumentElement.SelectSingleNode("/Refresh/LaserAlarms").InnerText;
|
||||
status.FYIMessages = doc.DocumentElement.SelectSingleNode("/Refresh/FYIMessages").InnerText;
|
||||
|
||||
int mode;
|
||||
var cncModeString = doc.DocumentElement.SelectSingleNode("/Refresh/CNCMode").InnerText;
|
||||
|
||||
if (int.TryParse(cncModeString, out mode))
|
||||
status.CNCMode = GetCNCMode(mode);
|
||||
|
||||
int runStatus;
|
||||
var cncRunStatusString = doc.DocumentElement.SelectSingleNode("/Refresh/CNCRunStatus").InnerText;
|
||||
|
||||
if (int.TryParse(cncRunStatusString, out runStatus))
|
||||
status.RunStatus = GetCNCRunStatus(runStatus);
|
||||
|
||||
int mains;
|
||||
var laserMainsString = doc.DocumentElement.SelectSingleNode("/Refresh/LaserMains").InnerText;
|
||||
|
||||
if (int.TryParse(laserMainsString, out mains))
|
||||
status.LaserMains = GetLaserMains(mains);
|
||||
|
||||
int hv;
|
||||
var highVoltageString = doc.DocumentElement.SelectSingleNode("/Refresh/HighVoltage").InnerText;
|
||||
|
||||
if (int.TryParse(highVoltageString, out hv))
|
||||
status.HighVoltage = GetHighVoltage(hv);
|
||||
|
||||
ApplyCorrections(status);
|
||||
|
||||
return status;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public LaserStatus GetStatus(Uri uri)
|
||||
{
|
||||
try
|
||||
{
|
||||
var refreshUri = new Uri(uri, "refresh.aspx");
|
||||
var request = WebRequest.Create(refreshUri.ToString());
|
||||
request.Method = "POST";
|
||||
|
||||
using (var stream = request.GetRequestStream())
|
||||
{
|
||||
var postData = "<Refresh><CNCMode/><CNCRunStatus/><ProgramName/><SystemAlarms/><LaserAlarms/><FYIMessages/><LaserMains/><HighVoltage/></Refresh>";
|
||||
var byteData = Encoding.ASCII.GetBytes(postData);
|
||||
stream.Write(byteData, 0, byteData.Length);
|
||||
}
|
||||
|
||||
var response = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
return GetStatus(response.GetResponseStream());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public LaserStatus GetStatus(string url)
|
||||
{
|
||||
URL = url;
|
||||
try
|
||||
{
|
||||
var uri = new Uri(url);
|
||||
return GetStatus(uri);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user