855 lines
27 KiB
C#
855 lines
27 KiB
C#
using Aurora.Api;
|
|
using Aurora.Api.Devices;
|
|
using AuroraLaserScanner.Utils;
|
|
using Hermes;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.Linq;
|
|
using System.Net.NetworkInformation;
|
|
using System.Text;
|
|
//using System.Windows.Shapes;
|
|
|
|
namespace AuroraLaserScanner
|
|
{
|
|
public partial class Scanner : Device
|
|
{
|
|
Logger Log = new Logger("Scanner");
|
|
private readonly bool _isSimulBySetting;
|
|
|
|
public ScannerConfig Config { get; set; }
|
|
|
|
private ScannerObj _scannerObj { get; set; }
|
|
|
|
public Scanner(string deviceId, bool isSimul = false)
|
|
{
|
|
CommType = CommunicationType.Etc;
|
|
_isSimulBySetting = isSimul;
|
|
}
|
|
DataTable m_dataTable = new DataTable();
|
|
|
|
protected override int DoActivate(IDeviceConfig config)
|
|
{
|
|
if (IsActivated) {
|
|
return E1.OK;
|
|
}
|
|
Config = config as ScannerConfig;
|
|
IsSimul = _isSimulBySetting || Config.IsDeviceSimul;
|
|
if (IsSimul) {
|
|
_scannerObj = new ScannerSimul();
|
|
return E1.OK;
|
|
}
|
|
if (Config.Type == eRTCType.RTC5) {
|
|
_scannerObj = new ScannerRTC5();
|
|
} else if (Config.Type == eRTCType.RTC6) {
|
|
_scannerObj = new ScannerRTC6();
|
|
} else {
|
|
_scannerObj = new ScannerSimul();
|
|
}
|
|
|
|
if (_scannerObj == null) {
|
|
Log.E(string.Format("ScannerObj is Null"));
|
|
return E1.ARGUMENT;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(Config.CorrectionFile) || string.IsNullOrEmpty(Config.ProgramFile) || string.IsNullOrEmpty(Config.LaserCorrectionFile)) {
|
|
Log.E(string.Format("File Path is Empty"));
|
|
return E1.ARGUMENT;
|
|
}
|
|
|
|
if (!File.Exists(Config.CorrectionFile) || !File.Exists(Config.LaserCorrectionFile)) {
|
|
Log.E(string.Format("File is not exist"));
|
|
return E1.ARGUMENT;
|
|
}
|
|
|
|
var errorCode = _scannerObj.Initialize(Config);
|
|
if (errorCode != E1.OK) {
|
|
Log.E(string.Format($"Initialize Error : {errorCode}"));
|
|
return E1.ARGUMENT;
|
|
}
|
|
|
|
return E1.OK;
|
|
}
|
|
|
|
protected override int DoDeactivate()
|
|
{
|
|
if (!IsSimul) {
|
|
_scannerObj?.Close();
|
|
}
|
|
return E1.OK;
|
|
}
|
|
|
|
#region ScannerObj
|
|
public void SetLaserPinOut(uint pins)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetLaserPinOut(pins);
|
|
}
|
|
|
|
public void GetXYPos(out double xPos, out double yPos)
|
|
{
|
|
if (!IsActivated) {
|
|
xPos = 0;
|
|
yPos = 0;
|
|
return;
|
|
}
|
|
_scannerObj.GetXYPos(out xPos, out yPos);
|
|
}
|
|
|
|
public void GetEncoder(out double encoderX, out double encoderY, bool rotateMode = false)
|
|
{
|
|
if (!IsActivated) {
|
|
encoderX = 0;
|
|
encoderY = 0;
|
|
return;
|
|
}
|
|
_scannerObj.GetEncoder(out encoderX, out encoderY, rotateMode);
|
|
}
|
|
|
|
public uint GetMarkingInfo()
|
|
{
|
|
if (!IsActivated) {
|
|
return 0;
|
|
}
|
|
return _scannerObj.GetMarkingInfo();
|
|
}
|
|
|
|
public uint ReadStatus()
|
|
{
|
|
if (!IsActivated) {
|
|
return 0;
|
|
}
|
|
return _scannerObj.ReadStatus();
|
|
}
|
|
|
|
public uint Open()
|
|
{
|
|
if (!IsActivated) {
|
|
return 0;
|
|
}
|
|
return _scannerObj.Open();
|
|
}
|
|
|
|
public int Initialize(ScannerConfig config)
|
|
{
|
|
if (!IsActivated) {
|
|
return E1.NETWORK;
|
|
}
|
|
return _scannerObj.Initialize(config);
|
|
}
|
|
|
|
public bool GetBusyStatus()
|
|
{
|
|
if (!IsActivated) {
|
|
return false;
|
|
}
|
|
return _scannerObj.GetBusyStatus();
|
|
}
|
|
|
|
public void SetStartList(eListNo no)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetStartList(no);
|
|
}
|
|
|
|
public void SetLaserTiming(uint periodHz, double laser1PulseWidthUs, double laser2PulseWidthUs)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetLaserTiming(periodHz, laser1PulseWidthUs, laser2PulseWidthUs);
|
|
}
|
|
// List 함수
|
|
public void SetLaserPulse(uint periodHz, uint laserPulse)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetLaserPulse(periodHz, laserPulse);
|
|
}
|
|
// Control 함수
|
|
public void SetLaserPulseCtrl(uint periodHz, uint laserPulse)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetLaserPulseCtrl(periodHz, laserPulse);
|
|
}
|
|
public void SetStandby(uint periodkHz, uint laserPulseWidthUs)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetStandby(periodkHz, laserPulseWidthUs);
|
|
}
|
|
|
|
public void LaserOnList(double interval)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.LaserOnList(interval);
|
|
}
|
|
|
|
public void WriteDA(uint portNo, float value/*0~100%*/, eFunctionType type = eFunctionType.COMMAND)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.WriteDA(portNo, value, type);
|
|
}
|
|
|
|
public void SetEndList()
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetEndList();
|
|
}
|
|
|
|
public void ExecuteList(eListNo no)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.ExecuteList(no);
|
|
}
|
|
|
|
public void StopExecution()
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.StopExecution();
|
|
}
|
|
|
|
public void LaserSignalOn()
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.LaserSignalOn();
|
|
}
|
|
|
|
public void LaserSignalOff()
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.LaserSignalOff();
|
|
}
|
|
|
|
public void InitFly2D(int offsetX = 0, int offsetY = 0)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.InitFly2D(offsetX, offsetY);
|
|
}
|
|
|
|
public void SimulateEncoder(uint EncoderNo)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SimulateEncoder(EncoderNo);
|
|
}
|
|
|
|
public void SetRotateCenter(double posX, double posY, eFunctionType type = eFunctionType.COMMAND)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetRotateCenter(posX, posY, type);
|
|
}
|
|
|
|
public void SetFlyRotate(double encoderResolution)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetFlyRotate(encoderResolution);
|
|
}
|
|
|
|
public void Fly_Return(double x, double y)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.Fly_Return(x, y);
|
|
}
|
|
|
|
public void SetJumpSpeedCtrl(double speed)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetJumpSpeedCtrl(speed);
|
|
}
|
|
|
|
public void SetJumpSpeed(double speed)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetJumpSpeed(speed);
|
|
}
|
|
|
|
public void JumpAbs(double x, double y, eFunctionType type = eFunctionType.COMMAND)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.JumpAbs(x, y, type);
|
|
}
|
|
|
|
public void JumpRel(double x, double y, eFunctionType type = eFunctionType.COMMAND)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.JumpRel(x, y, type);
|
|
}
|
|
|
|
public void SelectCorrectionTable(int no)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SelectCorrectionTable(no);
|
|
}
|
|
|
|
public double GetTime()
|
|
{
|
|
if (!IsActivated) {
|
|
return 0;
|
|
}
|
|
return _scannerObj.GetTime();
|
|
}
|
|
|
|
public void SetFlyX(double encoderResolution)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetFlyX(encoderResolution);
|
|
}
|
|
|
|
public void WaitForEncoderX(double position)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.WaitForEncoderX(position);
|
|
}
|
|
|
|
public void WaitForEncoderRotateX(double angle)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.WaitForEncoderRotateX(angle);
|
|
}
|
|
|
|
public void SetScannerDelay(uint jumpDelay, uint markDelay, uint arcDelay)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetScannerDelay(jumpDelay, markDelay, arcDelay);
|
|
}
|
|
|
|
public void SetLaserPinOutList(uint pins)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetLaserPinOutList(pins);
|
|
}
|
|
|
|
public void LongDelay(uint delay)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.LongDelay(delay);
|
|
}
|
|
|
|
public void SetTrigger(uint period/*㎲*/, eRecordSignal signal1, eRecordSignal signal2, eRecordSignal signal3, eRecordSignal signal4)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetTrigger(period, signal1, signal2, signal3, signal4);
|
|
}
|
|
|
|
public void SetMarkSpeed(double speed)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetMarkSpeed(speed);
|
|
}
|
|
|
|
public void SetLaesrDelay(int laserOnDelay, uint laserOffDelay)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetLaesrDelay(laserOnDelay, laserOffDelay);
|
|
}
|
|
|
|
public void MarkAbs(double x, double y)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.MarkAbs(x, y);
|
|
}
|
|
|
|
public void StoreEncoder(uint pos)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.StoreEncoder(pos);
|
|
}
|
|
|
|
public void SaveAndRestartTimer()
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SaveAndRestartTimer();
|
|
}
|
|
|
|
public void SetWobbelDirection(int dX, int dY)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetWobbelDirection(dX, dY);
|
|
}
|
|
|
|
public void SetWobbelMode(bool wobbelEnable, double transversal, double longitudinal, double frequency, int shape)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetWobbelMode(wobbelEnable, transversal, longitudinal, frequency, shape);
|
|
}
|
|
|
|
public void SetWobbelVector(double tansversal, double longitudinal, uint period, float power)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetWobbelVector(tansversal, longitudinal, period, power);
|
|
}
|
|
|
|
public void ParaJumpAbs(double x, double y, float power)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.ParaJumpAbs(x, y, power);
|
|
}
|
|
|
|
public void ParaJumpRel(double x, double y, float power)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.ParaJumpRel(x, y, power);
|
|
}
|
|
|
|
public void SetVectorControl(uint portNo, uint value)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.SetVectorControl(portNo, value);
|
|
}
|
|
|
|
public void ParaMarkAbs(double x, double y, float power)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.ParaMarkAbs(x, y, power);
|
|
}
|
|
|
|
public void ParaMarkRel(double x, double y, float power)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.ParaMarkRel(x, y, power);
|
|
}
|
|
|
|
public void ArcAbs(double x, double y, double angle)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.ArcAbs(x, y, angle);
|
|
}
|
|
|
|
public uint GetLastError()
|
|
{
|
|
if (!IsActivated) {
|
|
return 0;
|
|
}
|
|
return _scannerObj.GetLastError();
|
|
}
|
|
|
|
#endregion
|
|
|
|
public double GetCommandPosX()
|
|
{
|
|
return _scannerObj.CommandPosX;
|
|
}
|
|
public double GetCommandPosY()
|
|
{
|
|
return _scannerObj.CommandPosY;
|
|
}
|
|
|
|
public void WaitForListTaskCompleted(int timeOut, SequenceContext context = null)
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.WaitForListTaskCompleted(timeOut, context);
|
|
}
|
|
|
|
public uint GetListSpace()
|
|
{
|
|
if (!IsActivated) {
|
|
return Config.memory1;
|
|
}
|
|
return _scannerObj.GetListSpace();
|
|
}
|
|
public void EnableLaser()
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.EnableLaser();
|
|
}
|
|
public void DisableLaser()
|
|
{
|
|
if (!IsActivated) {
|
|
return;
|
|
}
|
|
_scannerObj.DisableLaser();
|
|
}
|
|
public void SaveRecord(string str1)
|
|
{
|
|
//ILSOSConfig로 파일 경로 수정
|
|
// TODO: DataPath 지정 하여 빼내도록 함. 전체 file Path 를 만들어서 주는 형태, 시간까지 포함해서
|
|
var DefaultPath = ConfigurationManager.AppSettings.Get("DATA_PATH");
|
|
string fullPath = Path.Combine(DefaultPath, "_device", "_scanner", "Record");
|
|
string fileName = fullPath + string.Format("\\{0}_{1}.csv", str1, DateTime.Now.ToString("yyyyMMdd_HHmmss.fff"));
|
|
|
|
uint busy, pos = 0;
|
|
|
|
_scannerObj.Measurement_status(out busy, out pos);
|
|
if (pos > 1048576) {
|
|
return;
|
|
}
|
|
|
|
int[] data1 = new int[pos];
|
|
int[] data2 = new int[pos];
|
|
int[] data3 = new int[pos];
|
|
int[] data4 = new int[pos];
|
|
_scannerObj.GetWaveForm(1, pos, out data1);
|
|
_scannerObj.GetWaveForm(2, pos, out data2);
|
|
_scannerObj.GetWaveForm(3, pos, out data3);
|
|
_scannerObj.GetWaveForm(4, pos, out data4);
|
|
|
|
System.Data.DataTable dataTable = new System.Data.DataTable();
|
|
|
|
dataTable.Columns.Add(new System.Data.DataColumn("No.", typeof(int)));
|
|
dataTable.Columns.Add(new System.Data.DataColumn(Config.RecordSignalType1.ToString(), typeof(int)));
|
|
dataTable.Columns.Add(new System.Data.DataColumn(Config.RecordSignalType2.ToString(), typeof(int)));
|
|
dataTable.Columns.Add(new System.Data.DataColumn(Config.RecordSignalType3.ToString(), typeof(int)));
|
|
dataTable.Columns.Add(new System.Data.DataColumn(Config.RecordSignalType4.ToString(), typeof(int)));
|
|
|
|
for (int i = 0; i < data1.Length; i++) {
|
|
System.Data.DataRow row = dataTable.NewRow();
|
|
int iRowCount = dataTable.Rows.Count;
|
|
object[] rowArray = new object[5];
|
|
|
|
rowArray[0] = iRowCount + 1;
|
|
rowArray[1] = data1[i];
|
|
rowArray[2] = data2[i];
|
|
rowArray[3] = data3[i];
|
|
rowArray[4] = data4[i];
|
|
|
|
row.ItemArray = rowArray;
|
|
dataTable.Rows.Add(row);
|
|
}
|
|
CSVUtils.ExportToCSV(fileName, dataTable);
|
|
|
|
}
|
|
public void SaveRecord(string str1, bool isRecordLDD, List<int> MetaDataWeldCoordinateID, int iCoordinateID)
|
|
{
|
|
//ILSOSConfig로 파일 경로 수정
|
|
var DefaultPath = ConfigurationManager.AppSettings.Get("DATA_PATH");
|
|
string fullPath = Path.Combine(DefaultPath, "_device", "_scanner", "Record");
|
|
string fileName = fullPath + string.Format("\\{0}_{1}.csv", str1, DateTime.Now.ToString("yyyyMMdd_HHmmss.fff"));
|
|
|
|
uint busy, pos = 0;
|
|
int changeLaserStatus = 0, CoordinateIdindex = 0;
|
|
|
|
_scannerObj.Measurement_status(out busy, out pos);
|
|
if (pos > 1048576) {
|
|
return;
|
|
}
|
|
|
|
int[] data1 = new int[pos];
|
|
int[] data2 = new int[pos];
|
|
int[] data3 = new int[pos];
|
|
int[] data4 = new int[pos];
|
|
_scannerObj.GetWaveForm(1, pos, out data1);
|
|
_scannerObj.GetWaveForm(2, pos, out data2);
|
|
_scannerObj.GetWaveForm(3, pos, out data3);
|
|
_scannerObj.GetWaveForm(4, pos, out data4);
|
|
|
|
System.Data.DataTable dataTable = new System.Data.DataTable();
|
|
|
|
if (isRecordLDD) {
|
|
fullPath = Path.Combine(DefaultPath, "_device", "_scanner", "Record", "Coordinate");
|
|
fileName = fullPath + string.Format("\\{0}_{1}.csv", str1, DateTime.Now.ToString("yyyyMMdd_HHmmss"));
|
|
|
|
dataTable.Columns.Add(new System.Data.DataColumn("Sequence ID", typeof(int)));
|
|
dataTable.Columns.Add(new System.Data.DataColumn("Weld ID", typeof(int)));
|
|
dataTable.Columns.Add(new System.Data.DataColumn("Laser State(ON:1/OFF:0)", typeof(int)));
|
|
dataTable.Columns.Add(new System.Data.DataColumn("Transition Offset(s)", typeof(int)));
|
|
dataTable.Columns.Add(new System.Data.DataColumn("Part X(mm)", typeof(double)));
|
|
dataTable.Columns.Add(new System.Data.DataColumn("Part Y(mm)", typeof(double)));
|
|
dataTable.Columns.Add(new System.Data.DataColumn("Head X(mm)", typeof(double)));
|
|
dataTable.Columns.Add(new System.Data.DataColumn("Head Y(mm)", typeof(double)));
|
|
|
|
for (int i = 0; i < data1.Length; i++) {
|
|
if (data3[i] == 0) {
|
|
changeLaserStatus = data3[i];
|
|
continue;
|
|
} else if ((changeLaserStatus != data3[i]) && data3[i] == 1) {
|
|
changeLaserStatus = data3[i];
|
|
CoordinateIdindex++;
|
|
}
|
|
//else if (changelaserstatus != data3[i])
|
|
//{
|
|
// changelaserstatus = data3[i];
|
|
//}
|
|
|
|
System.Data.DataRow row = dataTable.NewRow();
|
|
int iRowCount = dataTable.Rows.Count;
|
|
object[] rowArray = new object[8];
|
|
|
|
//int m_sequenceID = 1;
|
|
//int m_sequenceID = MetaDataWeldCoordinateID.Count;
|
|
int m_sequenceID = iCoordinateID;
|
|
|
|
//Recipe 객체 변경될때 m_weldID 값 변경 필요
|
|
int m_weldID = MetaDataWeldCoordinateID[CoordinateIdindex - 1];
|
|
|
|
int m_transitionOffset = 0;
|
|
|
|
rowArray[0] = m_sequenceID;
|
|
rowArray[1] = m_weldID;
|
|
rowArray[2] = data3[i]; //Laser State
|
|
rowArray[3] = m_transitionOffset;
|
|
rowArray[4] = Math.Round(Convert.ToDouble(data1[i]) / Config.ScaleXYFactor, 4);
|
|
rowArray[5] = Math.Round(Convert.ToDouble(data2[i]) / Config.ScaleXYFactor, 4);
|
|
rowArray[6] = Math.Round(Convert.ToDouble(data1[i]) / Config.ScaleXYFactor, 4);
|
|
rowArray[7] = Math.Round(Convert.ToDouble(data2[i]) / Config.ScaleXYFactor, 4);
|
|
|
|
row.ItemArray = rowArray;
|
|
dataTable.Rows.Add(row);
|
|
}
|
|
|
|
CSVUtils.ExportToLDDFileCSV(fileName, dataTable);
|
|
|
|
} else {
|
|
dataTable.Columns.Add(new System.Data.DataColumn("No.", typeof(int)));
|
|
dataTable.Columns.Add(new System.Data.DataColumn(Config.RecordSignalType1.ToString(), typeof(int)));
|
|
dataTable.Columns.Add(new System.Data.DataColumn(Config.RecordSignalType2.ToString(), typeof(int)));
|
|
dataTable.Columns.Add(new System.Data.DataColumn(Config.RecordSignalType3.ToString(), typeof(int)));
|
|
dataTable.Columns.Add(new System.Data.DataColumn(Config.RecordSignalType4.ToString(), typeof(int)));
|
|
|
|
for (int i = 0; i < data1.Length; i++) {
|
|
System.Data.DataRow row = dataTable.NewRow();
|
|
int iRowCount = dataTable.Rows.Count;
|
|
object[] rowArray = new object[5];
|
|
|
|
rowArray[0] = iRowCount + 1;
|
|
rowArray[1] = data1[i];
|
|
rowArray[2] = data2[i];
|
|
rowArray[3] = data3[i];
|
|
rowArray[4] = data4[i];
|
|
|
|
row.ItemArray = rowArray;
|
|
dataTable.Rows.Add(row);
|
|
}
|
|
CSVUtils.ExportToCSV(fileName, dataTable);
|
|
}
|
|
|
|
#region RTC6 보드 Pulse Counting
|
|
//int[] laserOnArray = null;
|
|
|
|
//for (int i = 0; i < 4; i++)
|
|
//{
|
|
// if (Config.RecordSignalType1.ToString() == "LaserON")
|
|
// {
|
|
// laserOnArray = data1;
|
|
// }
|
|
// else if (Config.RecordSignalType2.ToString() == "LaserON")
|
|
// {
|
|
// laserOnArray = data2;
|
|
// }
|
|
// else if (Config.RecordSignalType3.ToString() == "LaserON")
|
|
// {
|
|
// laserOnArray = data3;
|
|
// }
|
|
// else if (Config.RecordSignalType3.ToString() == "LaserON")
|
|
// {
|
|
// laserOnArray = data4;
|
|
// }
|
|
// else
|
|
// {
|
|
// return -1;
|
|
// }
|
|
//}
|
|
|
|
//int pulseCount = 0;
|
|
|
|
//for (int i = 0; i < laserOnArray.Length - 1; i++)
|
|
//{
|
|
// if (laserOnArray[i] == 0 && laserOnArray[i + 1] == 1)
|
|
// {
|
|
// pulseCount++;
|
|
// }
|
|
//}
|
|
//Log.I(string.Format($"Record LaserON Pulse Count : {pulseCount}"));
|
|
|
|
//return pulseCount;
|
|
#endregion
|
|
}
|
|
public void InitializeRecord()
|
|
{
|
|
m_dataTable = new System.Data.DataTable();
|
|
m_dataTable.Columns.Add(new System.Data.DataColumn("No.", typeof(int)));
|
|
m_dataTable.Columns.Add(new System.Data.DataColumn(Config.RecordSignalType1.ToString(), typeof(int)));
|
|
m_dataTable.Columns.Add(new System.Data.DataColumn(Config.RecordSignalType2.ToString(), typeof(int)));
|
|
m_dataTable.Columns.Add(new System.Data.DataColumn(Config.RecordSignalType3.ToString(), typeof(int)));
|
|
m_dataTable.Columns.Add(new System.Data.DataColumn(Config.RecordSignalType4.ToString(), typeof(int)));
|
|
}
|
|
public void StackRecord()
|
|
{
|
|
uint busy, pos = 0;
|
|
|
|
_scannerObj.Measurement_status(out busy, out pos);
|
|
if (pos > 1048576)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int[] data1 = new int[pos];
|
|
int[] data2 = new int[pos];
|
|
int[] data3 = new int[pos];
|
|
int[] data4 = new int[pos];
|
|
_scannerObj.GetWaveForm(1, pos, out data1);
|
|
_scannerObj.GetWaveForm(2, pos, out data2);
|
|
_scannerObj.GetWaveForm(3, pos, out data3);
|
|
_scannerObj.GetWaveForm(4, pos, out data4);
|
|
|
|
|
|
|
|
for (int i = 0; i < data1.Length; i++)
|
|
{
|
|
System.Data.DataRow row = m_dataTable.NewRow();
|
|
int iRowCount = m_dataTable.Rows.Count;
|
|
object[] rowArray = new object[5];
|
|
|
|
rowArray[0] = iRowCount + 1;
|
|
rowArray[1] = data1[i];
|
|
rowArray[2] = data2[i];
|
|
rowArray[3] = data3[i];
|
|
rowArray[4] = data4[i];
|
|
|
|
row.ItemArray = rowArray;
|
|
m_dataTable.Rows.Add(row);
|
|
}
|
|
}
|
|
|
|
public void SaveStackRecord(string str1)
|
|
{
|
|
var DefaultPath = ConfigurationManager.AppSettings.Get("DATA_PATH");
|
|
string fullPath = Path.Combine(DefaultPath, "_device", "_scanner", "Record");
|
|
string fileName = fullPath + string.Format("\\{0}_{1}.csv", str1, DateTime.Now.ToString("yyyyMMdd_HHmmss.fff"));
|
|
|
|
CSVUtils.ExportToCSV(fileName, m_dataTable);
|
|
}
|
|
public void SaveRecordZip(string metaDataFilepath, string coordinateFilepath)
|
|
{
|
|
var DefaultPath = ConfigurationManager.AppSettings.Get("DATA_PATH");
|
|
string fullPath = Path.Combine(DefaultPath, "_device", "_scanner", "Record", "LDDFileFormat");
|
|
string lddFilepath = fullPath + string.Format("\\{0}_{1}.zip", string.Format("LDDFileFormat"), DateTime.Now.ToString("yyyyMMdd_HHmmss"));
|
|
|
|
try {
|
|
using (FileStream zipToOpen = new FileStream(lddFilepath, FileMode.Create)) {
|
|
using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Create)) {
|
|
// XML 파일 추가
|
|
AddFileToZip(archive, metaDataFilepath);
|
|
// CSV 파일 추가
|
|
AddFileToZip(archive, coordinateFilepath);
|
|
|
|
}
|
|
}
|
|
|
|
// ZIP 파일의 확장자 변경
|
|
string newZipFilePath = Path.ChangeExtension(lddFilepath, ".gpi");
|
|
File.Move(lddFilepath, newZipFilePath);
|
|
} catch (Exception ex) {
|
|
Log.E(string.Format(ex.Message));
|
|
}
|
|
|
|
}
|
|
private void AddFileToZip(ZipArchive archive, string filePath)
|
|
{
|
|
string entryName = Path.GetFileName(filePath);
|
|
ZipArchiveEntry entry = archive.CreateEntry(entryName);
|
|
|
|
using (Stream entryStream = entry.Open())
|
|
using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) {
|
|
fileStream.CopyTo(entryStream);
|
|
}
|
|
}
|
|
public string GetLatestFile(string folderPath)
|
|
{
|
|
var directoryInfo = new DirectoryInfo(folderPath);
|
|
var latestFile = directoryInfo.GetFiles()
|
|
.OrderByDescending(f => f.LastWriteTime)
|
|
.FirstOrDefault();
|
|
|
|
if (latestFile == null) {
|
|
throw new FileNotFoundException("No files found in the specified directory.");
|
|
}
|
|
|
|
return latestFile.FullName;
|
|
}
|
|
|
|
|
|
}
|
|
}
|