Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

G-Code as Binary output


Recommended Posts

Greetings.

When you have extra time at work you can do many things :D

Here is sample of the code how to convert your G- code output to binary output if you want to try yourself
All the numbers are rounder up, all the negative numbers are converted to positive.
Also mastercam has limit for the amount of decimal spaces so big numbers can be converted correctly( or there is another way?)
code below require more work if you want to convert I, J and K to binary 
For example for k$ you need 4 checks
if k$ < 0, k$ = k$ * m_one
if k$ < one & k$ > zero, k$ = k$ * two^8
if k$ > zero & k$ > m_one,
if k$ < zero,

have fun guys, and remember if you want to try this do backup first

 

        if binary_output = one,
          [
          sbinary = " "
          if xabs < zero, xabs = xabs * m_one
          decimal = round(xabs)
          # Check if the decimal number is 0
          if decimal = zero, *decimal, e$
          # Initialize a variable to keep track of the power of 2
          power = zero
          # Loop to find the highest power of 2 less than or equal to the decimal number
          while two^power <= decimal,
              [
              power = power + one
              ]
          # Adjust the power as we overshot in the loop
          # Loop through each power of 2 in descending order
          while power > zero,
              # If the current power of 2 can be subtracted from the decimal number
              [
              if decimal - two^(power - one) >= zero,
                  [
                  sbinary = sbinary + sbinary_one  # Concatenate '1' to the string
                  decimal = decimal - two^(power - one)  # Update decimal value
                  ]
              else,
                  [
                  sbinary = sbinary + sbinary_zero  # Concatenate '0' to the string
                  ]
              power = power - one  # Decrement power
              ]    
          binary_digits = rpar(sbinary, one)
          xabs = binary_digits
          *xabs
          ]
        else,
          [
          if absinc$ = zero, *xabs, !xinc
          else, xinc, !xabs
          ]
        !xabs
Before
N100 G21
(TOOL - 5 OFFSET - 5)
(WALTER_VNMG  INSERT - INSERT)
N110 G0 T0505
N120 G18
N130 G97 S2000 M03
N140 G0 G54 X16.973 Z4.464 M8
N150 G50 S2000
N160 G96 S185
N170 G99 G1 X14.144 Z3.05 F.2
N180 X14.144 Z-6.757 F.2
N190 G18 G3 X14.2 Z-7.4 I-7.422 K-.643 F.2
N200 G1 X14.2 Z-17.959 F.1
N210 X14.2 Z-17.97 F.2
N220 X14.2 Z-24.1 F.2
N230 X17.028 Z-22.686 F.2
N240 G0 X17.028 Z4.464
N250 X15.117
N260 G1 X12.289 Z3.05 F.2
N270 X12.289 Z-3.75 F.2
N280 G3 X14.144 Z-6.758 I-6.494 K-3.651 F.2
N290 G1 X16.973 Z-5.343 F.2
N300 G0 X16.973 Z4.464
N310 X13.262
N320 G1 X10.433 Z3.05 F.2
N330 X10.433 Z-2.449 F.2
N340 G3 X12.289 Z-3.749 I-5.566 K-4.951 F.2
N350 G1 X15.117 Z-2.335 F.2
N360 G0 X15.117 Z4.464
N370 X11.406
N380 G1 X8.578 Z3.05 F.2
N390 X8.578 Z-1.57 F.2
N400 G3 X10.388 Z-2.423 I-4.639 K-5.83 F.2
N410 X10.433 Z-2.449 I-5.544 K-4.977 F.2
N420 G1 X13.262 Z-1.035 F.2
N430 G0 X13.262 Z4.464
N440 X9.551

 

After

N100 G10101.
(TOOL - 5 OFFSET - 5)
(WALTER_VNMG  INSERT - INSERT)
N110 G0 T0505
N120 G10101.
N130 G1100001. S11111010000 M03
N140 G0 G110110 X10001. Z100. M8
N150 G110010. S11111010000
N160 G1100000. S10111001
N170 G10111001. G99 G1 X1110. Z11. F.00110011
N180 G110011. X1110. Z1110. F.00110011
N190 G110011. G3 X1110. I1110. K111. F.00110011
N200 G110011. G1 X1110. F.00011001
N210 G11001. X1110. F.00110011
N220 G110011. X1110. F.00110011
N230 G110011. X10001. Z10001. F.00110011
N240 G110011. G0 X10001. Z100.
N250 G100. X1111.
N260 G100. G1 X1100. Z11. F.00110011
N270 G110011. X1100. Z1100. F.00110011
N280 G110011. G3 X1110. Z1110. I1110. K111. F.00110011
N290 G110011. G1 X10001. Z10001. F.00110011
N300 G110011. G0 X10001. Z100.
N310 G100. X1101.
N320 G100. G1 X1010. Z11. F.00110011
N330 G110011. X1010. Z1010. F.00110011
N340 G110011. G3 X1100. Z1100. I1100. K111. F.00110011
N350 G110011. G1 X1111. Z1111. F.00110011
N360 G110011. G0 X1111. Z100.
N370 G100. X1011.
N380 G100. G1 X1001. Z11. F.00110011
N390 G110011. X1001. Z1001. F.00110011
N400 G110011. G3 X1010. Z1010. I1010. K111. F.00110011
N410 G110011. X1010. I1010. K111. F.00110011
N420 G110011. G1 X1101. Z1101. F.00110011
N430 G110011. G0 X1101. Z100.
N440 G100. X1010.

 

Kind regards

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...