Hello Guest it is March 28, 2024, 07:36:20 PM

Author Topic: Input/Output control as it should be  (Read 1743 times)

0 Members and 1 Guest are viewing this topic.

Input/Output control as it should be
« on: November 17, 2018, 10:34:02 PM »
Hi guys,
For more automated solutions (like a control of the material feeders for lathes or for the collaborating robot control) I need the better control over I/O ports.
Since there's a solution ready in LinuxCNC (M64, M65, M66 commands) I'm trying to recreate them in Mach3 (I don't use Linux for now giving a chance to MAch3).

Can some brainyac check - pretty please - on my code for the M66 macro? It's not working and giving an error on the "Case 3" for no reason...

The code is as follows:

>

Option Explicit

Dim Signal_nr As Integer   'gets signal nr from the P-word
Dim Trigger As Integer  'gets the trigger event variant from the Q-word
Dim Input_nr As String 'to combine SIGNAL string with its number from the P-word for the IsActive command


Signal_nr = Param1() 'Get P-value
Input_nr="INPUT" & Signal_nr 'this one should create a string "SIGNAL#" with the # number from P-word to use as parameter for commands
Select Case Trigger
  
   Case 0 'IMMEDIATE - triggered immediately on the given signal HIGH detection.
      SystemWaitFor(Input_nr)
   
   Case 1 'RISING EDGE - triggered immediately on the given signal RISING EDGE
      While IsActive(Input_nr)
      Wend
      SystemWaitFor(Input_nr)
  
   Case 2 'FALLING EDGE - triggered immediately on the given signal FALLING EDGE
      While IsActive(Input_nr)
   
   Case 3 'HIGH - triggered on the detection of the HIGH state of the signal as opt. 0 but waits for the previous move to finish
      SystemWaitFor(Input_nr)
      While IsMoving()
      Wend
   
   Case 4 'LOW - triggered on the detection of the LOW state of the signal as opt. 1 but waits for the previous move to finish
      While IsActive(Input_nr)
      Wend
      While Ismoving()
      Wend
   
End Select
 
<

Thanks in advance
« Last Edit: November 17, 2018, 10:39:32 PM by marekesz »

Offline TPS

*
  •  2,501 2,501
    • View Profile
Re: Input/Output control as it should be
« Reply #1 on: November 18, 2018, 04:32:15 AM »
try this, not tested just had a look for the Compiler error

Code: [Select]
Option Explicit

Dim Signal_nr As Integer   'gets signal nr from the P-word
Dim Trigger As Integer  'gets the trigger event variant from the Q-word
Dim Input_nr As String 'to combine SIGNAL string with its number from the P-word for the IsActive command


Signal_nr = Param1() 'Get P-value
Trigger = Param2() 'Get the Q-value
Input_nr="INPUT" & Signal_nr 'this one should create a string "SIGNAL#" with the # number from P-word to use as parameter for commands
Select Case Trigger
 
   Case 0 'IMMEDIATE - triggered immediately on the given signal HIGH detection.
      SystemWaitFor(Input_nr)
   
   Case 1 'RISING EDGE - triggered immediately on the given signal RISING EDGE
      While IsActive(Input_nr)
      Wend
      SystemWaitFor(Input_nr)
   
   Case 2 'FALLING EDGE - triggered immediately on the given signal FALLING EDGE
      While IsActive(Input_nr)
      Wend
   
   Case 3 'HIGH - triggered on the detection of the HIGH state of the signal as opt. 0 but waits for the previous move to finish
      SystemWaitFor(Input_nr)
      While IsMoving()
      Wend
   
   Case 4 'LOW - triggered on the detection of the LOW state of the signal as opt. 1 but waits for the previous move to finish
      While IsActive(Input_nr)
      Wend
      While Ismoving()
      Wend
   
End Select

anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.