public static Eeprom ConvertEeprom(UInt32[] values) { var ee = new EepromV1 { Values = values }; if (ee.IsValid) { File.WriteAllLines(Environment.ExpandEnvironmentVariables(@"%TEMP%\EepromRead.nc"), ee.ToGCode()); var eeprom = Create(ee[EepromV1.EValueOffsets32.Signature]); eeprom.Values = values; eeprom.ReadFrom(ee); return(eeprom); } return(null); }
public static void WriteTo(this Eeprom eeprom, EepromV1 ee) { byte numAxis = ee[EepromV1.EValueOffsets8.NumAxis]; for (int i = 0; i < numAxis; i++) { ee[i, EepromV1.EAxisOffsets32.Size] = eeprom.GetAxis(i).Size; ee[i, EepromV1.EAxisOffsets8.EReverenceType] = (byte)eeprom.GetAxis(i).RefMove; ee[i, EepromV1.EAxisOffsets8.EReverenceSequence] = (byte)(Eeprom.EReverenceSequence)eeprom[i]; ee[i, EepromV1.EAxisOffsets8.EReverenceHitValueMin] = eeprom.GetAxis(i).RefHitValueMin; ee[i, EepromV1.EAxisOffsets8.EReverenceHitValueMax] = eeprom.GetAxis(i).RefHitValueMax; int direction = ee[EepromV1.EValueOffsets8.StepperDirection] & (~(1 << i)); if (eeprom.GetAxis(i).StepperDirection) { direction += 1 << i; } ee[EepromV1.EValueOffsets8.StepperDirection] = (byte)direction; ee[i, EepromV1.EAxisOffsets32.InitPosition] = eeprom.GetAxis(i).InitPosition; if (ee.DWSizeAxis > EepromV1.SIZEOFAXIS_EX) { ee[i, EepromV1.EAxisOffsets32.MaxStepRate] = eeprom.GetAxis(i).MaxStepRate; ee[i, EepromV1.EAxisOffsets16.Acc] = eeprom.GetAxis(i).Acc; ee[i, EepromV1.EAxisOffsets16.Dec] = eeprom.GetAxis(i).Dec; ee[i, EepromV1.EAxisOffsets32.StepsPerMm1000] = BitConverter.ToUInt32(BitConverter.GetBytes(eeprom.GetAxis(i).StepsPerMm1000), 0); ee[i, EepromV1.EAxisOffsets32.ProbeSize] = eeprom.GetAxis(i).ProbeSize; ee[i, EepromV1.EAxisOffsets32.RefMoveStepRate] = eeprom.GetAxis(i).RefMoveStepRate; } } ee[EepromV1.EValueOffsets16.MaxSpindleSpeed] = eeprom.MaxSpindleSpeed; ee[EepromV1.EValueOffsets8.SpindleFadeTime] = eeprom.SpindleFadeTime; ee[EepromV1.EValueOffsets32.RefMoveStepRate] = eeprom.RefMoveStepRate; ee[EepromV1.EValueOffsets32.MoveAwayFromReference] = eeprom.MoveAwayFromReference; ee[EepromV1.EValueOffsets32.MaxStepRate] = eeprom.MaxStepRate; ee[EepromV1.EValueOffsets16.Acc] = eeprom.Acc; ee[EepromV1.EValueOffsets16.Dec] = eeprom.Dec; ee[EepromV1.EValueOffsets16.JerkSpeed] = eeprom.JerkSpeed; ee[EepromV1.EValueOffsets32.StepsPerMm1000] = BitConverter.ToUInt32(BitConverter.GetBytes(eeprom.StepsPerMm1000), 0); if (ee[EepromV1.EValueOffsets32.Signature] == EepromV1.SIGNATUREPLOTTER) { ee[EepromV1.EValueOffsets32Plotter.EPenDownFeedrate] = eeprom.PenDownFeedrate; ee[EepromV1.EValueOffsets32Plotter.EPenUpFeedrate] = eeprom.PenUpFeedrate; ee[EepromV1.EValueOffsets32Plotter.EMovePenDownFeedrate] = eeprom.MovePenDownFeedrate; ee[EepromV1.EValueOffsets32Plotter.EMovePenUpFeedrate] = eeprom.MovePenUpFeedrate; ee[EepromV1.EValueOffsets32Plotter.EMovePenChangeFeedrate] = eeprom.MovePenChangeFeedrate; ee[EepromV1.EValueOffsets32Plotter.EPenDownPos] = eeprom.PenDownPos; ee[EepromV1.EValueOffsets32Plotter.EPenUpPos] = eeprom.PenUpPos; ee[EepromV1.EValueOffsets32Plotter.EPenChangePosX] = eeprom.PenChangePos_x; ee[EepromV1.EValueOffsets32Plotter.EPenChangePosY] = eeprom.PenChangePos_y; ee[EepromV1.EValueOffsets32Plotter.EPenChangePosZ] = eeprom.PenChangePos_z; ee[EepromV1.EValueOffsets32Plotter.EPenChangePosXOfs] = eeprom.PenChangePos_x_ofs; ee[EepromV1.EValueOffsets32Plotter.EPenChangePosYOfs] = eeprom.PenChangePos_y_ofs; ee[EepromV1.EValueOffsets16Plotter.EPenChangeServoClampOpenPos] = eeprom.ServoClampOpenPos; ee[EepromV1.EValueOffsets16Plotter.EPenChangeServoClampClosePos] = eeprom.ServoClampClosePos; ee[EepromV1.EValueOffsets16Plotter.EPenChangeServoClampOpenDelay] = eeprom.ServoClampOpenDelay; ee[EepromV1.EValueOffsets16Plotter.EPenChangeServoClampCloseDelay] = eeprom.ServoClampCloseDelay; } }
public static void ReadFrom(this Eeprom eeprom, EepromV1 ee) { eeprom.Signature = ee[EepromV1.EValueOffsets32.Signature]; byte numAxis = ee[EepromV1.EValueOffsets8.NumAxis]; eeprom.NumAxis = ee[EepromV1.EValueOffsets8.NumAxis]; eeprom.UseAxis = ee[EepromV1.EValueOffsets8.UseAxis]; eeprom.Info1 = ee[EepromV1.EValueOffsets32.Info1]; eeprom.Info2 = ee[EepromV1.EValueOffsets32.Info2]; for (int i = 0; i < numAxis; i++) { eeprom.GetAxis(i).DWEESizeOf = ee.DWSizeAxis; eeprom.GetAxis(i).Size = ee[i, EepromV1.EAxisOffsets32.Size]; eeprom.GetAxis(i).RefMove = (Eeprom.EReverenceType)ee[i, EepromV1.EAxisOffsets8.EReverenceType]; eeprom.GetAxis(i).RefHitValueMin = ee[i, EepromV1.EAxisOffsets8.EReverenceHitValueMin]; eeprom.GetAxis(i).RefHitValueMax = ee[i, EepromV1.EAxisOffsets8.EReverenceHitValueMax]; eeprom.GetAxis(i).InitPosition = ee[i, EepromV1.EAxisOffsets32.InitPosition]; eeprom.GetAxis(i).StepperDirection = (ee[EepromV1.EValueOffsets8.StepperDirection] & (1 << i)) != 0; eeprom[i] = (Eeprom.EReverenceSequence)ee[i, EepromV1.EAxisOffsets8.EReverenceSequence]; if (ee.DWSizeAxis > EepromV1.SIZEOFAXIS_EX) { eeprom.GetAxis(i).MaxStepRate = ee[i, EepromV1.EAxisOffsets32.MaxStepRate]; eeprom.GetAxis(i).Acc = ee[i, EepromV1.EAxisOffsets16.Acc]; eeprom.GetAxis(i).Dec = ee[i, EepromV1.EAxisOffsets16.Dec]; eeprom.GetAxis(i).StepsPerMm1000 = BitConverter.ToSingle(BitConverter.GetBytes(ee[i, EepromV1.EAxisOffsets32.StepsPerMm1000]), 0); eeprom.GetAxis(i).ProbeSize = ee[i, EepromV1.EAxisOffsets32.ProbeSize]; eeprom.GetAxis(i).RefMoveStepRate = ee[i, EepromV1.EAxisOffsets32.RefMoveStepRate]; } } eeprom.MaxSpindleSpeed = ee[EepromV1.EValueOffsets16.MaxSpindleSpeed]; eeprom.SpindleFadeTime = ee[EepromV1.EValueOffsets8.SpindleFadeTime]; eeprom.RefMoveStepRate = ee[EepromV1.EValueOffsets32.RefMoveStepRate]; eeprom.MoveAwayFromReference = ee[EepromV1.EValueOffsets32.MoveAwayFromReference]; eeprom.MaxStepRate = ee[EepromV1.EValueOffsets32.MaxStepRate]; eeprom.Acc = ee[EepromV1.EValueOffsets16.Acc]; eeprom.Dec = ee[EepromV1.EValueOffsets16.Dec]; eeprom.JerkSpeed = ee[EepromV1.EValueOffsets16.JerkSpeed]; eeprom.StepsPerMm1000 = BitConverter.ToSingle(BitConverter.GetBytes(ee[EepromV1.EValueOffsets32.StepsPerMm1000]), 0); if (eeprom.Signature == EepromV1.SIGNATUREPLOTTER) { eeprom.PenDownFeedrate = ee[EepromV1.EValueOffsets32Plotter.EPenDownFeedrate]; eeprom.PenUpFeedrate = ee[EepromV1.EValueOffsets32Plotter.EPenUpFeedrate]; eeprom.MovePenDownFeedrate = ee[EepromV1.EValueOffsets32Plotter.EMovePenDownFeedrate]; eeprom.MovePenUpFeedrate = ee[EepromV1.EValueOffsets32Plotter.EMovePenUpFeedrate]; eeprom.MovePenChangeFeedrate = ee[EepromV1.EValueOffsets32Plotter.EMovePenChangeFeedrate]; eeprom.PenDownPos = ee[EepromV1.EValueOffsets32Plotter.EPenDownPos]; eeprom.PenUpPos = ee[EepromV1.EValueOffsets32Plotter.EPenUpPos]; eeprom.PenChangePos_x = ee[EepromV1.EValueOffsets32Plotter.EPenChangePosX]; eeprom.PenChangePos_y = ee[EepromV1.EValueOffsets32Plotter.EPenChangePosY]; eeprom.PenChangePos_z = ee[EepromV1.EValueOffsets32Plotter.EPenChangePosZ]; eeprom.PenChangePos_x_ofs = ee[EepromV1.EValueOffsets32Plotter.EPenChangePosXOfs]; eeprom.PenChangePos_y_ofs = ee[EepromV1.EValueOffsets32Plotter.EPenChangePosYOfs]; eeprom.ServoClampOpenPos = ee[EepromV1.EValueOffsets16Plotter.EPenChangeServoClampOpenPos]; eeprom.ServoClampClosePos = ee[EepromV1.EValueOffsets16Plotter.EPenChangeServoClampClosePos]; eeprom.ServoClampOpenDelay = ee[EepromV1.EValueOffsets16Plotter.EPenChangeServoClampOpenDelay]; eeprom.ServoClampCloseDelay = ee[EepromV1.EValueOffsets16Plotter.EPenChangeServoClampCloseDelay]; } }