aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Properties/Resources.Designer.cs
blob: fb62b4ba4fae5344d5ba396a2e53b8030a9f1abc (plain)
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
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Tango.MachineStudio.RML.Properties {
    
    
    /// <summary>
    ///   A strongly-typed resource class, for looking up localized strings, etc.
    /// </summary>
    // This class was auto-generated by the StronglyTypedResourceBuilder
    // class via a tool like ResGen or Visual Studio.
    // To add or remove a member, edit your .ResX file then rerun ResGen
    // with the /str option, or rebuild your VS project.
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    internal class Resources {
        
        private static global::System.Resources.ResourceManager resourceMan;
        
        private static global::System.Globalization.CultureInfo resourceCulture;
        
        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal Resources() {
        }
        
        /// <summary>
        ///   Returns the cached ResourceManager instance used by this class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager {
            get {
                if ((resourceMan == null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Tango.MachineStudio.RML.Properties.Resources", typeof(Resources).Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }
        
        /// <summary>
        ///   Overrides the current thread's CurrentUICulture property for all
        ///   resource lookups using this strongly typed resource class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Globalization.CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }
    }
}
color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Drawing;
using Google.Protobuf;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
using Tango.PMR.Stubs;
using Tango.PMR.Diagnostics;
using Tango.FSE.Common.Connection;
using Tango.FSE.Common.Diagnostics;
using Tango.FSE.Procedures;
using System.IO;
using System.Windows.Forms;
using Tango.PMR.EmbeddedParameters;

public class Program
{
const double	MIN_SLOP=0.7;
const double	MAX_SLOP=1.4;
const double	ERROR_SLOP=-1;
const double	MIN_50cc_on_volt=2.3;
const double	MAX_50cc_on_volt=3.2;
const double	ERROR_50cc_on_volt=-1;

int [] Convert_Midtank_No = new Int32 [8] {1,3,5,7,2,4,6,8};
uint [,] ADC_Add_Chnl = new uint [8,2]	{
												{0x44,0x20},				
												{0x44,0x08},				
												{0x46,0x80},
												{0x46,0x20},
												{0x44,0x10},
												{0x44,0x04},
												{0x46,0x40},
												{0x46,0x10},
										};


const Int32	F3_VALVE_OUT	=	0x600008E2	;
string Machine_SN	;
private const string FILE_PATH = @"C:\MidTankLog\";
string File_name;
double Full_Cartridge=1000;	// on CC 
double 	Slop=0.92;
//----------------------
const Int32 I2C_ID =  2;
//const Int32 I2C_Slave_Add = 0x46; //must be 0x40, 0x44 or 0x46
//----------------------


private IProcedureContext context;




    public void OnExecute(IProcedureContext context)
    {
      

	Int32 Timout ;
	Int32 Interval;
	Int32 midtankno = 0;
	double Full_Point=0;			//on Voltage
	double resualt;
	double Sum=0 ;
	double Old_Sum=0 ;
	double Start_Point=0;
	

	if (!Directory.Exists(FILE_PATH))
		{
			Directory.CreateDirectory(FILE_PATH);
		}			



    var response =context.RequestUserInputFor<String>("Enter Midtank S/N: ", "");
	context.Write("\n");
	Machine_SN = response;
	context.WriteLine(Machine_SN);
	File_name= FILE_PATH +Machine_SN + DateTime.Now.ToString("MM_dd_yyyy_HH_mm_ss")+".csv";
	context.Write(File_name);
 	context.WriteToFile(File_name,"MidTank S/N:," + Machine_SN);
	

    var response1 =context.RequestUserInputFor<String>("Enter Midtank number to calibrate  (1-8):", "");
   context.WriteLine(response1);
	midtankno = Int32.Parse(response1);
 	context.AppendToFile(File_name,"MidTank Number:\t" + response1);
	if (midtankno==8)
	{
		Slop=1;
		Timout=60;		//60 minutes
		Interval=60;	//60 second
	}
	else
	{
		Slop=0.92;
		Timout=10*2;		//10 minutes
		Interval=30;	//30 second

	}
    var response10 =context.RequestUserInputFor<String>("Enter Cartridge Valume on CC  (500-1500):", "");
   context.WriteLine(response10);
	Full_Cartridge = double.Parse(response10);
 	context.AppendToFile(File_name,"Cartridge Valume:\t" + response10);
 	context.AppendToFile(File_name,"Slop value:\t" + Slop);


	DialogResult result = MessageBox.Show("Are you sure to calibrate Midtank No: "+ midtankno + " with "+ Full_Cartridge +" CC" , "Warning",MessageBoxButtons.YesNo);
	if(result == DialogResult.Yes)
	{



		string box_msg = "Please Insert cartridge ";

		MessageBox.Show(box_msg);
		
		open_valve(midtankno,1,1)		;	//open Air valve
		open_valve(midtankno,0,1)		;	//open Ink valve
		Int32 i=0; 
		while (i<Timout)					//check for 15 minitus 
		{
			Sum=0;
			for (Int32 j=0;j<Interval;j++)
			{
				resualt=read_pressure_sensor(midtankno);
				context.AppendToFile(File_name,resualt+",V");
				Sum=Sum+resualt;
				Thread.Sleep(1000);
			}
			
			
			if (i==0) 
				Start_Point=Sum/Interval;
			
			if (Sum>Old_Sum)
				Old_Sum=Sum-Old_Sum;
			else
				Old_Sum=Old_Sum-Sum;
		
   
			if ((check_valve(midtankno,1) != 0) && (check_valve(midtankno,0) != 0))
			{
				i++;
				if ( Old_Sum <0.02)	
					i=Timout+1;		//end 
				Old_Sum=Sum;
			}
			else
			{
			open_valve(midtankno,1,0)		;	//open Air valve
			open_valve(midtankno,0,0)		;	//open Ink valve
			Old_Sum=0;
			
			}	
		}
		Full_Point=Sum/Interval;
		

		close_valve(midtankno,1,1)		;	//close Air valve
		close_valve(midtankno,0,1)		;	//close Ink valve

			
		if (insert_slop_t_eeprom(Full_Point, midtankno,Start_Point)==0)
		{
				box_msg ="Turn Power Off and On to finish the calibration.";
				MessageBox.Show(box_msg);


    	context.AddResult(ResultType.Passed, "Test passed", "Test passed.");
				
		}
		else
		{
				box_msg ="Calibration error";
				MessageBox.Show(box_msg);


    	context.AddResult(ResultType.Failed, "Test Fail", "Test Fail.");
				
		}
	}

}


	int	insert_slop_t_eeprom( double FullPoint,Int32 midtankno, double StartPoint)
{
//	context.Write("\n ");

		StartPoint=FullPoint-StartPoint;
		StartPoint=StartPoint/Full_Cartridge;
		if ((StartPoint>0.7 ) && (StartPoint>1.3 ))
		{
			MidTankDataSetupRequest midTankDataSetupRequest = new MidTankDataSetupRequest();

			MidTankData midTankData = new MidTankData();
			midTankData.MidTankId = Convert.ToUInt32 (midtankno-1);
			midTankData.InitialOffsetA =FullPoint - (Full_Cartridge/1000-0.1)/Slop;
			midTankData.SlopeB = Slop;
			
			context.Write("\nMidtank No:" + midtankno + "=\tVoltage Zero is  ="+(FullPoint - (Full_Cartridge/1000-0.1)/Slop)+"\tSlop="+ Slop);
			context.AppendToFile(File_name,"\nMidtank No:" + midtankno + "=\tVoltage Zero is  ="+(FullPoint - (Full_Cartridge/1000-0.1)/Slop)+"\tSlop="+ Slop);

			
			midTankDataSetupRequest.MidTankInfo.Add(midTankData);
		

			var response =context.Send<MidTankDataSetupResponse>(midTankDataSetupRequest);

			return	0;
		}
		else
			context.Write("\nError");
			context.AppendToFile(File_name,"\n Slop Error");
			return	1;
	

    }



int adc_configuration(uint I2C_Slave_Add,uint channel ) 
	{
	StubI2CWriteBytesRequest stubI2CWriteBytesRequest = new StubI2CWriteBytesRequest();
	stubI2CWriteBytesRequest.I2CId = I2C_ID;
	stubI2CWriteBytesRequest.SlaveAddress = I2C_Slave_Add;
	
	UInt32 uInt32 = new UInt32();
	stubI2CWriteBytesRequest.BytesTWrite.Add(0x00);//Byte 0 to write
	stubI2CWriteBytesRequest.BytesTWrite.Add(channel);//Byte 1 to Write, must be 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02 or 0x01 for different channels
	stubI2CWriteBytesRequest.BytesTWrite.Add(0x80);//Byte 2 to Write
	
	var response =context.Send<StubI2CWriteBytesResponse>(stubI2CWriteBytesRequest);
	
	return 1;
	}


int adc_set_for_read_ch(uint I2C_Slave_Add) 
	{
	StubI2CWriteBytesRequest stubI2CWriteBytesRequest = new StubI2CWriteBytesRequest();
	stubI2CWriteBytesRequest.I2CId = I2C_ID;
	stubI2CWriteBytesRequest.SlaveAddress = I2C_Slave_Add;
	
	UInt32 uInt32 = new UInt32();
	stubI2CWriteBytesRequest.BytesTWrite.Add(0x01);//Byte 0 to write

	var response =context.Send<StubI2CWriteBytesResponse>(stubI2CWriteBytesRequest);
	
	return 1;
	}




double adc_read_ch(uint I2C_Slave_Add) 
	{
	StubI2CReadBytesRequest stubI2CReadBytesRequest = new StubI2CReadBytesRequest();
	stubI2CReadBytesRequest.I2CId = I2C_ID;
	stubI2CReadBytesRequest.SlaveAddress = I2C_Slave_Add;
	stubI2CReadBytesRequest.NumberOfBytesToRead = 2; // Number of bytes to read

	var response1 =context.Send<StubI2CReadBytesResponse>(stubI2CReadBytesRequest);
	uint temph=0;
	uint templ=0;
	uint temp;
	double calc;
	double calc1;
	double calc2;
			temph=response1.ReadBytes[0];
			templ=response1.ReadBytes[1];
			temp = (temph << 8) | templ;
			temp=temp & 0x0fff;
				
			calc = (double)temp *2.5 / 4096.0;
		
			calc1 = (1.96- calc) * 4.64 + 1.96;
			context.Write("Vsensor [volts]:\t");
			context.Write(calc1 + "\n");

	
	return calc1;
	}

double		read_pressure_sensor(Int32 i )
	{
double resualt =0 ;
		   switch (i)
      {
        case 1:
			adc_configuration(0x44,0x20);		//a2d_address 0x44 channel channel 2
			adc_set_for_read_ch(0x44);
			resualt=adc_read_ch(0x44);
		break;
		
		case 2:
			adc_configuration(0x44,0x08);		//a2d_address 0x44 channel channel 4
			adc_set_for_read_ch(0x44);
			resualt=adc_read_ch(0x44);
		break;
		
		case 3:
			adc_configuration(0x46,0x80);		//a2d_address 0x46 channel channel 0
			adc_set_for_read_ch(0x46);
			resualt=adc_read_ch(0x46);
		break;
		
		case 4:
			adc_configuration(0x46,0x20);		//a2d_address 0x46 channel channel 2
			adc_set_for_read_ch(0x46);
			resualt=adc_read_ch(0x46);
		break;
		
		case 5:
			adc_configuration(0x44,0x10);		//a2d_address 0x44 channel channel 3
			adc_set_for_read_ch(0x44);
			resualt=adc_read_ch(0x44);
		break;
		
		case 6:
			adc_configuration(0x44,0x04);		//a2d_address 0x44 channel channel 5
			adc_set_for_read_ch(0x44);
			resualt=adc_read_ch(0x44);
		break;
		
		case 7:
			adc_configuration(0x46,0x40);		//a2d_address 0x46 channel channel 1
			adc_set_for_read_ch(0x46);
			resualt=adc_read_ch(0x46);
		break;
		
		case 8:
			adc_configuration(0x46,0x10);		//a2d_address 0x46 channel channel 3
			adc_set_for_read_ch(0x46);
			resualt=adc_read_ch(0x46);
		break;
		
        default:
        context.Write("Error");

        break;
	  }	
		
		return resualt;
	}	


//--------------------------------
int open_valve (int valve_nm,int valve_type,int check_valve)		//valve_type=0 is Air ,1 is Ink ; check_valve=1 send feedbak
{
	int temp1=Convert_Midtank_No[valve_nm-1]	;

	string temp;
	SetBit (F3_VALVE_OUT,(((valve_type+1)*8)- temp1), 1);	
	
		if (check_valve!=0)
		{
			temp="Air";
			if (valve_type==1)
			temp="Ink";
				
			DialogResult result = MessageBox.Show("Did " + temp + "Valve of Midtank " + valve_nm +" open?", "Warning",MessageBoxButtons.YesNo);
			if(result == DialogResult.No)
				{
//					Units_status[(valve_nm-1)*3+valve_type,1]="Fail";
					context.Write(temp +"Valve\tFail\n");	
					return 0;
				}
			else 
				{
//					Units_status[(valve_nm-1)*3+valve_type,1]="Pass";
					context.Write(temp +"Valve\tOpen\n");	
					return 1;
				}
			
		}
		return 1;

}
//--------------------------------	
int close_valve (int valve_nm,int valve_type,int check_valve)
{
	int temp1=Convert_Midtank_No[valve_nm-1];	

	string temp;
	SetBit (F3_VALVE_OUT,(((valve_type+1)*8)- temp1), 0);
	if (check_valve!=0)
		{
			temp="Air";
			if (valve_type==1)
			temp="Ink";
				
			DialogResult result = MessageBox.Show("Did " + temp +" Valve of Midtank " + valve_nm +" close?", "Warning",MessageBoxButtons.YesNo);
			if(result == DialogResult.No)
				{
//					Units_status[(valve_nm-1)*3+valve_type,1]="Fail";
					context.Write(temp +"Valve\tFail\n");	
					return 0;
				}
			else 
				{
//					Units_status[(valve_nm-1)*3+valve_type,1]="Pass";
					context.Write(temp +"Valve\tclose\n");	
					return 1;
				}			
		}
	return 1;

}

public Int32 SetBit(Int32 Adr, Int32 BitNo, Int32 Bit)
{
	Int32 BitMask;
	Int32 RetVal;
	RetVal = Fpga_Read_Reg(Adr);
	Int32 RV = RetVal  ;
	
	if (Bit == 0x1) 
	{
		BitMask = 0x1 << BitNo;
		RV = RV | BitMask;
		Fpga_Write_Reg( Adr, RV );
	}
	else if (Bit == 0x0)
	{
		BitMask = ~(0x1 << BitNo);
		RV = RV & BitMask;
		Fpga_Write_Reg(Adr, RV );	
	}
	return 1;
}

int Fpga_Write_Reg(Int32 Addr, Int32 Data)
{
	var response =context.Send<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,Addr, Data);
	
	return 1;
}


Int32 check_valve (Int32 valve_nm,int valve_type)
{
	Int32 temp1=Convert_Midtank_No[valve_nm-1];	
	
    var response =context.Send<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F3_VALVE_OUT);
	Int32 RV =(Int32) response.Value & 0xffff ;
	RV = RV & ( 0x1 << (((valve_type+1)*8)- temp1));
	return RV;

}


Int32 Fpga_Read_Reg(Int32 Addr)
{
    
context.Write("123");

	var response =context.Send<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,Addr);
	context.Write("456");

	Int32 RV= (Int32) response.Value & 0xffff;
	context.Write("789");

	return RV;
}    
    
    
    
}