From dd3f8c9514019953562fe21d3275c42d3ac49f03 Mon Sep 17 00:00:00 2001 From: pan261 Date: Thu, 16 Sep 2021 18:41:51 -0400 Subject: [PATCH] Started waterjet .sta file generation code --- Flow_Waterjet_BIDC/Bechtel Waterjet.cps | 75 +++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/Flow_Waterjet_BIDC/Bechtel Waterjet.cps b/Flow_Waterjet_BIDC/Bechtel Waterjet.cps index 57fd684..520cafa 100644 --- a/Flow_Waterjet_BIDC/Bechtel Waterjet.cps +++ b/Flow_Waterjet_BIDC/Bechtel Waterjet.cps @@ -103,6 +103,80 @@ var compensationOffset = 0; // center compensation var etchOperation = false; // though-cut unless set to true var forceOutput = false; +/** + * + * @param num + * @returns Little Endian hex string (float) + */ + function ToHex(num) { + if (num == 0) { + return "00000000"; //bypass + } + + var sign = "0"; + + if(num < 0.0) { + sign = "1"; + num = -num; + } + + var mantissa = parseFloat(num).toString(2); + var exponent = 0; + + if (mantissa.indexOf('.') == -1) { + mantissa = mantissa.toString() + ".0"; + } + + if (mantissa.substr(0, 1) === "0") { + exponent = mantissa.indexOf('.') - mantissa.indexOf('1') + 127; + } + else { + exponent = mantissa.indexOf('.') - 1 + 127; + } + + mantissa = mantissa.replace(".", ""); + mantissa = mantissa.substr(mantissa.indexOf('1') + 1); + + if (mantissa.length > 23) { + mantissa = mantissa.substr(0, 23); + } + else { + while (mantissa.length < 23) { + mantissa = mantissa + "0"; + } + } + + var exp = parseFloat(exponent).toString(2); + + while(exp.length < 8) { + exp = "0" + exp; + } + + var numberFull = sign + exp + mantissa; + return parseInt(numberFull, 2).toString(16); + +} + +/** + * (IN PROGRESS) Write machine config to .sta file + */ +function writeSta() { + try { + var file = new TextFile("C:\\Users\\" + getGlobalParameter("username") + "\\AppData\\Local\\Fusion 360 CAM\\nc\\hello.txt", true, "utf-8"); + + var float = 9.94; + + + file.writeln(ToHex(6.0)); + + file.close(); + + } catch (e) { + error(localize("Failed to write sta file.")); + } + +} + /** Writes the specified block. */ @@ -451,6 +525,7 @@ function onSectionEnd() { } function onClose() { + writeSta(); if (isRedirecting()) { var mainProgram = getRedirectionBuffer(); // TAG: no need for redirection closeRedirection();