using CoreUnit.Common; using GUI.Properties; using System; using System.ComponentModel; using System.IO; using System.Reflection; using System.Threading; using System.Windows.Forms; using System.Xml.Serialization; namespace CoreUnit.Scanner { public abstract class ScannerUnit { public class ScannerUnitParam { public enum eListNo { LIST1, LIST2 } public enum eLaserMode { CO2, YAG1, YAG2, YAG3, LaserMode4, YAG5, LaserMode6 } public enum eLaserSignal { LASERON, LASER1, LASER2 }; public enum eWaitEncoderMode { NoUse, Range, OverStepping, UnderStepping, BothDirection } public enum eOntheFlyCoordinate { XY, Rotate } public enum eRecordSignal { LaserON = 0, StatusAX, StatusAY, SampleX = 7, SampleY, SampleZ, SampleAX_Corr, SampleAY_Corr, SampleAZ_Corr, StatusAX_LaserOn = 16, StatusAY_LaserOn, SampleAX_Out = 20, SampleAY_Out, SampleAX_Trans = 25, SampleAY_Trans, SampleAZ_Trans, AnalogOut1 = 33, AnalogOut2 = 34, Encoder0 = 43, Encoder1 = 44 } public enum eEthConfigLinkLossMode { Mode0 = 0, Mode1, Mode2, Mode3 } uint m_primaryHeadNo; uint m_secondHeadNo; uint m_ControlMode; eLaserMode m_laserMode; uint m_laserControl; uint m_firstPulseKiller; uint m_laserPeriod; uint m_laser1PulseWidth; uint m_jumpDelay; uint m_markDelay; uint m_polygonDelay; int m_laserOnDelay; uint m_laserOffDelay; uint m_markSpeed; uint m_jumpSpeed; double m_scaleXYFactor; double m_scaleZFactor; bool m_use3DMode; bool m_useEncoderFeedbackMode; string m_correctionFile; string m_laserCorrectionFile; string m_programFile; double m_scanXSize; double m_scanYSize; double m_scanZSize; bool m_useMarkingOnTheFly; double m_markingOnTheFlyEncoderResolutionX; double m_markingOnTheFlyEncoderResolutionY; double m_markingOnTheFlyEncoderResolutionRotate; eWaitEncoderMode m_markingStartWaitMode; eOntheFlyCoordinate m_ontheFlyCoordinate; double m_markingOnTheFlyRotateCenterX; double m_markingOnTheFlyRotateCenterY; double m_markingStartEncoderPositionX; double m_markingRangeMinX; double m_markingRangeMaxX; double m_markingRangeMinY; double m_markingRangeMaxY; double m_markingRangeMinRotate; double m_markingRangeMaxRotate; double m_markingOntheFlyOffsetX; double m_markingOntheFlyOffsetY; double m_markingOntheFlyParkingPositionX; double m_markingOntheFlyParkingPositionY; double m_flySpeedInterlock; double m_rotaryEncoderOffset; //int m_teachingNumOfRevolutions = 0; //double m_absoluteEncoderOffset = 0; double m_markingOntheFlyStageSpeed; double m_translationAngle; double m_translationXOffset; double m_translationYOffset; eLaserSignal m_laserSiganlPin2; eLaserSignal m_laserSiganlPin1; eLaserSignal m_laserSiganlPin9; eEthConfigLinkLossMode m_ethConfigLinkLoss; [Browsable(true)] [ReadOnly(false)] [Category("Head")] [DisplayName("Primary Scan No.")] [Description("Primary Scan Head Number")] public uint PrimaryHeadNo { set { m_primaryHeadNo = value; } get { return m_primaryHeadNo; } } [Browsable(true)] [ReadOnly(false)] [Category("Head")] [DisplayName("Secondary Scan No.")] [Description("Secondary Scan Headn Number - If no second scan head is, Input just 0 number")] public uint SecondHeadNo { set { m_secondHeadNo = value; } get { return m_secondHeadNo; } } [Browsable(true)] [ReadOnly(false)] [Category("Mode")] [DisplayName("Control Mode")] [Description("enables or disables the external control input for extern list starts, locks or unlocks the external control input for external list stops and resets the counter for external list starts to zero")] public uint ControlMode { set { m_ControlMode = value; } get { return m_ControlMode; } } [Browsable(true)] [ReadOnly(false)] [Category("Mode")] [DisplayName("Laser Mode")] [Description("Selects the laser control mode")] public eLaserMode LaserMode { set { m_laserMode = value; } get { return m_laserMode; } } [Browsable(true)] [ReadOnly(false)] [Category("Mode")] [DisplayName("Laser Control")] [Description("defines and enables or disables the laser control signals")] public uint LaserControl { set { m_laserControl = value; } get { return m_laserControl; } } [Browsable(true)] [ReadOnly(false)] [Category("Scanner Delay")] [DisplayName("Jump Delay(㎲)")] [Description("To allow for the setting time and for the lag, Jump delay is inserted")] public uint JumpDelay { set { m_jumpDelay = value; } get { return m_jumpDelay; } } [Browsable(true)] [ReadOnly(false)] [Category("Scanner Delay")] [DisplayName("Mark Delay(㎲)")] [Description("To allow for the setting time and for the lag, Mark delay is inserted")] public uint MarkDelay { set { m_markDelay = value; } get { return m_markDelay; } } [Browsable(true)] [ReadOnly(false)] [Category("Scanner Delay")] [DisplayName("Polygon Delay(㎲)")] [Description("To allow for the setting time and for the lag, Polygon delay is inserted")] public uint PolygonDelay { set { m_polygonDelay = value; } get { return m_polygonDelay; } } [Browsable(true)] [ReadOnly(false)] [Category("Laser Delay")] [DisplayName("Laser On Delay(㎲)")] [Description("When the scan board turns on the laser, laser on delay defines the moment")] public int LaserOnDelay { set { m_laserOnDelay = value; } get { return m_laserOnDelay; } } [Browsable(true)] [ReadOnly(false)] [Category("Laser Delay")] [DisplayName("Laser Off Delay(㎲)")] [Description("When the scan board turns off the laser, laser off delay defines the moment")] public uint LaserOffDelay { set { m_laserOffDelay = value; } get { return m_laserOffDelay; } } [Browsable(true)] [ReadOnly(false)] [Category("Laser Timing")] [DisplayName("Laser Period(KHz)")] [Description("defines the output period")] public uint LaserPeriod { set { m_laserPeriod = value; } get { return m_laserPeriod; } } [Browsable(true)] [ReadOnly(false)] [Category("Laser Timing")] [DisplayName("Laser Pulse(㎲)")] [Description("Pulse lengths of the laser signal LASER1 and LASER2")] public uint Laser1PulseWidth { set { m_laser1PulseWidth = value; } get { return m_laser1PulseWidth; } } [Browsable(true)] [ReadOnly(false)] [Category("Speed")] [DisplayName("Mark Speed(mm/s)")] [Description("defines the marking speed for the subsequent vector and arc commands")] public uint MarkSpeed { set { m_markSpeed = value; } get { return m_markSpeed; } } [Browsable(true)] [ReadOnly(false)] [Category("Speed")] [DisplayName("Jump Speed(mm/s)")] [Description("defines the jump speed for the following vector commands")] public uint JumpSpeed { set { m_jumpSpeed = value; } get { return m_jumpSpeed; } } [Browsable(true)] [ReadOnly(false)] [Category("Scale")] [DisplayName("XY Scale")] [Description("mm to bit unit convert scale factor")] public double ScaleXYFactor { set { m_scaleXYFactor = value; } get { return m_scaleXYFactor; } } [Browsable(true)] [ReadOnly(false)] [Category("Scale")] [DisplayName("Z Scale")] [Description("mm to bit unit convert scale factor")] public double ScaleZFactor { set { m_scaleZFactor = value; } get { return m_scaleZFactor; } } [Browsable(true)] [ReadOnly(false)] [Category("Laser Timing")] [DisplayName("First Pulse Killer(㎲)")] [Description("defines the length of the FirstPulseKiller signal for a YAG laser")] public uint FirstPulseKiller { set { m_firstPulseKiller = value; } get { return m_firstPulseKiller; } } [Browsable(true)] [ReadOnly(false)] [Category("Use Mode")] [DisplayName("Use Z axis")] [Description("defines to use Z axis")] public bool Use3DMode { set { m_use3DMode = value; } get { return m_use3DMode; } } [Browsable(true)] [ReadOnly(false)] [Category("File")] [DisplayName("Scanner Program File")] [Description("defines directory of scanner program file")] public string ProgramFile { set { m_programFile = value; } get { return m_programFile; } } [Browsable(true)] [ReadOnly(false)] [Category("File")] [DisplayName("Scanner Correction File")] [Description("defines directory of scanner correction file")] [EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))] public string CorrectionFile { set { m_correctionFile = value; } get { return m_correctionFile; } } [Browsable(true)] [ReadOnly(false)] [Category("File")] [DisplayName("Laser Correction File")] [Description("defines directory of laser correction file")] [EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))] public string LaserCorrectionFile { set { m_laserCorrectionFile = value; } get { return m_laserCorrectionFile; } } [Browsable(true)] [ReadOnly(false)] [Category("Use Mode")] [DisplayName("Use Position Feedback")] [Description("defines to use position feedback mode")] public bool UseEncoderFeedbackMode { set { m_useEncoderFeedbackMode = value; } get { return m_useEncoderFeedbackMode; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("Use MOTF Mode")] [Description("true to start marking operation in MOTF mode; otherwise, false.")] public bool UseMarkingOnTheFly { set { m_useMarkingOnTheFly = value; } get { return m_useMarkingOnTheFly; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("MOTF X-Axis Encoder Resolution[um/count]")] [Description("scaling factor for the X direction in um/count")] public double MarkingOnTheFlyEncoderResolutionX { set { m_markingOnTheFlyEncoderResolutionX = value; } get { return m_markingOnTheFlyEncoderResolutionX; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("MOTF Y-Axis Encoder Resolution[um/count]")] [Description("scaling factor for the Y direction in um/count")] public double MarkingOnTheFlyEncoderResolutionY { set { m_markingOnTheFlyEncoderResolutionY = value; } get { return m_markingOnTheFlyEncoderResolutionY; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("MOTF Rotate Encoder Resolution[Count/rev]")] [Description("scaling factor for the Rotate in Count/rev")] public double MarkingOnTheFlyEncoderResolutionRotate { set { m_markingOnTheFlyEncoderResolutionRotate = value; } get { return m_markingOnTheFlyEncoderResolutionRotate; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("MOTF Rotate Center X")] [Description("MOTF Rotate Center X")] public double MarkingOnTheFlyRotateCenterX { set { m_markingOnTheFlyRotateCenterX = value; } get { return m_markingOnTheFlyRotateCenterX; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("MOTF Rotate Center Y")] [Description("MOTF Rotate Center Y")] public double MarkingOnTheFlyRotateCenterY { set { m_markingOnTheFlyRotateCenterY = value; } get { return m_markingOnTheFlyRotateCenterY; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("Marking Start X-Axis Encoder Position[mm]")] [Description("Execution will wait until X-Axis encoder position hits this position, in mm")] public double MarkingStartEncoderPositionX { set { m_markingStartEncoderPositionX = value; } get { return m_markingStartEncoderPositionX; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("Marking Range Min X[mm]")] [Description("Marking Range Min X[mm]")] public double MarkingRangeMinX { set { m_markingRangeMinX = value; } get { return m_markingRangeMinX; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("Marking Range Max X[mm]")] [Description("Marking Range Max X[mm]")] public double MarkingRangeMaxX { set { m_markingRangeMaxX = value; } get { return m_markingRangeMaxX; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("Marking Range Min Y[mm]")] [Description("Marking Range Min Y[mm]")] public double MarkingRangeMinY { set { m_markingRangeMinY = value; } get { return m_markingRangeMinY; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("Marking Range Max Y[mm]")] [Description("Marking Range Max Y[mm]")] public double MarkingRangeMaxY { set { m_markingRangeMaxY = value; } get { return m_markingRangeMaxY; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("Marking Range Min Rotate[degree]")] [Description("Marking Range Min Rotate[degree]")] public double MarkingRangeMinRotate { set { m_markingRangeMinRotate = value; } get { return m_markingRangeMinRotate; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("Marking Range Max Rotate[degree]")] [Description("Marking Range Max Rotate[degree]")] public double MarkingRangeMaxRotate { set { m_markingRangeMaxRotate = value; } get { return m_markingRangeMaxRotate; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("MOTF Offset X(mm)")] [Description("MOTF Offset X(mm)")] public double MarkingOntheFlyOffsetX { set { m_markingOntheFlyOffsetX = value; } get { return m_markingOntheFlyOffsetX; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("MOTF Offset Y(mm)")] [Description("MOTF Offset Y(mm)")] public double MarkingOntheFlyOffsetY { set { m_markingOntheFlyOffsetY = value; } get { return m_markingOntheFlyOffsetY; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("MOTF Park Position X(mm)")] [Description("MOTF Park Position X(mm)")] public double MarkingOntheFlyParkingPositionX { set { m_markingOntheFlyParkingPositionX = value; } get { return m_markingOntheFlyParkingPositionX; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("MOTF Park Position Y(mm)")] [Description("MOTF Park Position Y(mm)")] public double MarkingOntheFlyParkingPositionY { set { m_markingOntheFlyParkingPositionY = value; } get { return m_markingOntheFlyParkingPositionY; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("Marking Start Wait Mode")] [Description("NoUse : No Use\nWait : Wait until encoder position hits specified value\nRange : position in range\nOverSide : overstepping(position independent)\nUnderSide : understepping(position independent)\nBothSide : overstepping/understepping(position dependent)")] public eWaitEncoderMode MarkingStartWaitMode { set { m_markingStartWaitMode = value; } get { return m_markingStartWaitMode; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("On The Fly Coordinate")] [Description("On The Fly Coordinate")] public eOntheFlyCoordinate OnTheFlyCoordinate { set { m_ontheFlyCoordinate = value; } get { return m_ontheFlyCoordinate; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("MOTF Speed Interlock")] [Description("MOTF Speed Interlock(XY:mm/sec, Rotary:degree/sec")] public double FlySpeedInterlock { set { m_flySpeedInterlock = value; } get { return m_flySpeedInterlock; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("MOTF Rotary Offset")] [Description("Rotary stage angle offset from absolute encoder value(-360 ~ 0)")] public double RotaryEncoderOffset { set { m_rotaryEncoderOffset = value; } get { return m_rotaryEncoderOffset; } } [Browsable(true)] [ReadOnly(false)] [Category("Marking On The Fly(MOTF)")] [DisplayName("MOTF Stage Speed(Linear/Rotary)")] [Description("Linear Track: mm/s, Rotary : deg/s (temp)")] public double MOTFStageSpeed { set { m_markingOntheFlyStageSpeed = value; } get { return m_markingOntheFlyStageSpeed; } } [Browsable(true)] [ReadOnly(false)] [Category("Scan Area Size")] [DisplayName("Scan X Axis Area Size(mm)")] [Description("defines X axis of area size")] public double ScanXSize { get { return m_scanXSize; } set { m_scanXSize = value; } } [Browsable(true)] [ReadOnly(false)] [Category("Scan Area Size")] [DisplayName("Scan Y Axis Area Size(mm)")] [Description("defines Y axis of area size")] public double ScanYSize { get { return m_scanYSize; } set { m_scanYSize = value; } } [Browsable(true)] [ReadOnly(false)] [Category("Scan Area Size")] [DisplayName("Scan Z Axis Height(mm)")] [Description("defines Z axis of area size")] public double ScanZSize { get { return m_scanZSize; } set { m_scanZSize = value; } } [Browsable(true)] [ReadOnly(false)] [Category("Scan Translation")] [DisplayName("Scan X Axis Translation Shift(mm)")] [Description("defines X axis translation shift")] public double TranslationXOffset { get { return m_translationXOffset; } set { m_translationXOffset = value; } } [Browsable(true)] [ReadOnly(false)] [Category("Scan Translation")] [DisplayName("Scan Y Axis Translation Shift(mm)")] [Description("defines Y axis translation shift")] public double TranslationYOffset { get { return m_translationYOffset; } set { m_translationYOffset = value; } } [Browsable(true)] [ReadOnly(false)] [Category("Scan Translation")] [DisplayName("Scan Angle Translation Shift(mm)")] [Description("defines Angle translation shift")] public double TranslationAngle { get { return m_translationAngle; } set { m_translationAngle = value; } } [Browsable(true)] [ReadOnly(false)] [Category("Laser Signal")] [DisplayName("Laser Signal Pin 2")] [Description("Laser Signal Pin 2 (Default : LASERON)")] [XmlSerializable] public eLaserSignal LaserSiganlPin2 { get { return m_laserSiganlPin2; } set { m_laserSiganlPin2 = value; } } [Browsable(true)] [ReadOnly(false)] [Category("Laser Signal")] [DisplayName("Laser Signal Pin 1")] [Description("Laser Signal Pin 1 (Default : LASER1)")] [XmlSerializable] public eLaserSignal LaserSiganlPin1 { get { return m_laserSiganlPin1; } set { m_laserSiganlPin1 = value; } } [Browsable(true)] [ReadOnly(false)] [Category("Laser Signal")] [DisplayName("Laser Signal Pin 9")] [Description("Laser Signal Pin 9 (Default : LASER2)")] [XmlSerializable] public eLaserSignal LaserSiganlPin9 { get { return m_laserSiganlPin9; } set { m_laserSiganlPin9 = value; } } bool m_useRecordSignal = false; [Browsable(true)] [ReadOnly(false)] [Category("Record Siganl")] [DisplayName("Use Record Signal")] [Description("Use Record Signal")] public bool UseRecordSignal { get { return m_useRecordSignal; } set { m_useRecordSignal = value; } } eRecordSignal m_recordSignalType1 = eRecordSignal.Encoder0; [Browsable(true)] [ReadOnly(false)] [Category("Record Siganl")] [DisplayName("Record Signal Type 1")] [Description("Record Signal Type 1")] public eRecordSignal RecordSignalType1 { get { return m_recordSignalType1; } set { m_recordSignalType1 = value; } } eRecordSignal m_recordSignalType2 = eRecordSignal.Encoder1; [Browsable(true)] [ReadOnly(false)] [Category("Record Siganl")] [DisplayName("Record Signal Type 2")] [Description("Record Signal Type 2")] public eRecordSignal RecordSignalType2 { get { return m_recordSignalType2; } set { m_recordSignalType2 = value; } } eRecordSignal m_recordSignalType3 = eRecordSignal.AnalogOut1; [Browsable(true)] [ReadOnly(false)] [Category("Record Siganl")] [DisplayName("Record Signal Type 3")] [Description("Record Signal Type 3")] public eRecordSignal RecordSignalType3 { get { return m_recordSignalType3; } set { m_recordSignalType3 = value; } } eRecordSignal m_recordSignalType4 = eRecordSignal.AnalogOut2; [Browsable(true)] [ReadOnly(false)] [Category("Record Siganl")] [DisplayName("Record Signal Type 4")] [Description("Record Signal Type 4")] public eRecordSignal RecordSignalType4 { get { return m_recordSignalType4; } set { m_recordSignalType4 = value; } } uint m_recordPeriod = 10; [Browsable(true)] [ReadOnly(false)] [Category("Record Siganl")] [DisplayName("Record Period(㎲)")] [Description("Record Period(Minimum 10 ㎲)")] public uint RecordPeriod { get { return m_recordPeriod; } set { m_recordPeriod = value; } } [Browsable(true)] [ReadOnly(false)] [Category("Ethernet Connection")] [DisplayName("Link Loss Config")] [Description("Mode 0 : Laser Disabled, LIST execution continues.\nMode 1: Laser Disabled, List Execution is stopped.\n Mode 2 : simulate external stop. \nMode 3 : Ethernet Link Loss detection switched off.")] public eEthConfigLinkLossMode EthernetConfigLinkLoss { get { return m_ethConfigLinkLoss; } set { m_ethConfigLinkLoss = value; } } string m_scannerParamFile; public string GetScannerParamFile() { return m_scannerParamFile; } public ScannerUnitParam() { } public ScannerUnitParam(string fileName) { m_primaryHeadNo = 1; m_secondHeadNo = 2; m_ControlMode = 0; m_laserMode = 0; m_laserControl = 0; m_laserOnDelay = 0; m_laserOffDelay = 0; m_jumpDelay = 100; m_markDelay = 100; m_polygonDelay = 100; m_laserPeriod = 16; m_laser1PulseWidth = 4; m_markSpeed = 100; m_jumpSpeed = 100; m_scaleXYFactor = 100; m_scaleZFactor = 100; m_firstPulseKiller = 10; m_use3DMode = false; m_useEncoderFeedbackMode = false; m_useMarkingOnTheFly = false; m_markingOnTheFlyEncoderResolutionX = 1; m_markingOnTheFlyEncoderResolutionY = 1; m_markingOnTheFlyEncoderResolutionRotate = 1; m_markingStartWaitMode = eWaitEncoderMode.NoUse; m_ontheFlyCoordinate = eOntheFlyCoordinate.XY; m_markingStartEncoderPositionX = 0; m_markingRangeMinX = 0; m_markingRangeMaxX = 0; m_markingRangeMinY = 0; m_markingRangeMaxY = 0; m_markingRangeMinRotate = 0; m_markingRangeMaxRotate = 0; m_markingOntheFlyOffsetX = 0; m_markingOntheFlyOffsetY = 0; m_flySpeedInterlock = 1000; m_rotaryEncoderOffset = 0; m_markingOntheFlyStageSpeed = 350; m_programFile = @"D:\EQPData\LASA.eqpdata\Scanner"; m_correctionFile = @"D:\EQPData\LASA.eqpdata\Scanner\Cor_1to1.ct5"; m_laserCorrectionFile = @"D:\EQPData\LASA.eqpdata\Scanner\Cor_1to1.ct5"; m_scanYSize = 0; m_scanXSize = 0; m_scanZSize = 0; m_scannerParamFile = fileName; m_translationXOffset = 0; m_translationYOffset = 0; m_translationAngle = 0; m_laserSiganlPin2 = eLaserSignal.LASERON; m_laserSiganlPin1 = eLaserSignal.LASER1; m_laserSiganlPin9 = eLaserSignal.LASER2; m_ethConfigLinkLoss = eEthConfigLinkLossMode.Mode3; } } public const uint NO_ERROR = 0; protected ScannerUnitParam m_scannerUnitParam = null; public ScannerUnitParam ScannerUnitParamObj { set { lock (this) { m_scannerUnitParam = value; } } get { lock (this) { return m_scannerUnitParam; } } } public bool IsOpenUnit { get { lock (this) { return isOpenUnit; } } set { lock (this) { isOpenUnit = value; } } } public double CommandPosX { get { lock (this) { return m_commandPosX; } } set { lock (this) { m_commandPosX = value; } } } public double CommandPosY { get { lock (this) { return m_commandPosY; } } set { lock (this) { m_commandPosY = value; } } } public double CommandPosZ { get { lock (this) { return m_commandPosZ; } } set { lock (this) { m_commandPosZ = value; } } } string m_scannerParamFile = string.Empty; private bool isOpenUnit = false; protected uint m_deviceNo; double m_commandPosX = 0; double m_commandPosY = 0; double m_commandPosZ = 0; public enum eFunctionType { COMMAND, LIST }; public enum eAnalogPortOut { DA1 = 1, DA2 }; public enum eEncoderWaitThroughMode { UnderStepping = -1, BothSide = 0, OverStepping = 1 } public enum eParkType { RealImage = 0, VirtualImage = 1 } public enum eListNo { LIST1 = 1, LIST2 = 2 }; public enum eAutoControlParameter { NoUse = 0, AnalogOut1, AnalogOut2, DigitalOut8Bit, PulseLength, HalfPeriod, DigitalOut16bit, FocusShift } // 초기화 public abstract uint Open(); public abstract void Close(); // MOTION FUNCTIONS public abstract void Initialize(); public abstract void JumpAbs(double x, double y, eFunctionType type = eFunctionType.COMMAND); public abstract void JumpAbs3D(double x, double y, double z, eFunctionType type = eFunctionType.COMMAND); public abstract void JumpRel(double x, double y, eFunctionType type = eFunctionType.COMMAND); public abstract void JumpRel3D(double x, double y, double z, eFunctionType type = eFunctionType.COMMAND); public abstract void JumpAbsZ(double z, eFunctionType type = eFunctionType.COMMAND); public abstract void JumpRelZ(double z, eFunctionType type = eFunctionType.COMMAND); public abstract void MarkAbs(double x, double y); public abstract void ArcAbs(double x, double y, double angle /*(+)가 반시계 방향*/); public abstract void ArcRel(double x, double y, double angle /*(+)가 반시계 방향*/ ); public abstract void MarkRel(double x, double y); public abstract void GetXYPos(out double x, out double y); public abstract void GetZPos(out double z); public abstract void GetEncoder(out double encoderX, out double encoderY, bool rotateMode = false); public abstract uint GetMarkingInfo(); public abstract uint GetStartStopInfo(); /// /// Stores the current counts of the two RTC encoder counters in a cache on the RTC /// /// Storage position. 0 or 1 public abstract void StoreEncoder(uint pos); public abstract void ReadEncoder(out double encoder0_0, out double encoder1_0, out double encoder0_1, out double encoder1_1, bool rotateMode = false); public abstract void WaitForEncoderX(double position); public abstract void WaitForEncoderY(double position); public abstract void WaitForEncoderRotateX(double angle); public abstract void WaitForEncoderRotateY(double angle); public abstract void WaitForEncoderRotateXMode(double angle, eEncoderWaitThroughMode mode); public abstract void WaitForEncoderRotateYMode(double angle, eEncoderWaitThroughMode mode); public abstract void WaitForEncoderXMode(double position, eEncoderWaitThroughMode mode); public abstract void WaitForEncoderYMode(double position, eEncoderWaitThroughMode mode); public abstract void WaitForEncoderMode(double position, uint encoderNo, eEncoderWaitThroughMode mode); public abstract void WaitForEncoderRange(double minX, double maxX, double minY, double maxY); public abstract void WaitForEncoderRotateRange(double minRotateX, double maxRotateX, double minRotateY, double maxRotateY); public abstract void SetFlyX(double encoderResolution = 0); public abstract void SetFlyY(double encoderResolution = 0); public abstract void SetFlyRotate(double encoderResolution); public abstract void SetFlyRotatePos(double encoderResolution); public abstract void SetRotateCenter(double posX, double posY, eFunctionType type = eFunctionType.COMMAND); public abstract void ActivateFlyXY(double encoderResolutionX, double encoderResolutionY); public abstract void ActivateFly1Axis(int axis, int mode, double scale, int offset); public abstract void Fly_Return(double posX, double posY); public abstract void ParkPosition(double posX, double posY, eParkType type = eParkType.VirtualImage); public abstract void ParkReturn(double posX, double posY, eParkType type = eParkType.VirtualImage); public abstract void InitFly2D(int offsetX = 0, int offsetY = 0); public abstract void SimulateEncoder(uint EncoderNo); public abstract void SetControlMode(uint mode); public abstract void SetLaesrDelay(int laserOnDelay, uint laserOffDelay); public abstract void SetScannerDelay(uint jumpDelay, uint markDelay, uint arcDelay); public abstract void SetJumpSpeedCtrl(double speed); public abstract void SetJumpSpeed(double speed); public abstract void SetMarkSpeed(double speed); public abstract void SetStartList(eListNo no); public abstract uint LoadList(eListNo no); public abstract void SetEndList(); public abstract void ExecuteList(eListNo no); public abstract void StartLoop(); public abstract void QuitLoop(); public abstract void AutoChange(); public abstract bool GetBusyStatus(); public abstract void SelectCorrectionTable(int no); public abstract void StopExecution(); public abstract uint GetRTCVersion(); public abstract uint GetDLLVersion(); public abstract void SetLaserTiming(uint halfPeriod, uint laser1PulseWidth, uint laser2PulseWidth); public abstract void SetStandby(uint periodHz, uint laserPulseWidthUs); public abstract void SetLaserMode(ScannerUnitParam.eLaserMode mode); public abstract void SetLaserControl(uint mode); public abstract void SetFirstPulseKiller(uint width); //unit:us public abstract void LaserSignalOn(); public abstract void LaserSignalOff(); public abstract void LaserOnList(double interval); public abstract void SetAngle(double angle, uint atOnce = 1, eFunctionType type = eFunctionType.COMMAND); public abstract void SetOffset(double offsetX, double offsetY, uint atOnce = 1, eFunctionType type = eFunctionType.COMMAND); public abstract void DisableLaser(); public abstract void EnableLaser(); // Write DA public abstract void WriteDA(uint portNo, float value/*0~100%*/, eFunctionType type = eFunctionType.COMMAND); //Ramping 관련 기능 추가 public abstract void SetVectorControl(uint portNo, uint value); public abstract void ParaMarkAbs(double x, double y, float powerValue/*0~100%*/ ); public abstract void ParaMarkRel(double x, double y, float powerValue/*0~100%*/ ); public abstract void ParaJumpAbs(double x, double y, float powerValue/*0~100%*/ ); public abstract void ParaJumpRel(double x, double y, float powerValue/*0~100%*/ ); public abstract void ParaLaserOnPulsesList(double period/*msec 최소시간은 0.01msec*/, uint pulses /*0~65535*/, float powerValue/*0~100%*/ ); //SetTrigger 기능 관련 추가 public abstract void StopTrigger(); public abstract void SetTrigger(uint period/*㎲*/, ScannerUnitParam.eRecordSignal signal1, ScannerUnitParam.eRecordSignal signal2); public abstract void SetTrigger(uint period/*㎲*/, ScannerUnitParam.eRecordSignal signal1, ScannerUnitParam.eRecordSignal signal2, ScannerUnitParam.eRecordSignal signal3, ScannerUnitParam.eRecordSignal signal4); public abstract void Measurement_status(out uint busy, out uint pos); public abstract uint ReadStatus(); public abstract void GetWaveForm(uint channel, uint number, out int[] data); public abstract void SetWobbelMode(bool wobbelEnable, double tansversal, double longitudinal, double frequency, int mode); public abstract void SetWobbelDirection(int dX, int dY); public abstract void SetWobbelVector(double tansversal, double longitudinal, UInt32 period, float power); public abstract void ConfigLaserSignal(ScannerUnitParam.eLaserSignal pin2, ScannerUnitParam.eLaserSignal pin1, ScannerUnitParam.eLaserSignal pin9); public abstract void LongDelay(uint delay); public abstract void SetEthernetConfigLinkLoss(ScannerUnitParam.eEthConfigLinkLossMode mode); public abstract int CheckEthernetConnection(out uint errorCode); #region 리스트 실행 시간 측정 public abstract void SaveAndRestartTimer(); public abstract double GetTime(); #endregion public ScannerUnit(string fileName) { m_commandPosX = 0; m_commandPosY = 0; m_commandPosZ = 0; m_scannerParamFile = fileName; m_scannerUnitParam = new ScannerUnitParam(fileName); Load(); } public void Load() { FileInfo fileInfo = new FileInfo(m_scannerParamFile); if (fileInfo.Exists == false) { MessageBox.Show(string.Format("파일({0})이 존재하지 않습니다. 기본 데이터의 파일을 생성합니다.", m_scannerParamFile), "파일 읽기 에러", MessageBoxButtons.OK, MessageBoxIcon.Error); Save(); } else { try { XmlSerializer xmlSerializer = new XmlSerializer(m_scannerUnitParam.GetType()); using (StreamReader rdr = new StreamReader(m_scannerParamFile)) { m_scannerUnitParam = (ScannerUnitParam)xmlSerializer.Deserialize(rdr); } UtilUnit.logUnit.SetLog(LogUnit.eLogType.DEBUG, MethodBase.GetCurrentMethod().Name, string.Format("[ScannerUnit] 스캐너 Unit 정보 파일({0}) 읽기 완료", m_scannerParamFile)); } catch (Exception ex) { throw new System.Exception(string.Format("ERR_SCANNER_FAIL_TO_LOAD_SCANNER_PARAM_FILE;ERROR MSG:{0}", ex.Message)); } } } public void Save() { try { XmlSerializer xmlSerializer = new XmlSerializer(typeof(ScannerUnitParam)); using (StreamWriter wr = new StreamWriter(m_scannerParamFile)) { xmlSerializer.Serialize(wr, m_scannerUnitParam); } UtilUnit.logUnit.SetLog(LogUnit.eLogType.DEBUG, MethodBase.GetCurrentMethod().Name, string.Format("[ScannerUnit] 스캐너 Unit 정보 파일({0}) 쓰기 완료", m_scannerParamFile)); } catch (Exception ex) { throw new System.Exception(string.Format("ERR_SCANNER_FAIL_TO_SAVE_SCANNER_PARAM_FILE;ERROR MSG:{0}", ex.Message)); } } public void WaitForMotionCompleted(double commandX, double commandY, int timeOut) { TimeSpan spanTime; DateTime startTime = DateTime.Now; do { spanTime = DateTime.Now.Subtract(startTime); if (spanTime.TotalMilliseconds > (timeOut * 1000)) { throw new Exception("ERR_SCANNER_TIMEOUT_FOR_MOTION_CMPL"); } if (ScannerUnitParamObj.UseEncoderFeedbackMode) { double currPosX = 0f, currPosY = 0f; GetXYPos(out currPosX, out currPosY); //PointF targetPt = new PointF(); //CoreUnit.Common.UtilUnit.TranslateCoordination(new PointF((float)currPosX, (float)currPosY), ref targetPt, (float)ScannerUnitParamObj.TranslationAngle); if ((Math.Abs(commandX - currPosX) < Settings.Default.ScannerInPositionValue) && (Math.Abs(commandY - currPosY) < Settings.Default.ScannerInPositionValue)) { return; } } //else if (!GetBusyStatus()) //{ // return; //} else { Thread.Sleep(timeOut); return; } Thread.Sleep(1); } while (true); } public void WaitForListTaskCompleted(int timeOut) //단위는 초 { TimeSpan spanTime; DateTime startTime = DateTime.Now; do { spanTime = DateTime.Now.Subtract(startTime); if (spanTime.TotalMilliseconds > (timeOut * 1000)) { throw new Exception("ERR_SCANNER_TIMEOUT_FOR_LIST_CMP"); } Thread.Sleep(1); } while (GetBusyStatus() == true); } private int encoderOverflowCount = 0; /// /// 회전 엔코더 Overflow 카운트 /// public int EncoderOverflowCount { get { return encoderOverflowCount; } set { encoderOverflowCount = value; } } /// /// 현재 Rotary의 회전 각도에서, 현재 용접 카운트와 지그 번호를 계산. 추가로 Overflow 카운트도 초기화 /// /// Rotary 회전 Offset. 운전 시작 시 Rotary가 지그 1번 정중심에서부터 시작했을 경우가 0. 범위는 0이상 /// Rotary Welding Count. 30도 구간 하나가 지나갈 때마다 +1 /// 현재 '용접 중' 구간에 들어가 있는 지그 번호 public void InitRotaryOnTheFlyWeldingCount(double rotaryAngleOffset, out int weldingCount, out int weldingJigNo) { // rotaryAngleOffset = 0도 이상 15도 미만일 때, weldingCount = 0, weldingJigNo = 1 // rotaryAngleOffset = 15도 이상 45도 미만일 때, weldingCount = 1, weldingJigNo = 2 // rotaryAngleOffset = 45도 이상 75도 미만일 때, weldingCount = 2, weldingJigNo = 3 // rotaryAngleOffset = 315도 이상 345도 미만일 때, weldingCount = 11, weldingJigNo = 12 // rotaryAngleOffset = 345도 이상 360도 미만일 때, weldingCount = 12, weldingJigNo = 1 // 현재 로터리 엔코더 값을 기준으로 현재 카운트, 지그 번호를 확인 weldingCount = (int)((rotaryAngleOffset + 15) / 30); // m_weldingCount = 0, 1, 2, ... weldingJigNo = weldingCount % 12 + 1; // m_weldingJigNo = 1, 2, ... , 12 } /// /// Rotary Flying 용접 시, 다음 Rotary Section의 시작 각도를 계산하고 wait_for_encoder 함수까지 호출) /// /// Rotary Welding Count. 30도 구간 하나가 지나갈 때마다 +1 /// Rotary 회전 Offset. 운전 시작 시 Rotary가 지그 1번 정중심에서부터 시작했을 경우가 0. 범위는 0이상 360.0미만 /// list 명령 "set_fly_rot"실행 시 RTC 보드 소요시간 때문에 발생하는 각도 오프셋 /// 계산의 결과값이며, 여기까지 wait_for_encoder 수행 public void WaitForEncoderNextRotarySection(int weldingCount, double rotaryAngleOffset, double encoderResetOffset, out double sectionStartAngle) { double encoderAllowedMinDegree = Int32.MinValue / ScannerUnitParamObj.MarkingOnTheFlyEncoderResolutionRotate * 360.0; double encoderAllowedMaxDegree = Int32.MaxValue / ScannerUnitParamObj.MarkingOnTheFlyEncoderResolutionRotate * 360.0; // 1.1. 시작 각도 = (현재 지그 번호 * 30도) -15도 - 초기화 엔코더 값 - 엔코더 리셋 보상값 // rotaryAngleOffset = x가 0도 이상 15도 미만일 때, weldingCount = 1부터 시작, sectionStartAngle = 15 - x에서 30씩 증가 // rotaryAngleOffset = x가 15도 이상 45도 미만일 때, weldingCount = 2부터 시작, sectionStartAngle = 30 - x에서 30씩 증가 // rotaryAngleOffset = x가 45도 이상 75도 미만일 때, weldingCount = 3부터 시작, sectionStartAngle = 30 - x에서 30씩 증가 // rotaryAngleOffset = x가 315도 이상 345도 미만일 때, weldingCount = 12부터 시작, sectionStartAngle = 30 - x에서 30씩 증가 // rotaryAngleOffset = x가 345도 이상 360도 미만일 때, weldingCount = 13부터 시작, sectionStartAngle = 30 - x에서 30씩 증가 sectionStartAngle = weldingCount * 30 - 15 - rotaryAngleOffset - encoderResetOffset - EncoderOverflowCount * (encoderAllowedMaxDegree - encoderAllowedMinDegree); // 1.2. 계산된 시작각도가 이미 지나버렸으면 알람 발생 필요 // 1.3. Overflow가 나는 숫자라면, 보상할 것. if (sectionStartAngle > encoderAllowedMaxDegree) { sectionStartAngle -= encoderAllowedMaxDegree - encoderAllowedMinDegree; EncoderOverflowCount++; } double sectionEndAngle = (encoderAllowedMaxDegree < sectionStartAngle + 30.0) ? encoderAllowedMaxDegree : sectionStartAngle + 30.0; WaitForEncoderRotateRange(encoderAllowedMinDegree, encoderAllowedMaxDegree, sectionStartAngle, sectionEndAngle); } } }