Macro problem at startup and during program run.

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Macro problem at startup and during program run.

Postby MarcDe » Sun Feb 07, 2021 12:01 pm

First of all, a small introduction. I have built my own milling machine with a UC300 ETH_5LPT card. This machine is running very well for the moment.
20210207_111415.jpg

Now I like to replace some buttons, and integrate it on a small touch screen control panel (Mitsubishi GT2107). I am using the Modbus_TCP protocol.
20210207_111715.jpg

20210207_105834.jpg

95% if this macro is working fine.
I have two problems:
1: when starting the software, the UCCNC software gives a problem that there is something wrong with the macro. When I enter a "Thread.Sleep (30);" at the beginning of this macro, this error no longer occurs. This line does give an extra delay in this macro, so I like to avoid this.
2021-02-07_10-42-30.jpg
2021-02-07_10-42-30.jpg (83.25 KiB) Viewed 11357 times

2: When I run a program it's not longer possible to give a "FEED HOLD" or a "CYCLE STOP" command via the operator panel. I've already looked at this topic on the forum: "http://www.forum.cncdrive.com/viewtopic.php?f=4&t=1506&hilit=modbus" but without a good result.
I am using software version 1.2113.
I am currently testing it in demo mode (DEMO_UC300ETH_5LPT).

M2003.txt
(7.04 KiB) Downloaded 575 times
MarcDe
 
Posts: 12
Joined: Fri Apr 24, 2020 9:41 pm

Re: Macro problem at startup and during program run.

Postby dezsoe » Sun Feb 07, 2021 7:17 pm

For your first question: wait only when the program starts. I've made this little change in your macro. It will wait for the reset to be active when it first starts. The problem is that if the macroloop starts quick enough then there are fields that are not loaded with their initial values. Also, on startup the reset starts inactive. If you wait for the reset at startup then you'll be good.

Code: Select all
// UCCNC Modbus communication
// Mitsubishi GT2107-WTBD HMI operator panel
// Based on examples: DEZSOE, NM156

ushort[] values = new ushort[24];
byte[] fBytes;
ushort ReadValue;
bool ResetLED = AS3.GetLED(25);
bool MistLED = AS3.GetLED(52);
bool FloodLED = AS3.GetLED(53);
bool CyclestartLED = AS3.GetLED(54);
bool IdleLED = AS3.GetLED(18);
bool RunLED = AS3.GetLED(19);

if (FirstRun && !ResetLED)
{
  while (!exec.GetLED(25))
    Thread.Sleep(10);
  ResetLED = exec.GetLED(25);
  FirstRun = false;
}

//Thread.Sleep(30);

if (!ResetLED)
{
   float XDRO   = Convert.ToSingle(AS3.Getfield(226));   // X Work Co.
   fBytes       = BitConverter.GetBytes(XDRO);
   values[0]    = BitConverter.ToUInt16(fBytes, 0);
   values[1]    = BitConverter.ToUInt16(fBytes, 2);

   float YDRO   = Convert.ToSingle(AS3.Getfield(227));   // Y Work Co.
   fBytes       = BitConverter.GetBytes(YDRO);
   values[2]    = BitConverter.ToUInt16(fBytes, 0);
   values[3]    = BitConverter.ToUInt16(fBytes, 2);

   float ZDRO   = Convert.ToSingle(AS3.Getfield(228));   // Z Work Co.
   fBytes       = BitConverter.GetBytes(ZDRO);
   values[4]    = BitConverter.ToUInt16(fBytes, 0);
   values[5]    = BitConverter.ToUInt16(fBytes, 2);

   float FEED   = Convert.ToSingle(AS3.Getfield(867));   // Feed command
   fBytes       = BitConverter.GetBytes(FEED);
   values[6]    = BitConverter.ToUInt16(fBytes, 0);
   values[7]    = BitConverter.ToUInt16(fBytes, 2);

   float SPEED  = Convert.ToSingle(AS3.Getfield(869));   // Speed command
   fBytes       = BitConverter.GetBytes(SPEED);
   values[8]    = BitConverter.ToUInt16(fBytes, 0);
   values[9]    = BitConverter.ToUInt16(fBytes, 2);

   float FACTUAL = Convert.ToSingle(AS3.Getfield(868)); // Feed actual
   fBytes       = BitConverter.GetBytes(FACTUAL);
   values[10]   = BitConverter.ToUInt16(fBytes, 0);
   values[11]   = BitConverter.ToUInt16(fBytes, 2);

   float SACTUAL = Convert.ToSingle(AS3.Getfield(870)); // Speed actual
   fBytes       = BitConverter.GetBytes(SACTUAL);
   values[12]   = BitConverter.ToUInt16(fBytes, 0);
   values[13]   = BitConverter.ToUInt16(fBytes, 2);

   //
   //

   string feedover = AS3.Getfield(232);               // Feed override
   string value = feedover.Substring(0, feedover.Length-1);
   float FOVERRIDE = FEED * (Convert.ToSingle(value) / 100.0F);
   fBytes       = BitConverter.GetBytes(FOVERRIDE);
   values[14]   = BitConverter.ToUInt16(fBytes, 0);
   values[15]   = BitConverter.ToUInt16(fBytes, 2);

   string spinover = AS3.Getfield(233);               // Speed override
   string value2 = spinover.Substring(0, spinover.Length-1);
   float SOVERRIDE = SPEED * (Convert.ToSingle(value2) / 100.0F);
   fBytes       = BitConverter.GetBytes(SOVERRIDE);
   values[16]   = BitConverter.ToUInt16(fBytes, 0);
   values[17]   = BitConverter.ToUInt16(fBytes, 2);

   float XDROM   = Convert.ToSingle(AS3.Getfield(871));   // X Machine Co.
   fBytes        = BitConverter.GetBytes(XDROM);
   values[18]    = BitConverter.ToUInt16(fBytes, 0);
   values[19]    = BitConverter.ToUInt16(fBytes, 2);

   float YDROM   = Convert.ToSingle(AS3.Getfield(872));   // Y Machine Co.
   fBytes        = BitConverter.GetBytes(YDROM);
   values[20]    = BitConverter.ToUInt16(fBytes, 0);
   values[21]    = BitConverter.ToUInt16(fBytes, 2);

   float ZDROM   = Convert.ToSingle(AS3.Getfield(873));   // Z Machine Co.
   fBytes        = BitConverter.GetBytes(ZDROM);
   values[22]    = BitConverter.ToUInt16(fBytes, 0);
   values[23]    = BitConverter.ToUInt16(fBytes, 2);
   
   exec.SetModbusregisters(0, values);   // Write Multiple Registers address 400001 to 400030
}

if(exec.GetModbusregister(30, out ReadValue) & !RunLED)   // Read Holding Register address 400031
{
   int newInputs = ((int)ReadValue & 0xFFFF) ^ 0xFFFF;
   if (lastInputs == 65536) lastInputs = newInputs;
   
   if (newInputs != lastInputs)
   {
      int change = newInputs ^ lastInputs;
        if ((change & 0x01) != 0)      //HOME ALL
        {
         if (((newInputs & 0x01) != 0) != AS3.Getbuttonstate(113))
            exec.Callbutton(113);
        }
        if ((change & 0x02) != 0)      //GOTO ZERO   
        {
         if (((newInputs & 0x02) != 0) != AS3.Getbuttonstate(131))
            exec.Callbutton(131);
        }    
        if ((change & 0x04) != 0)      //ZERO ALL
        {
         if (((newInputs & 0x04) != 0) != AS3.Getbuttonstate(106))
            exec.Callbutton(106);
        }               
        if ((change & 0x08) != 0)      //SAFE Z
        {
         if (((newInputs & 0x08) != 0) != AS3.Getbuttonstate(216))
            exec.Callbutton(216);
        }
        if ((change & 0x10) != 0)      //ZERO X
        {
         if (((newInputs & 0x10) != 0) != AS3.Getbuttonstate(100))
            exec.Callbutton(100);
        }
        if ((change & 0x20) != 0)      //ZERO Y   
        {
         if (((newInputs & 0x20) != 0) != AS3.Getbuttonstate(101))
            exec.Callbutton(101);
        }
        if ((change & 0x40) != 0)      //ZERO Z
        {
         if (((newInputs & 0x40) != 0) != AS3.Getbuttonstate(102))
            exec.Callbutton(102);
        }
        if ((change & 0x80 ) != 0)   //HOME X
        {
         if (((newInputs & 0x80) != 0) != AS3.Getbuttonstate(107))
            exec.Callbutton(107);
        }
        if ((change & 0x100) != 0)   //HOME Y
        {
         if (((newInputs & 0x100) != 0) != AS3.Getbuttonstate(108))
            exec.Callbutton(108);
        }
        if ((change & 0x200) != 0)   //HOME Z
        {
         if (((newInputs & 0x200) != 0) != AS3.Getbuttonstate(109))
            exec.Callbutton(109);
        }       
        if ((change & 0x0400) != 0)   //MIST ON/OFF
        {
         if (((newInputs & 0x0400) != 0) != AS3.Getbuttonstate(508))
            exec.Callbutton(508);   //ON
            else
            exec.Callbutton(509);   //OFF
        }       
        if ((change & 0x0800) != 0)   //COOLANT ON/OFF
        {
         if (((newInputs & 0x0800) != 0) != AS3.Getbuttonstate(510))
            exec.Callbutton(510);   //ON
            else
            exec.Callbutton(511);   //OFF
        }   
        if ((change & 0x1000) != 0)   //CYCLE START
        {
         if (((newInputs & 0x1000) != 0) != AS3.Getbuttonstate(128))
            exec.Callbutton(128);   //ON
        }
        if ((change & 0x2000) != 0)   //Run single line
        {
         if (((newInputs & 0x2000) != 0) != AS3.Getbuttonstate(129))
            exec.Callbutton(129);   //ON
        }       
        if ((change & 0x4000) != 0)   //CYCLE STOP
        {
         if (((newInputs & 0x4000) != 0) != AS3.Getbuttonstate(130))
            exec.Callbutton(130);   //ON         
        }   
        if ((change & 0x8000) != 0)   //FEED HOLD
        {
         if (((newInputs & 0x8000) != 0));// != AS3.Getbuttonstate(522))
            exec.Callbutton(522);   //ON         
        }             
      lastInputs = newInputs;
   }
   
   if(MistLED)      // Toggle Mist button LED address 400036.b0
   {
      lastLEDstatus = lastLEDstatus | 0x01;
   }
   else
   {
      tempValue = 0x01;
      lastLEDstatus = lastLEDstatus & (tempValue ^ 0xFF);
   }

   if(FloodLED)   // Toggle Coolant button LED address 400036.b1
   {
      lastLEDstatus = lastLEDstatus | 0x02;   
   }
   else
   {
      tempValue = 0x02;
      lastLEDstatus = lastLEDstatus & (tempValue ^ 0xFF);   
   }
   
   if(CyclestartLED)   // Toggle Coolant button LED address 400036.b2
   {
      lastLEDstatus = lastLEDstatus | 0x04;   
   }
   else
   {
      tempValue = 0x04;
      lastLEDstatus = lastLEDstatus & (tempValue ^ 0xFF);   
   }
   
   exec.SetModbusregister(35,Convert.ToUInt16(lastLEDstatus));
   
   //Console.WriteLine(lastLEDstatus);   
}
// ------------------------------------------------
#Events
// ------------------------------------------------

static bool FirstRun = false;

int lastInputs = 65536;
int lastLEDstatus = 0;
int tempValue = 0;
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Macro problem at startup and during program run.

Postby dezsoe » Sun Feb 07, 2021 8:51 pm

For your second question. I've found the problem. Somehow you press the cycle start more than once: if the cycle is already started then the exec.Callbutton(128) will not return (and will not detect any buttons!) until you press stop (or reset). So check for the CycleStart LED (54) before you call button 128 and call only if the LED is off.

Code: Select all
      if (!exec.GetLED(54))
        exec.Callbutton(128);
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Macro problem at startup and during program run.

Postby MarcDe » Mon Feb 08, 2021 9:55 am

Thanks for the info. The first problem is solved, there was just one small mistake in your example project, " static bool FirstRun = false; " must be " static bool FirstRun = true; "
About my second question, I can do a "CYCLE START" and a "FEED HOLD" on my operator panel, but I can't do a "CYCLE STOP" when the cycle is running. I still receive the Modbus commands from my HMI when i hit the "CYCLE STOP" button.
2021-02-08_10-48-06.jpg
MarcDe
 
Posts: 12
Joined: Fri Apr 24, 2020 9:41 pm

Re: Macro problem at startup and during program run.

Postby dezsoe » Mon Feb 08, 2021 11:42 am

Sorry, I forgot to switch it back to true. :)

Yes, the Modbus will receive the data, but your macro is stuck, so it will not do anything until you stop the cycle on the screen. I don't see what do you want with the Getbuttonstate checks. Try the original way with one exception: call the start cycle button only if the cycle is not started.

Cycle start:

Code: Select all
        if ((change & 0x1000) != 0)   //CYCLE START
        {
           if (((newInputs & 0x1000) != 0) && !exec.GetLED(54))
              exec.Callbutton(128);   //ON
        }

All others:

Code: Select all
        if ((change & 0x4000) != 0)   //CYCLE STOP
        {
           if ((newInputs & 0x4000) != 0)
              exec.Callbutton(130);   //ON         
        }   

You can watch what's happening with this:

Code: Select all
      if ((change & 0x1000) != 0)  //CYCLE START
      {
        if ((newInputs & 0x1000) != 0)
        {
          exec.AddStatusmessage("Callbutton start");
          exec.Callbutton(128);  //ON
          exec.AddStatusmessage("Callbutton finished");
        }
      }
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Macro problem at startup and during program run.

Postby MarcDe » Tue Feb 09, 2021 8:07 pm

Hi,

I have done some research on the communication between UCCNC software and the HMI.
When I press and release a button on the HMI, the macro interprets this as a double status change. I think the second state change (release button) will remain in the buffer until the first state change (push button) is handled. I think this is the reason why the macro hangs for a certain period of time.

Code: Select all
// UCCNC Modbus communication
// Mitsubishi GT2107-WTBD HMI operator panel
// Based on examples: DEZSOE, NM156

ushort[] values = new ushort[24];
byte[] fBytes;
ushort ReadValue;
bool ResetLED = AS3.GetLED(25);
bool MistLED = AS3.GetLED(52);
bool FloodLED = AS3.GetLED(53);
bool CyclestartLED = AS3.GetLED(54);
bool IdleLED = AS3.GetLED(18);
bool RunLED = AS3.GetLED(19);

 // ----------------------------------------------------------------------------------
 
if (FirstRun && !ResetLED)
{
   while (!exec.GetLED(25))Thread.Sleep(10);
   ResetLED = exec.GetLED(25);
   FirstRun = false;
}

 // ----------------------------------------------------------------------------------
 
if (!ResetLED)
{
   float XDRO   = Convert.ToSingle(AS3.Getfield(226));   // X Work Co.
   fBytes       = BitConverter.GetBytes(XDRO);
   values[0]    = BitConverter.ToUInt16(fBytes, 0);
   values[1]    = BitConverter.ToUInt16(fBytes, 2);

   float YDRO   = Convert.ToSingle(AS3.Getfield(227));   // Y Work Co.
   fBytes       = BitConverter.GetBytes(YDRO);
   values[2]    = BitConverter.ToUInt16(fBytes, 0);
   values[3]    = BitConverter.ToUInt16(fBytes, 2);

   float ZDRO   = Convert.ToSingle(AS3.Getfield(228));   // Z Work Co.
   fBytes       = BitConverter.GetBytes(ZDRO);
   values[4]    = BitConverter.ToUInt16(fBytes, 0);
   values[5]    = BitConverter.ToUInt16(fBytes, 2);

   float FEED   = Convert.ToSingle(AS3.Getfield(867));   // Feed command
   fBytes       = BitConverter.GetBytes(FEED);
   values[6]    = BitConverter.ToUInt16(fBytes, 0);
   values[7]    = BitConverter.ToUInt16(fBytes, 2);

   float SPEED  = Convert.ToSingle(AS3.Getfield(869));   // Speed command
   fBytes       = BitConverter.GetBytes(SPEED);
   values[8]    = BitConverter.ToUInt16(fBytes, 0);
   values[9]    = BitConverter.ToUInt16(fBytes, 2);

   float FACTUAL = Convert.ToSingle(AS3.Getfield(868)); // Feed actual
   fBytes       = BitConverter.GetBytes(FACTUAL);
   values[10]   = BitConverter.ToUInt16(fBytes, 0);
   values[11]   = BitConverter.ToUInt16(fBytes, 2);

   float SACTUAL = Convert.ToSingle(AS3.Getfield(870)); // Speed actual
   fBytes       = BitConverter.GetBytes(SACTUAL);
   values[12]   = BitConverter.ToUInt16(fBytes, 0);
   values[13]   = BitConverter.ToUInt16(fBytes, 2);

   string feedover = AS3.Getfield(232);                  // Feed override
   string value = feedover.Substring(0, feedover.Length-1);
   float FOVERRIDE = FEED * (Convert.ToSingle(value) / 100.0F);
   fBytes       = BitConverter.GetBytes(FOVERRIDE);
   values[14]   = BitConverter.ToUInt16(fBytes, 0);
   values[15]   = BitConverter.ToUInt16(fBytes, 2);

   string spinover = AS3.Getfield(233);                  // Speed override
   string value2 = spinover.Substring(0, spinover.Length-1);
   float SOVERRIDE = SPEED * (Convert.ToSingle(value2) / 100.0F);
   fBytes       = BitConverter.GetBytes(SOVERRIDE);
   values[16]   = BitConverter.ToUInt16(fBytes, 0);
   values[17]   = BitConverter.ToUInt16(fBytes, 2);

   float XDROM   = Convert.ToSingle(AS3.Getfield(871));   // X Machine Co.
   fBytes        = BitConverter.GetBytes(XDROM);
   values[18]    = BitConverter.ToUInt16(fBytes, 0);
   values[19]    = BitConverter.ToUInt16(fBytes, 2);

   float YDROM   = Convert.ToSingle(AS3.Getfield(872));   // Y Machine Co.
   fBytes        = BitConverter.GetBytes(YDROM);
   values[20]    = BitConverter.ToUInt16(fBytes, 0);
   values[21]    = BitConverter.ToUInt16(fBytes, 2);

   float ZDROM   = Convert.ToSingle(AS3.Getfield(873));   // Z Machine Co.
   fBytes        = BitConverter.GetBytes(ZDROM);
   values[22]    = BitConverter.ToUInt16(fBytes, 0);
   values[23]    = BitConverter.ToUInt16(fBytes, 2);
   
   exec.SetModbusregisters(0, values);               // Write Multiple Registers address 400001 to 400030
}

 // ----------------------------------------------------------------------------------
 
if(exec.GetModbusregister(30, out ReadValue) & !RunLED)   // Read Holding Register address 400031
{
   int newInputs = ((int)ReadValue & 0xFFFF) ^ 0xFFFF;
   if (lastInputs == 65536) lastInputs = newInputs;
   
   if (newInputs != lastInputs)
   {
      int change = newInputs ^ lastInputs;
     Console.WriteLine(change);
    
     switch (change)
      {
      case 0x1:                  //HOME ALL
         exec.Callbutton(113);
         break ;
      case 0x2:                  //GOTO ZERO
         exec.Callbutton(131);
         break ;
      case 0x4:                  //ZERO ALL
         exec.Callbutton(106);
         break ;
      case 0x8:                  //SAFE Z
         exec.Callbutton(216);
         break ;
      case 0x10:                  //ZERO X
         exec.Callbutton(100);
         break ;
      case 0x20:                  //ZERO Y
         exec.Callbutton(101);
         break ;
      case 0x40:                  //ZERO Z
         exec.Callbutton(102);
         break ;
      case 0x80:                  //HOME X
         exec.Callbutton(107);
         break ;
      case 0x100:                  //HOME Y
         exec.Callbutton(108);
         break ;
      case 0x200:                  //HOME Z
         exec.Callbutton(109);
         break ;
      case 0x400:                  //MIST ON/OFF
          {
            if ((newInputs & 0x0400) != 0) exec.Callbutton(508);   
            else exec.Callbutton(509);                        
         }
         break ;
      case 0x800:                  //COOLANT ON/OFF
          {
            if ((newInputs & 0x0800) != 0) exec.Callbutton(510);      
            else exec.Callbutton(511);                        
         }        
         break ;
      case 0x1000:               //CYCLE START
          {
            if (((newInputs & 0x1000) != 0) && !exec.GetLED(54))
            {
               exec.AddStatusmessage("Callbutton start");
               exec.Callbutton(128); 
               exec.AddStatusmessage("Callbutton finished");
            }      
         }
         break ;
      case 0x2000:               //SINGLE LINE
         exec.Callbutton(129);
         break ;
      case 0x4000:               //CYCLE STOP
         exec.Callbutton(130);
         break ;
      case 0x8000:               //FEED HOLD
         exec.Callbutton(522);
         break ;         
      }
    lastInputs = newInputs;
   }
   
 // ---------------------------------------------------------------------------------- 
 
   if(MistLED)                     // Toggle Mist button LED address 400036.b0
   {
      lastLEDstatus = lastLEDstatus | 0x01;
   }
   else
   {
      tempValue = 0x01;
      lastLEDstatus = lastLEDstatus & (tempValue ^ 0xFF);
   }

   if(FloodLED)                     // Toggle Coolant button LED address 400036.b1
   {
      lastLEDstatus = lastLEDstatus | 0x02;   
   }
   else
   {
      tempValue = 0x02;
      lastLEDstatus = lastLEDstatus & (tempValue ^ 0xFF);   
   }
   
   if(CyclestartLED)                  // Toggle Coolant button LED address 400036.b2
   {
      lastLEDstatus = lastLEDstatus | 0x04;   
   }
   else
   {
      tempValue = 0x04;
      lastLEDstatus = lastLEDstatus & (tempValue ^ 0xFF);   
   }
   exec.SetModbusregister(35,Convert.ToUInt16(lastLEDstatus));
   
}

 // ----------------------------------------------------------------------------------
 
#Events

 // ----------------------------------------------------------------------------------

static bool FirstRun = true;

int lastInputs = 65536;
int lastLEDstatus = 0;
int tempValue = 0;


Modbus communication

2021-02-09_20-14-28.jpg


Console

2021-02-09_20-31-44.jpg
MarcDe
 
Posts: 12
Joined: Fri Apr 24, 2020 9:41 pm

Re: Macro problem at startup and during program run.

Postby MarcDe » Wed Feb 10, 2021 11:54 am

From my point of view, once UCCNC is in a cycle, it is no longer possible to process other commands in this macro until the cycle is complete. Or, would it be possible to put the cycle stop command in a separate macro? I haven't tried this yet. If you use multiple macros, do they work completely independently or not (multitasking)?
MarcDe
 
Posts: 12
Joined: Fri Apr 24, 2020 9:41 pm

Re: Macro problem at startup and during program run.

Postby MarcDe » Wed Feb 10, 2021 12:12 pm

Placing the command "CYCLE STOP" in a separate macro does not work.
MarcDe
 
Posts: 12
Joined: Fri Apr 24, 2020 9:41 pm

Re: Macro problem at startup and during program run.

Postby dezsoe » Wed Feb 10, 2021 3:05 pm

OK, let's start it from the beginning. As I wrote, the original macro works fine, except the double cycle start. The conditions were written to only press a button once. You changed the conditions, so now it does not work, because the cycle start button is called twice (or more than once) and the exec.Callbutton(128) will not return until you stop/reset. Here I wrote a code snippet for you to see how the input check works:

Code: Select all
if (newInputs != lastInputs)
{
  // change will contain 1s where the new and the last input states differ
  // checking a bit in change will show if that button/switch state changed:
  //   the button was pressed or released or a switch was switched
  int change = newInputs ^ lastInputs;

  // NC reset switch -> force reset to switch state
  if ((change & 0x01) != 0)
  {
    // the state changed -> will not only press a button, but change the state
    // if the input goes low then turn on reset mode
    // if the input goes high then turn off reset mode
    if ((newInputs & 0x01) != 0)
      exec.Callbutton(513);
    else
      exec.Callbutton(512);
  }

  // Compare SPST switch state to screen button state -> press button if needed
  if ((change & 0x02) != 0)
  {
    // you have a switch and a function: the state of the switch determines
    //   the new state of the function
    // here AS3.Getbuttonstate was used, but not all functions can be checked this way
    // some functions have to be checked by exec.GetLED
    // (you can check all functions by exec.GetLED)
    // the following example will only press button 114 if the state of the switch
    //   is not equal to the state of the function
    if (((newInputs & 0x02) != 0) != AS3.Getbuttonstate(114))
      exec.Callbutton(114);
  }

  // NO pushbutton
  if ((change & 0x04) != 0)
  {
    // general pushbutton: when you press it then it calls the button
    // calls only if the state of the input goes high!
    if ((newInputs & 0x04) != 0)
      exec.Callbutton(130);                                                     // Button pressed
  }

  // Special NO pushbutton for Cycle Start
  if ((change & 0x04) != 0)
  {
    // when you press it and the cycle is not started then it calls the button
    // calls only if the state of the input goes high and the cycle is not started!
    if (((newInputs & 0x04) != 0) && !exec.GetLED(54))
      exec.Callbutton(128);
  }

  // save the current state of the inputs for the next check
  lastInputs = newInputs;
}
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Macro problem at startup and during program run.

Postby MarcDe » Wed Feb 10, 2021 3:26 pm

Hi Dezsoe,

I think there is a little misunderstanding, the "Cycle Start" always worked, the only thing what's not working is the "Cycle Stop" command. All the rest is working. And this was also my question from te beginning. The only thing I have done is cleanig up my program and use a "Select Case" instead of all the "If" commands. There is no difference between the first and tha last version about behavior. I am not so a C# guru like you. :)
MarcDe
 
Posts: 12
Joined: Fri Apr 24, 2020 9:41 pm

Next

Return to Macros

Who is online

Users browsing this forum: No registered users and 3 guests