Quantcast
Channel: SharpDevelop Community
Viewing all articles
Browse latest Browse all 1764

Lost information when call a funtion for secondtime

$
0
0

I hav app when i call the first time de function everything is ok but when i call for second time the values y selected gone..

 

here my code

        publicclassCaptRegSeries
        {
            publicComboBoxcmboxVariable;
            publicCheckBoxchkEnabled;
            
            publicCaptRegSeries(ComboBox cmboxvariable,  CheckBox chkenabled)
            {
                this.cmboxVariable = cmboxvariable;
                this.chkEnabled = chkenabled;
            }
        }

 

    public  List<CaptRegSeries> CaptureSeriesIndex = newList<CaptRegSeries>();

 

this for select what combobox seleted you can see is public.

 

after select all i push button Run all is ok bust be take 100 values. and then call ejecutatunning again but this time what i selected is gone CaprureSeriesIdex isnull.

 

/*
 * Created by SharpDevelop.
 * User: ***
 * Date: 6/16/2016
 * Time: 4:27 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;
using System.Windows.Forms.DataVisualization.Charting;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Threading;
using System.Linq;

namespace editorlcc
{
    ///<summary>
    /// Description of Formtunning.
    ///</summary>
    publicpartialclassFormtunning : Form
    {
        privateMainFormmform;
        privatestringPrggen = string.Empty;
        privatestringnextM = string.Empty;
        privateintsamples=0;
        privateDecimalloops=0;
        publicintcharIndexser=0;
        publicintcharIndex=-1;
        
        publicclassregdatos
        {
            publicregdatos( string Regname, string Registro, string Regtipo, bool Actibado, string Descripcion)
            {
                this.regname= Regname;
                this.registro= Registro;
                this.regtipo=Regtipo;
                this.activado=Actibado;
                this.descripcion=Descripcion;
            }
            publicstring regname{ set; get;}
            publicstring registro{ set; get;}
            publicstring regtipo{ set; get;}
            publicbool   activado{ get; set;}
            publicstring descripcion{get; set;}
        }
            
        publicList<regdatos> lstregs = newList<regdatos>();

        publicclassCaptRegSeries
        {
            publicComboBoxcmboxVariable;
            publicCheckBoxchkEnabled;
            
            publicCaptRegSeries(ComboBox cmboxvariable,  CheckBox chkenabled)
            {
                this.cmboxVariable = cmboxvariable;
                this.chkEnabled = chkenabled;
            }
        }
        public  List<CaptRegSeries> CaptureSeriesIndex = newList<CaptRegSeries>();
        
        publicFormtunning(MainForm mform)
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();
            this.mform = mform;
            mform.updatedcharvalues += newMainForm.updatecharseries(updateseriesvalues);
            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //
        }
        
        privatedelegatevoid ObjectDelegate(object obj);
        
        voidFormtunningLoad(object sender, EventArgs e)
        {
            lstregs.Add( newregdatos("V","462","LONG",false,"Temporal Velocity TV"));
            lstregs.Add( newregdatos("DESP","480","LONG",false,"Desired Position TT"));
            lstregs.Add( newregdatos("CARP","486","LONG",false,"Temporal Desired Position TO"));
            lstregs.Add( newregdatos("CURP","494","LONG",false,"Current Real Position TP"));
            int nr;
            cBoxY1.Items.Clear();
            cBoxY2.Items.Clear();
            cBoxY3.Items.Clear();
            cBoxY4.Items.Clear();
            for(nr =0; nr <= lstregs.Count-1;nr++)
            {
                cBoxY1.Items.Add(lstregs[nr].regname);
                cBoxY2.Items.Add(lstregs[nr].regname);
                cBoxY3.Items.Add(lstregs[nr].regname);
                cBoxY4.Items.Add(lstregs[nr].regname);
                  
            }
            
            CaptureSeriesIndex.Add(newCaptRegSeries(this.cBoxY1, this.chkBoxy1 ));
            CaptureSeriesIndex.Add(newCaptRegSeries(this.cBoxY2, this.chkBoxy2 ));
            CaptureSeriesIndex.Add(newCaptRegSeries(this.cBoxY3, this.chkBoxy3 ));
            CaptureSeriesIndex.Add(newCaptRegSeries(this.cBoxY4, this.chkBoxy4 ));
            
            chart1.Series[0].Points.Clear();
            chart1.Series[1].Points.Clear();
            chart1.Series[2].Points.Clear();
            chart1.Series[3].Points.Clear();
            
           
            btnRun.Enabled=false;
            cBoxY1.Enabled=false;
            cBoxY2.Enabled=false;
            cBoxY3.Enabled=false;
            cBoxY4.Enabled=false;
            chkBoxy1.Enabled=false;
            chkBoxy2.Enabled=false;                 
            chkBoxy3.Enabled=false;
            chkBoxy4.Enabled=false;

        }
    
 
        
        privatestring SiDifValues
        {
            get{ returntBSiDif.Text ;}
            set { tBSiDif.Text = value;}
        }

      
        privatestring SIintValues
        {
            get{ returntBSiInt.Text ;}
            set { tBSiInt.Text = value;}
        }        
        privatestring StrockeValues
        {
            get{ returntBStrock.Text ;}
            set { tBStrock.Text = value;}
        }
        
        privatestring SGValues
        {
            get{ returntBSG.Text ;}
            set { tBSG.Text = value;}
        }
        privatestring SPValues
        {
            get{ returntBSpeed.Text ;}
            set { tBSpeed.Text = value;}
        }
      privatestring EncResValues
        {
            get{ returntBEncRes.Text ;}
            set { tBEncRes.Text = value;}
        }    

        privatestring OffSetValues
        {
            get{ returntBOffset.Text ;}
            set { tBOffset.Text = value;}
        }
        
        privatestring ACCValues
        {
            get{ returntBAcce.Text ;}
            set { tBAcce.Text = value;}
        }  
        privatestring SQMaxValues
        {
            get{ returntBSqMax.Text ;}
            set { tBSqMax.Text = value;}
        }  
       privatestring SQMinValues
        {
            get{ returntBSqMin.Text ;}
            set { tBSqMin.Text = value;}
        }       
       
         privatestring ILValues
        {
            get{ returntBILimit.Text ;}
            set { tBILimit.Text = value;}
        }  
        privatestring SEValues
        {
            get{ returntBSe.Text ;}
            set { tBSe.Text = value;}
        } 
        
        privatestring DIValues
        {
            get{ returncBDirec.SelectedText ;}
            set { cBDirec.SelectedItem = value;}
        }   
        
        privatestring PosErValues
        {
            get{ returntBPosEr.Text ;}
            set {tBPosEr.Text = value;}
        }
        
        
        voidBtnCloseClick(object sender, EventArgs e)
        {

             this.mform.port.WriteString("MF");
            System.Threading.Thread.Sleep(40);             
             this.mform.port.WriteString(((char) 27).ToString()+"");
            this.Close();
        }
        
      here i call procedure ejecutatunning. all is good from here.

    
        voidBtnRunClick(object sender, EventArgs e)
        {
    
            if( !mform.port.IsOpen()) return;
            
             if (!this.chkBoxy1.Checked && !this.chkBoxy2.Checked && !this.chkBoxy3.Checked && !this.chkBoxy4.Checked)
             {
                MessageBox.Show("Error: All capture items are disabled. Enable at least one of them.", "Can not start capture", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
             }
             
             
             foreach (Series current inthis.chart1.Series)
             {
                current.Points.Clear();
             }
             Globals.CaptureIndex = -1;
             Globals.capturedata = true;

              ejecutetunning();
    
                        
            
        }
        
        privatevoidejecutetunning()
        {
            
            Globals.lastcommand="CD";
            Globals.capturedata=true;
            string RegValFind = string.Empty;
            
            CaptRegSeries CaptRegSeriesItem;
            while (true)
            {
                Globals.CaptureIndex++;
                if (Globals.CaptureIndex< this.CaptureSeriesIndex.Count)
                {
                    CaptRegSeriesItem = this.CaptureSeriesIndex[Globals.CaptureIndex];
                    if (CaptRegSeriesItem.chkEnabled.Checked)
                    {
                        Globals.capturedata = true;
                        break;
                    }
                }
                else
                {
                    Globals.capturedata = false;
                }
            }
            if( Globals.capturedata)
            {
               
              samples=Convert.ToInt32(this.tBSample.Text);
               loops=Convert.ToDecimal(this.tBLoop.Text);
              System.Threading.Thread.Sleep(40);

              mform.port.WriteString("AL" + ((int)(this.samples / this.loops)).ToString() + ",WW422");            
              System.Threading.Thread.Sleep(40);                
              RegValFind =cBoxY1.Text;
              this.Invoke((Action)(() => RegValFind = CaptureSeriesIndex[Globals.CaptureIndex].cmboxVariable.Text));

              string RegNum=GetRegValue(RegValFind);
              mform.port.WriteString("AL" + RegNum + ",WW424");
              System.Threading.Thread.Sleep(60);                
              mform.port.WriteString("AL0"  + ",WW426");    
              System.Threading.Thread.Sleep(60);                
              mform.port.WriteString("MS"  + Convert.ToInt32(this.tBStartMacro.Text).ToString()+"");    
              System.Threading.Thread.Sleep(2000);
              mform.port.WriteString(((char) 27).ToString()+"");
              System.Threading.Thread.Sleep(60);        
              mform.port.WriteString(((char) 27).ToString()+"");            
              System.Threading.Thread.Sleep(60);                      
              mform.port.WriteString("DD100");
              Globals.lastcommand="CD";
              Globals.capturedata=true;              
               
            }
          
        }
         
        privatestringGetRegValue( string RegName)
        {   int i;
            for( i =1 ; i < lstregs.Count; i++)
                if( RegName == lstregs[i].regname )
            {
                returnlstregs[i].registro;
            }
             return"";
        }

        privatevoidupdateseriesvalues(int dato)
        {
        
            this.chart1.Series[Globals.CaptureIndex].Points.AddXY((Double)charIndexser,(double)dato);
            
            charIndexser++;
            if(charIndexser> 99)
            {
        //        charIndex++;
                charIndexser=0;
                ejecutetunning();

call second time but i call from here lost the selection option in combo box.


            }
            return;
        }
        
    
        voidCBoxY1SelectedIndexChanged(object sender, EventArgs e)
        {
           cBoxY2.Items.Remove(cBoxY1.Text);
           cBoxY3.Items.Remove(cBoxY1.Text);
           cBoxY4.Items.Remove(cBoxY1.Text);
           chkBoxy1.Checked=true;
        }
        voidCBoxY2SelectedIndexChanged(object sender, EventArgs e)
        {
           cBoxY3.Items.Remove(cBoxY2.Text);
           cBoxY4.Items.Remove(cBoxY2.Text);
           chkBoxy2.Checked=true;
        }
        voidCBoxY3SelectedIndexChanged(object sender, EventArgs e)
        {
           cBoxY4.Items.Remove(cBoxY3.Text);
           chkBoxy3.Checked=true;
        }

        voidCBoxY4SelectedIndexChanged(object sender, EventArgs e)
        {
           chkBoxy4.Checked=true;
        }
        
        voidBtnSendprgClick(object sender, EventArgs e)
        {

            btnSendprg.Enabled=false;
            if(mform.port.IsOpen())
            {
//               mform.port.DisableHandler();
               Globals.lastcommand="HOMING";
               mform.port.WriteString(((char) 27).ToString()+"");

               mform.port.WriteString("AB");
               System.Threading.Thread.Sleep(100);        
               mform.port.WriteString("MF");
               System.Threading.Thread.Sleep(100);        
               
               Globals.fmresult.richTextBoxEx1.Clear();                                  
               mform.port.WriteString("RM");
               System.Threading.Thread.Sleep(600);               
               mform.port.WriteString("MD0,1VM,MN,SG50,SI50,SD2000,OO0,SV26214,SA5243,SQ15000,IL8000,SE12000,DI1,GO,WA5");
               System.Threading.Thread.Sleep(180);               
               mform.port.WriteString("MD1,RW538,IB-200,NO,MJ2,RP");
               System.Threading.Thread.Sleep(160);                             
               mform.port.WriteString("MD2,DH,DI0,FI,AL0,WL1830");
               System.Threading.Thread.Sleep(160);               
               mform.port.WriteString("MD3,RL448,IC10,ST,MJ5,RL494,IG1000,NO,MJ4,RL1830,IG3000,NO,MJ4,RP");
               System.Threading.Thread.Sleep(160);               
               mform.port.WriteString("MD4,MF,MG\"Index NO Found\",EP");
               System.Threading.Thread.Sleep(160);                  
               mform.port.WriteString("MD5,PM,MN,GH,MG\"HOME READY\"");
               System.Threading.Thread.Sleep(160);               
               string MacFol = Convert.ToInt32(tBStartMacro.Text).ToString();


               long SV=Convert.ToInt32(SPValues);
               SV=(SV*13107200)*100;
               SV=(SV/(Convert.ToInt32(EncResValues)*100000));
               double ACC=Convert.ToInt32(SPValues);
               ACC=(ACC*2621.44)*10;
               ACC=Convert.ToInt32( ACC/Convert.ToInt32(EncResValues));
               Prggen +="MD" +MacFol +","+"CS100,CD100,"+cBAxes.SelectedItem.ToString()+"VM,MN,SV"+SV.ToString()+",SA"+ACC.ToString()+",SQ"+SQMaxValues+",SE"+PosErValues+",MA0"+",GO,WS20";
               mform.port.WriteString(Prggen+"");
               System.Threading.Thread.Sleep(180);               
               Prggen=string.Empty;
            
               MacFol = (Convert.ToInt32(tBStartMacro.Text)+1).ToString();
               nextM = (Convert.ToInt32(tBStartMacro.Text)+2).ToString();
               long PE=Convert.ToInt32(PosErValues);
               PE=(PE/Convert.ToInt32(EncResValues));
               float SQ=Convert.ToInt32(SQMaxValues);
               float ERL=6f/ 30f;
               Int32 SQR=Convert.ToInt32((SQ*ERL));
                        
               Prggen += "MD"+MacFol+",VM,MN,SV"+SV.ToString() ;
               Prggen += ",SA"+ACC.ToString()+",SQ"+SQMinValues+",DI"+cBDirec.SelectedItem.ToString()+",SQ"+SQR.ToString()+",GO,WA100"+",SQ2809";
               mform.port.WriteString(Prggen+"");
               System.Threading.Thread.Sleep(160);               

               Prggen=string.Empty;
            
               MacFol = (Convert.ToInt32(tBStartMacro.Text)+2).ToString();
               nextM = (Convert.ToInt32(tBStartMacro.Text)+3).ToString();
               if( Convert.ToInt32(cBDirec.SelectedItem.ToString()) ==0)
               {
                 Prggen +="MD"+MacFol+",RW538,IG"+Convert.ToInt32(tBPosEr.Text).ToString()+",AB,MJ"+nextM+",RP";
                 mform.port.WriteString(Prggen+"");
                System.Threading.Thread.Sleep(160);               

               }
               else
               {
                 Prggen +="MD"+MacFol+",RW538,IB"+Convert.ToInt32(tBPosEr.Text).ToString()+",AB,MJ"+nextM+",RP";
                 mform.port.WriteString(Prggen+"");            
                System.Threading.Thread.Sleep(160);               

               }

               Prggen=string.Empty;
                        
               MacFol = (Convert.ToInt32(tBStartMacro.Text)+3).ToString();
               nextM = (Convert.ToInt32(tBStartMacro.Text)+4).ToString();
               Prggen+= "MD"+MacFol+",PM,SV"+SV.ToString()+",SA"+ACC.ToString()+",SQ"+SQMaxValues+",GH,WS,EP,DD100";
               mform.port.WriteString(Prggen+"");
               System.Threading.Thread.Sleep(160);               
               Prggen=string.Empty;
               mform.port.WriteString("MS0");

               btnRun.Enabled=true;    
               cBoxY1.Enabled=true;
               cBoxY2.Enabled=true;
               cBoxY3.Enabled=true;
               cBoxY4.Enabled=true;
               chkBoxy1.Enabled=true;
               chkBoxy2.Enabled=true;                 
               chkBoxy3.Enabled=true;
               chkBoxy4.Enabled=true;
               cBoxY1.Focus();
//               mform.port.EnableHandler();
             
            }
        }
        
        voidFormtunningShown(object sender, EventArgs e)
        {
    //     private CaptRegSeries CaptRegSeriesItem;
        }
        
        
    }
}

 

give me idea what i doing wront i when call 4 times ejecutatunning procedure.

 

thanks.


Viewing all articles
Browse latest Browse all 1764

Trending Articles