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.

Re: Macro problem at startup and during program run.

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

Latest version

I've put also an extra line of code to avoid doubble input.
This about te explination I sended you yesterday.

Code: Select all
if (newInputs != lastInputs)
   {
      int change = newInputs ^ lastInputs;
    
     if(ReadValue == 0) change = 0;
    
     Console.WriteLine(ReadValue);
     Console.WriteLine(change);
    
     switch (change) .................
      


I had this problem with all the buttons I hit.

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;    
     if(ReadValue == 0) change = 0;
    
     Console.WriteLine(ReadValue);
     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");
            }      
         }
         exec.Callbutton(128);
         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;
MarcDe
 
Posts: 11
Joined: Fri Apr 24, 2020 9:41 pm

Re: Macro problem at startup and during program run.

Postby MarcDe » Wed Feb 10, 2021 4:47 pm

Small mistake in my latest program, but same result.


Code: Select all
      case 0x1000:               //CYCLE START
          {
            if (!exec.GetLED(54))
            {
            Console.WriteLine(change);
               exec.AddStatusmessage("Callbutton start");
               exec.Callbutton(128); 
               exec.AddStatusmessage("Callbutton finished");
            }      
         }
         break ;
MarcDe
 
Posts: 11
Joined: Fri Apr 24, 2020 9:41 pm

Re: Macro problem at startup and during program run.

Postby MarcDe » Wed Feb 10, 2021 5:54 pm

Hi,

Now I've integrated your sample project into mine and uninstalled the rest of the program which is not needed.
I can start the cycle, but I cannot stop it. I have to stop the cycle on my pc.

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(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;

      // NO pushbutton   CYCLE STOP

      if ((change & 0x4000) != 0)
      {
         if ((newInputs & 0x4000) != 0)
         {
         exec.Callbutton(130);
         Console.WriteLine(change);
         }
      }
      
      // Special NO pushbutton for CYCLE START

      if ((change & 0x1000) != 0)
      {
         if (((newInputs & 0x1000) != 0) && !exec.GetLED(54))
         {
         exec.Callbutton(128);
         Console.WriteLine(change);
         }
      }
      lastInputs = newInputs;
   } 
}

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

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

static bool FirstRun = true;

int lastInputs = 65536;
int lastLEDstatus = 0;
int tempValue = 0;
MarcDe
 
Posts: 11
Joined: Fri Apr 24, 2020 9:41 pm

Re: Macro problem at startup and during program run.

Postby dezsoe » Wed Feb 10, 2021 6:27 pm

With this line you don't read the keys if the controller is working:

Code: Select all
if(exec.GetModbusregister(30, out ReadValue) & !RunLED)   // Read Holding Register address 400031

You don't need the whole condition. LED #19 is on when the controller is working. Don't mix it with LED #54 which is on when cycle is started.
dezsoe
 
Posts: 1341
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 7:19 pm

Hello Dezsoe,

IT'S WORKING!!!!!!

I removed "&! RunLED" as you explained, and it works. To avoid those time consuming questions, is there any literature or sample projects available where I can find those tips and tricks?
The documentation I have is the "UCCNC MACROS - 1-2113 - REV A.pdf".

MANY THANKS!!! ... I owe you a beer. :D :D :D
MarcDe
 
Posts: 11
Joined: Fri Apr 24, 2020 9:41 pm

Re: Macro problem at startup and during program run.

Postby dezsoe » Wed Feb 10, 2021 10:23 pm

Hello MarcDe,

I'm happy you got it working.

You can find many sample codes even here on this forum and Rob's manual is also very useful, but only practice can teach you. I started programming almost 40 years ago, but I still learn every day. I write a program and only a half year later I can improve it... :)
dezsoe
 
Posts: 1341
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Previous

Return to Macros

Who is online

Users browsing this forum: No registered users and 2 guests