Hello Guest it is April 18, 2024, 11:52:10 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 - Chaoticone

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 »
631
Mach4 General Discussion / Re: Multiple inputs in LUA script
« on: October 12, 2016, 01:15:30 PM »
Also, where are you putting this script and how are you running it?

Seems to me the script Daz gave you would need to be in a function in the screen load script. Then you would make sure your inputs are setup in the sig lib in the screen load script so that when any of the inputs change states they would run that function.

632
Mach4 General Discussion / Re: Multiple inputs in LUA script
« on: October 12, 2016, 01:03:32 PM »
I realized earlier today that the script I inserted was the first capture and not completely correct as far as the inputs.  Here's the corrected script I've been testing.  I've tested the individual pins changing state with the Set RRO statement and it works fine.  And I've tried the below script with just two inputs and can't get it to work, so i'm thinking it's not the three inputs that's giving me a problem, I think there's something wrong in the wording of the script.

Code: [Select]
local Input14 = 0;
local Input15 = 0;
local Input17 = 0;
local hSig = 0;

hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT14);
Input14 = mc.mcSignalGetState(hSig);

hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT15);
Input15 = mc.mcSignalGetState(hSig);

hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT17);
Input17 = mc.mcSignalGetState(hSig);

if ((Input14 == 1) and (Input15 ==1) and (Input17 == 1)) then
    local inst = mc.mcGetInstance();
    mc.mcCntlSetRRO(inst, 100.0);
end

Bob

So what inputs are you using? 14,15,17 or 18,19,20?

Daz's script should work a treat but if your using different inputs edit the script so its looking at the right ones.

633
Mach4 General Discussion / Re: Multiple inputs in LUA script
« on: October 12, 2016, 12:56:11 PM »
Ok, here is the thing, in the call hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT18) inst is the first parameter required. What is inst? In your script it does not know because you have not defined it yet. You edited it to define it after it was needing defined. So any variable you are using for a parameter must be defined before using it.

The reason it works in the screen load script is because inst is defined at the very beginning of the screen load script.

inst as you can tell by the api call mc.mcGetInstance() is the instance of Mach. Because Mach4 can have multiple instances you need to know what instance you want to get or set. With the exception of a few, all api calls will use the instance parameter for the first parameter.

You only need to define it once within the scope of whatever it is your doing.

That error message is telling you exactly what is going on. It was looking for a number for the instance parameter (defined as mInst for Mach Instance in the api docs) but got a nil because the variable you were using for the instance ("inst") was not defined. All variables in lua are given the value of nil until you overwrite it with something else. So it got a nil when it was needing a number.

But listen, don't feel bad about this. I did this jut a week or so ago myself.  :-[  Tunnel vision may be the death of me. Thankfully another fella loaned me his eyes for a bit and caught it right off.


634
Mach4 General Discussion / Re: Multiple inputs in LUA script
« on: October 12, 2016, 08:07:38 AM »
Where are you defining the inst = mc.mcGetInstance(); before getting the hSig's?

636
Mach4 General Discussion / Re: Macro - Pause until input triggered
« on: September 30, 2016, 04:32:40 PM »
I am going to look at adding an error check module and the necessary bits to make it work in the default profiles. I have done it and tested it already and got it all working with some help from DTG. I had a very simple mistake and just kept overlooking it.  :-[  Garbage in is garbage out and I'm not immune from giving it some garbage myself. I think most when they start out coding have those moments when they want to kick their own butt. Happens to us all I think so remember that when your ready to give up.

Anyway, the m100 discussed earlier in this topic would like this after its all done. I like this much better..........

Code: [Select]
function m100()

local inst, hSig, rc
inst = mc.mcGetInstance()

hSig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1) -- Get handle for output 1
if (rc~= 0) then --Check our errors
mc.mcCntlSetLastError(inst, (mcErrorCheck[rc]))
                --wx.wxMessageBox(mcErrorCheck[rc]) --popup a message box with the error
end

rc = mc.mcSignalSetState(hSig, 1) --turn on output 1
if (rc~= 0) then --Check our errors
mc.mcCntlSetLastError(inst, (mcErrorCheck[rc]))
end

rc = mc.mcSignalWait(inst, mc.ISIG_INPUT21, 1, 5) --Wait 5 seconds for input 21 to become active
if (rc~= 0) then mc.mcCntlSetLastError(inst, (mcErrorCheck[rc])) end --In line check our errors works too

end

if (mc.mcInEditor() == 1) then
    m100()
end


637
Mach4 General Discussion / Re: Macro - Pause until input triggered
« on: September 28, 2016, 03:09:55 PM »
This should work. I changed the time to 5 seconds but you can adjust as needed.

Note, I have it putting the first checks in a MessageBox, the last 2 checks write them to the status bar or message bar in Mach. All of them write a message even if there is no error (MERROR_NOERROR).

Code: [Select]
function m100()

local inst, hSig, rc
inst = mc.mcGetInstance()
hSig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1) -- Get handle for output 1

if (rc == mc.MERROR_NOERROR) then
wx.wxMessageBox("MERROR_NOERROR")
elseif (rc == mc.MERROR_INVALID_INSTANCE) then
wx.wxMessageBox("MERROR_INVALID_INSTANCE")
elseif (rc == mc.MERROR_SIGNAL_NOT_FOUND) then
wx.wxMessageBox("MERROR_SIGNAL_NOT_FOUND")
end

rc = mc.mcSignalSetState(hSig, 1) --turn on output 1

if (rc == mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "MERROR_NOERROR")
elseif (rc == mc.MERROR_INVALID_ARG) then
mc.mcCntlSetLastError(inst, "MERROR_INVALID_ARG")
end

rc = mc.mcSignalWait(inst, mc.ISIG_INPUT21, 1, 5) --Wait 5 seconds for input 21 to become active

if (rc == mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "MERROR_NOERROR")
elseif (rc == mc.MERROR_INVALID_INSTANCE) then
mc.mcCntlSetLastError(inst, "MERROR_INVALID_INSTANCE")
elseif (rc == mc.MERROR_INVALID_ARG) then
mc.mcCntlSetLastError(inst, "MERROR_INVALID_ARG")
elseif (rc == mc.MERROR_NOT_ENABLED) then
mc.mcCntlSetLastError(inst, "MERROR_NOT_ENABLED")
elseif (rc == mc.MERROR_TIMED_OUT) then
mc.mcCntlSetLastError(inst, "MERROR_TIMED_OUT")
end
end

if (mc.mcInEditor() == 1) then
    m100()
end

638
Mach4 General Discussion / Re: Macro - Pause until input triggered
« on: September 28, 2016, 12:02:58 PM »
yay you lot have been busy, glad its working for you now.

DazTheGas

Thanks Daz!

I have not had a use for the mc.mcSignalWait API call yet so hadn't used it beofre but bet I will find a use for it real soon now. :)

Love it when a plan comes together! The devil is in the details. Thankfully the details are covered pretty good in the help file.

639
Mach4 General Discussion / Re: Macro - Pause until input triggered
« on: September 28, 2016, 11:55:11 AM »
Is there a simple way to pause motion until an input is triggered within a macro?  

I would like to ensure my Z axis returns home before the macro ends because after the macro would be an X-Y move. This is a cylinder where I have output 1 activate the "up" direction and output 0 activate the "down" direction.  

Something like this:

1. activate output_1 (up)
2. wait for Z home switch to trigger
3. end macro.

What is the best way to code step 2 (wait for input) in a Macro?

Good, thanks for testing!

This does not do any error checking and the time it waits for the input to go high is indefinite (neither of which are very good ideas) and it does not take your "In automatic Cycle" into account but it should be all that is needed to do what you were looking for originally.

Also note the 2 M100's were changed to m100 so should be saved as m100.mcs. Early on their was some debate about whether or not M codes should be upper or lower case in the scripts themselves. The answer is lower case. It should prevent some possible issues in non Windows OS's.

I would also delete any other M100 files (M100.mcs, M100.mcc, M100.bak) each time you edit the macro and before testing. If not, your changes may not take effect until you do.

Code: [Select]
function m100()
    
    local inst, hSig
    inst = mc.mcGetInstance()
    hSig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1) -- Get handle for output 1
    
    mc.mcSignalSetState(hSig, 1) --turn on output 1
    mc.mcSignalWait(inst, mc.ISIG_INPUT21, 1, 0) --Wait indefinitely (0) for input 21 to become active
  
end

if (mc.mcInEditor() == 1) then
    m100()
end

640
Mach4 General Discussion / Re: Macro - Pause until input triggered
« on: September 28, 2016, 11:02:34 AM »
Nice, thanks!

Does this work as well?

Code: [Select]
function M100()
    
    local inst = mc.mcGetInstance()
    local input_20 = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT20) -- Get handle for input 20
    local input_20_State = mc.mcSignalGetState(input_20) -- Get input 20 state
    
    if input_20 == 0 then
        wx.wxMessageBox("Could not locate signal!")

    else

        if input_20_State == 1 then --If input_20_State equals 1, then the signal is active.
            wx.wxMessageBox("Signal is already active!")

        else    --If input_20_State does not equal 1, then the signal is inactive.
            --wx.wxMessageBox("Setting input_20 high")
            mc.mcSignalSetState(input_20, 1)
   mc.mcSignalWait(inst, mc.ISIG_INPUT21, 1, 0)
        end
    end
end

if (mc.mcInEditor() == 1) then
    M100()
end

Also, just wondering what this is.........  mc.mcSignalSetState(input_20, 1)

Shouldn't that be turning on an output to fire the raise solenoid?

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 »