Hello Guest it is March 29, 2024, 11:19:52 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - joeaverage

Pages: « 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 »
2151
Mach4 General Discussion / Re: when to use rc = ?
« on: August 07, 2019, 08:56:19 PM »
Hi,
ideally you would use rc (return code) on EVERY API call.

Lets take a typical Lua API:

hsig,rc=mc.mcSignalGetHandle(inst,mc.OSIG_OPUTPUT23)

This API requires two parameters (or inputs if you prefer the term) namely an instance number and a number identifying the output
signal for which you want a handle. Note that mc.OSIG_OUTPUT23 actually evaluates to a number.....the text string is called an 'enumeration'
and is done that way because humans remember names better than numbers.

This API has two returns, one is the handle we wanted but also a return code.

When the Lua function, in this case mcSignalGetHandle(), is returned it returns values in the form of a stack. The stack is read from the lefthand most
entry.

Thus:
hsig=mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT23) is perfectly OK. The variable hisg will hold the correct value after the call has been executed.
the variable rc will be on the stack but if you don't read it thats OK.

However:
hsig,rc=mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT23) is also perfectly OK. The variable hsig will have the required handle AND rc will have a return code.

Most of us don't bother with return codes and we consequently get a lot of code errors without understanding why. Expert programmers read return codes EVERY
API call and they have far fewer crashes.

I myself are somewhere in between, certain APIs which give trouble I test completely, others I don't bother.
Also if you write code for a newcomer to Lua then including all the extra code just to read return codes often confuses the newcomer which is definitely
not helpful..........but tends to start a bad habit, namely that of not reading return codes.

Craig

2152
Hi,
good.

You are misreading the syntax......in Lua syntax your API calls have one too many parameters. I think you are confusing the
example in API.chm which is ALWAYS C++ syntax.

Lua syntax is:

Quote
val, rc = mc.mcAxisGetPos(
   number mInst,
   number axisId)

Thus in Lua:
local valX,rc=mc.mcAxisGetMachinePos(inst, mc.X_AXIS)

Whereas C++ syntax is:

Quote
int mcAxisGetPos(
   MINSTANCE mInst,
   int axisId,
   double *val);

Thus the API call would have three parameters, the instance number, the axis number AND a pointer to the data.

Craig

2153
Mach4 General Discussion / Re: Creating M-Code to activate Outputs
« on: August 07, 2019, 05:10:44 AM »
Hi,
whoops, made a mistake, the mc.mcSignalSetState and mc.mcSignalGetState don't need instance parameters:

Code: [Select]
function m101()
local inst=mc.mcGetInstance()
local hsig=mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1)
local current=mc.mcSignalGetState(hsig)
if current ==1 then
      mc.mcSignalSetSate(hsig,0)
else
      mc.mcSignalSetState(hsig,1)
end
end
if (mc.mcInEditor()==1)then
     m101()
end

Craig

2154
Mach4 General Discussion / Re: Tool Table and Tool Changer question
« on: August 07, 2019, 05:03:02 AM »
Hi,
kool!

When Mach interprets Gcode it reduces all letters to lowercase and deletes leading zeros.

Thus 'M05' is actually interpreted m5 and G01 X0.25 is interpreted g1x.25. Note it also strips out blanks but can make
code too hard to read. Mostly if you use uppercase everything works but there are times when it does not, particularly when
Mach searches for a macro, if it doesn't find your M06 it WILL find m6, the built in macro. It pays therefore to use the
format that Mach expects otherwise you'll end up with some extremely hard to find bugs.

Craig

2155
Mach4 General Discussion / Re: Creating M-Code to activate Outputs
« on: August 07, 2019, 12:32:49 AM »
Hi,

Quote
So if I copy that and just change OSIG_OUTPUT1 to OSIG_OUTPUT2 and the m101's to m102's I can control 2 outputs and so on?

Yes, up to output#63

Craig

2156
Hi,
use pound variables or registers.

You update a pound variable (register) with a script. Then you use the format:

mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 X"..#500.."Y"..#501)

where #500 and #501 are the pound variables that hold the values you want. You can do the same thing
more formally using register values which in turn require register handles.

Note I am at work and have not tested this....may do later when I get home.

Craig


2157
Mach4 General Discussion / Re: Creating M-Code to activate Outputs
« on: August 06, 2019, 11:50:25 PM »
Hi,
OK thats easy.

Open the script editor and enter:

Code: [Select]
function m101()
local inst=mc.mcGetInstance()
local hsig=mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1)
local current=mc.mcSignalGetState(inst,hsig)
if current ==1 then
      mc.mcSignalSetSate(inst,hsig,0)
else
      mc.mcSignalSetState(inst,hsig,1)
end
end
if (mc.mcInEditor()==1)then
     m101()
end

Save in the macros folder of your profile as m101.mcs

If in your Gcode file you code m101 then output#1 will turn on, code it a second time and it will turn off.
You will have to use your PoKeys plugin to assign a pin to the output.

Note I am at work and cannot run this through the debugger...may do so when I get home.

Craig

2158
Mach4 General Discussion / Re: Creating M-Code to activate Outputs
« on: August 06, 2019, 10:00:56 PM »
Hi,

Quote
That is more complex than what I am looking for all I want to do is create an M-code that will turn on/off outputs

Then you need to answer the question....do you want to be able to turn off from a button OR do you want to turn them on or
off as part of a Gcode job?

Craig

2159
Mach4 General Discussion / Re: Creating M-Code to activate Outputs
« on: August 06, 2019, 08:59:00 PM »
Hi,
have a look at this thread.....they are sort of related:

https://www.machsupport.com/forum/index.php?topic=41580.0

So the question is whether you want to be able to turn the outputs on or off using m codes which are embedded
in your Gcode program or whether, like the other guy, use a GUI button to turn them on or off.

Note you could do both but would require macros in the macros folder that will be used by Gcode and a basically
indentical function in the screen load script that can be used by the GUI thread. Another way of 'skinning the same cat' is to
have a module.....but start simply and work up to that.

Craig

2160
Mach4 General Discussion / Re: Button script
« on: August 06, 2019, 08:52:10 PM »
Hi,

Quote
Is it possible to call a Macro from a button?

Not quite. Remember, a button is in the GUI and is a part of the GUI chunk. A macro on the other hand is part of the
Gcode interpreter chunk. One chunk or the other runs. It is not possible for a GUI button to call a function that is
in the other chunk.

You have done a good thing, writing it as a macro and testing it out with the editor.

What you need to do is extract the function and call it some other name than m127(), maybe MyFunction(). Note you can
delete the:
if (mc.mcInEditor()==1) then
   m127()
end
from the function.

Now put the function and all its code in the screen load script. Change the called function in the button script to MyFunction().

Thus when you hit the button, being in the GUI chunk, the button script will search for MyFunction() and it will find it in the screenload
script which is also in the same chunk.

Craig

Pages: « 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 »