Skip to content

Commit

Permalink
Started waterjet .sta file generation code
Browse files Browse the repository at this point in the history
  • Loading branch information
pan261 committed Sep 16, 2021
1 parent 6fb2f7e commit dd3f8c9
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions Flow_Waterjet_BIDC/Bechtel Waterjet.cps
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -451,6 +525,7 @@ function onSectionEnd() {
}

function onClose() {
writeSta();
if (isRedirecting()) {
var mainProgram = getRedirectionBuffer(); // TAG: no need for redirection
closeRedirection();
Expand Down

0 comments on commit dd3f8c9

Please sign in to comment.