Yes… back in action. I haven’t done anything with this for more than 18 month, but when working on another post-processor I realized that things have happened with the post-processor in Fusion 360. The current version actually have support for calling the javascript classes I was missing, e.g. the BinaryFile class
One difference from before is that I work with Windows and not macOS so I still have to check if this also applies for the mac. However, the joy was not long lasting as I’m still not able to save the binary file successfully. I can load, open, a file, but when saving all efforts results in a 0 byte file. Hmm… This is maybe something I should address to Autodesk but for now I just want to explore the options.
As I mentioned in an earlier post, you can convert your result to a binary file with python, but my initial thought was that it had to be a second step for the user to do that. But when I was digging deeper in to javascript I realized I could launch an external process from the post-processor, making it a single-step user experience possible.
The Concept
Basically this is how I solved the task of saving a file as binary (for Windows) from the post-processor a.k.a a cps-file:
- Create a path to Fusion 360 python.exe
- Check for a python script in a folder. If not there, create the script by writing a py-file to the destination.
- Write the all the machine code as hex-text, i.e. 2EFA etc, to a separate temporarily text-file. Note: The actual machine code for the RuiDa controller is still do be done.
- Finally launch the python script which will take convert the hex-text-file to a binary.
By doing it this way. You don’t need anything else than the ruida.cps file since the python execution is handle by the post-processor itself. Cool…
What’s Next
Next step will be to do the actual machine code, which is the actual point of having a post-processor for the RuiDa controller. I will also check if this solution also works with macOS. However this will not be explored in a near future…..
Pyhon Script
Here is an example of the python script that could be created by the post-processor:
import os, sys
# Open hextext, tmp-file
r = open(sys.argv[1],'r')
lines = [line.rstrip('\n') for line in r] be
r.close()
# Delete tmp-file
os.remove(sys.argv[1])
# create a binary file
with open(sys.argv[2], 'wb') as f:
for line in lines:
f.write(bytes.fromhex(line))