diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2020-08-27 16:08:47 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2020-08-27 16:08:47 +0300 |
| commit | 0c038093d83f8e266f09f489cd93dda3dbc6ab3f (patch) | |
| tree | 375412271dfaddd6168108671d5d3e99fabcf855 /Software/Stubs Collection | |
| parent | ddce0f3215746d6884acb94f3cedc613008aed5c (diff) | |
| download | Tango-0c038093d83f8e266f09f489cd93dda3dbc6ab3f.tar.gz Tango-0c038093d83f8e266f09f489cd93dda3dbc6ab3f.zip | |
4 winders test; keep alive embedded==>management. procedures.
Diffstat (limited to 'Software/Stubs Collection')
3 files changed, 1599 insertions, 1 deletions
diff --git a/Software/Stubs Collection/Procedures/Mid tank calibration.pproj b/Software/Stubs Collection/Procedures/Mid tank calibration.pproj index 0bb05e75b..655bbd099 100644 --- a/Software/Stubs Collection/Procedures/Mid tank calibration.pproj +++ b/Software/Stubs Collection/Procedures/Mid tank calibration.pproj @@ -1 +1,477 @@ -{"$id":"1","Inputs":{"$id":"2","$values":[{"$id":"3","Type":"Default","SelectionInputs":{"$id":"4","$values":[]},"DisplayName":"Check Tamper / Fan alarms","Description":"Check Tamper / Fan alarms","Key":"CheckTampers","Value":"1.0"},{"$id":"5","Type":"Default","SelectionInputs":{"$id":"6","$values":[]},"DisplayName":"Initial Heating on startup","Description":"Initial Heating on startup","Key":"InitialHeating","Value":"true"},{"$id":"7","Type":"Default","SelectionInputs":{"$id":"8","$values":[]},"DisplayName":"WCF Value","Description":"WCF Value","Key":"WCF_Value","Value":"40"},{"$id":"9","Type":"Default","SelectionInputs":{"$id":"10","$values":[]},"DisplayName":"AutoFill Mode","Description":"Controls the AutoFill Mode","Key":"AutoFillMode","Value":"3.0"}]},"Variables":{"$id":"11","$values":[]},"Resources":{"$id":"12","$values":[]},"Dialogs":{"$id":"13","$values":[]},"ID":"2bd29884-5eb9-4d27-be4e-6cfa31dc9f66","Name":"Mid tank calibration","Description":"This procedure lets the FSE to define values for cleaning, tamper alarms, initial heating, WCF value and automatic dispenser filling.","ApartmentState":"MTA","ReferenceAssemblies":{"$id":"14","$values":[{"$id":"15","File":"C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\mscorlib.dll","HintType":"System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"},{"$id":"16","File":"C:\\WINDOWS\\Microsoft.Net\\assembly\\GAC_MSIL\\System.Core\\v4.0_4.0.0.0__b77a5c561934e089\\System.Core.dll","HintType":"System.Linq.Enumerable, System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"},{"$id":"17","File":"C:\\WINDOWS\\Microsoft.Net\\assembly\\GAC_MSIL\\System.Windows.Forms\\v4.0_4.0.0.0__b77a5c561934e089\\System.Windows.Forms.dll","HintType":"System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"},{"$id":"18","File":"C:\\Program Files (x86)\\Twine Solutions LTD\\Tango FSE\\Tango.FSE.Procedures.dll","HintType":"Tango.FSE.Procedures.ProcedureProject, Tango.FSE.Procedures, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"},{"$id":"19","File":"C:\\Program Files (x86)\\Twine Solutions LTD\\Tango FSE\\Tango.FSE.Common.dll","HintType":"Tango.FSE.Common.Diagnostics.IDiagnosticsProvider, Tango.FSE.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"},{"$id":"20","File":"C:\\Program Files (x86)\\Twine Solutions LTD\\Tango FSE\\Tango.BL.dll","HintType":"Tango.BL.Enumerations.TechMonitors, Tango.BL, Version=2.0.36.1608, Culture=neutral, PublicKeyToken=null"},{"$id":"21","File":"C:\\Program Files (x86)\\Twine Solutions LTD\\Tango FSE\\Tango.PMR.dll","HintType":"Tango.PMR.Common.MessageType, Tango.PMR, Version=2.0.40.1608, Culture=neutral, PublicKeyToken=null"},{"$id":"22","File":"C:\\Program Files (x86)\\Twine Solutions LTD\\Tango FSE\\Tango.Transport.dll","HintType":"Tango.Transport.ITransporter, Tango.Transport, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"},{"$id":"23","File":"C:\\Program Files (x86)\\Twine Solutions LTD\\Tango FSE\\Tango.Integration.dll","HintType":"Tango.Integration.Operation.IMachineOperator, Tango.Integration, Version=2.0.31.1608, Culture=neutral, PublicKeyToken=null"},{"$id":"24","File":"C:\\Program Files (x86)\\Twine Solutions LTD\\Tango FSE\\Google.Protobuf.dll","HintType":"Google.Protobuf.IMessage, Google.Protobuf, Version=3.4.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604"},{"$id":"25","File":"C:\\WINDOWS\\Microsoft.Net\\assembly\\GAC_MSIL\\System.Drawing\\v4.0_4.0.0.0__b03f5f7f11d50a3a\\System.Drawing.dll","HintType":"System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"}]},"Scripts":{"$id":"26","$values":[{"$id":"27","Name":"Program.csx","IsEntryPoint":true,"Code":"using System;\r\nusing System.Collections.Generic;\r\nusing System.Collections.ObjectModel;\r\nusing System.ComponentModel;\r\nusing System.Linq;\r\nusing System.IO;\r\nusing System.Text;\r\nusing System.Threading;\r\nusing System.Threading.Tasks;\r\nusing System.Drawing;\r\nusing Google.Protobuf;\r\nusing Tango.BL.Entities;\r\nusing Tango.BL.Enumerations;\r\nusing Tango.PMR.Stubs;\r\nusing Tango.PMR.Diagnostics;\r\nusing Tango.PMR.EmbeddedParameters;\r\nusing Tango.FSE.Common.Connection;\r\nusing Tango.FSE.Common.Diagnostics;\r\nusing Tango.FSE.Procedures;\r\n\r\n\r\npublic class Program\r\n{\r\n\r\nprivate IProcedureContext context;\r\n\r\n\t//----------------------\r\n\tconst double \tSlop=0.92;\r\n\tconst double\tMIN_SLOP=0.7;\r\n\tconst double\tMAX_SLOP=1.4;\r\n\tconst double\tERROR_SLOP=-1;\r\n\tconst double\tMIN_50cc_on_volt=2.3;\r\n\tconst double\tMAX_50cc_on_volt=3.2;\r\n\tconst double\tERROR_50cc_on_volt=-1;\r\n\tdouble CartSizeLiter = 1.0;\r\n\t\r\n\tint [] Convert_Midtank_No = new Int32 [8] {1,3,5,7,2,4,6,8};\r\n\tuint [,] ADC_Add_Chnl = new uint [8,2]\t{\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t{0x44,0x20},\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t{0x44,0x08},\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t{0x46,0x80},\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t{0x46,0x20},\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t{0x44,0x10},\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t{0x44,0x04},\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t{0x46,0x40},\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t{0x46,0x10},\r\n\t\t\t\t\t\t\t\t\t\t\t};\r\n\t\r\n\t\r\n\tconst Int32\tF3_VALVE_OUT\t=\t0x600008E2\t;\r\n\tstring Machine_SN\t;\r\n\tprivate const string FILE_PATH = @\"C:\\MidTankLog\\\";\r\n\tstring File_name;\r\n\tdouble [,] voltage_array = new double[9,9];\r\n\tstring [] Parameter = new string[5] {\"\\t\",\"Empty [V]\",\"100cc [V]\",\"800cc [V]\",\" b [L/V] \"};\r\n\t\tdouble Full_Cartridge=1;\t// 1 litter less 100 cc\r\n\t\r\n\t//----------------------\r\n\tconst Int32 I2C_ID = 2;\r\n\t//const Int32 I2C_Slave_Add = 0x46; //must be 0x40, 0x44 or 0x46\r\n\t//----------------------\r\n\t\r\n public void OnExecute(IProcedureContext context)\r\n {\r\n\tthis.context = context;\r\n\t\r\n\tInt32 midtankno = 0;\r\n\tdouble Full_Point=0;\t\t\t//on Voltage\r\n\tdouble resualt;\r\n\tdouble Sum=0 ;\r\n\tdouble Old_Sum=0 ;\r\n\t\r\n\r\n\tif (!Directory.Exists(FILE_PATH))\r\n\t\t{\r\n\t\t\tDirectory.CreateDirectory(FILE_PATH);\r\n\t\t}\t\t\t\r\n\r\n\r\n \t//Machine_SN = context.GetInput<string>(\"Midtank_SN\");\r\n var response = context.RequestUserInputFor<String>(\"Mid Tank Serial Number\", \"Enter Midtank S/N:\");\r\n\tcontext.Write(\"\\n\");\r\n\tMachine_SN = response;\r\n\tcontext.WriteLine(Machine_SN);\r\n\tFile_name= FILE_PATH +Machine_SN + DateTime.Now.ToString(\"MM_dd_yyyy_HH_mm_ss\")+\".csv\";\r\n\tcontext.Write(File_name);\r\n \tcontext.WriteToFile(File_name,\"MidTank S/N:,\" + Machine_SN); \r\n\t\r\n\t\r\n\r\n\t//midtankno = context.GetInput<int>(\"MidTankId\");\r\n\tvar response1 = context.RequestUserInputFor<String>(\"Mid Tank Number\", \"Enter Midtank number to calibrate (1-8):\");\r\n\tcontext.WriteLine(response1);\r\n\tmidtankno = Int32.Parse(response1);\r\n \tcontext.AppendToFile(File_name,\"MidTank Number:\\t\" + response1);\r\n\r\n\r\n\tvar response2 = context.RequestUserInputFor<int>(\"Cartridge size\", \"Enter enter cartridge size in ml (1000/700/500):\");\r\n\tcontext.WriteLine(response2);\r\n\tint Cart_size = response2;\r\n \tcontext.AppendToFile(File_name,\"Cartrideg size:\\t\" + response2);\r\n\r\n\r\n string box_msg = \"Please Insert cartridge with\" +Cart_size+\"cc (Lubbricant add 500cc only) \";\r\n// string box_title = \"Midatnk empty\";\r\n// context.ShowInfo(box_msg, box_title);\r\n\tcontext.ShowInfo(box_msg);\r\n\r\n\t//int CartInserted = 0;\r\n\t//while (CartInserted == 0)\r\n\t//\tCartInserted = context.GetInput<int>(\"insertCartridge\");\r\n\t\r\n\tCartSizeLiter = Cart_size/1000;\r\n\t\r\n\topen_valve(midtankno,1,1)\t\t;\t//open Air valve\r\n\topen_valve(midtankno,0,1)\t\t;\t//open Ink valve\r\n\tInt32 i=0; \r\n\twhile (i<60*15)\t\t\t\t\t//check for 15 minitus \r\n\t{\r\n\t\tSum=0;\r\n\t\tfor (Int32 j=0;j<30;j++)\r\n\t\t{\r\n\t\t\tresualt=read_pressure_sensor(midtankno);\r\n\t\t\tcontext.AppendToFile(File_name,resualt+\",mV\");\r\n\t\t\tSum=Sum+resualt;\r\n\t\t\tThread.Sleep(1000);\r\n\t\t}\r\n\t\ti=i+1;\r\n\t\tif (Sum>Old_Sum)\r\n\t\t\tOld_Sum=Sum-Old_Sum;\r\n\t\telse\r\n\t\t\tOld_Sum=Old_Sum-Sum;\r\n\t\t\t\r\n\t\tif ( Old_Sum <0.02)\t\r\n\t\t\ti=60*15;\t\t//end \r\n\t\tOld_Sum=Sum;\r\n\t}\r\n\tFull_Point=Sum/30;\r\n\t\r\n\tbox_msg = \"Send file\" + File_name +\"to Mati\"; \r\n\tcontext.ShowInfo(box_msg);\r\n\t\r\n\t\r\n\t//\tcontext.Send<StubFpgaWriteRegResponse>(\"StubFpgaWriteRegRequest\" ,F3_VALVE_OUT, 0x000f);\t\t// open all valve air of midtank and close all ink of midtank\r\n\t//\tThread.Sleep(500);\r\n\t//\tcontext.Send<StubFpgaWriteRegResponse>(\"StubFpgaWriteRegRequest\" ,F3_VALVE_OUT, 0x00ff);\t\t// open all valve air of midtank and close all ink of midtank\r\n\t//\tThread.Sleep(500);\r\n\t//\tcontext.Send<StubFpgaWriteRegResponse>(\"StubFpgaWriteRegRequest\" ,F3_VALVE_OUT, 0x0fff);\t\t// open all valve air of midtank and close all ink of midtank\r\n\t//\tThread.Sleep(500);\r\n\t//\tcontext.Send<StubFpgaWriteRegResponse>(\"stubFpgaWriteRegRequest\" ,F3_VALVE_OUT, 0xffff);\t\t// open all valve air and ink of midtank\r\n\t//\r\n\t//\tThread.Sleep(2500);\r\n\r\n\t//\tThread.Sleep(1000);\t\r\n\t\t\r\n\t//\tread_pressure_sensor(1);\r\n \t\t\r\n\t//\tbox_msg =\"Insert 100cc of appropriate ink/lube to each midtank\\n\\t1.black ink\\n\\t2. Magenta ink\\n\\t3. Transparent ink\\n\\t4. Cleaner\\n\\t5. Cyan ink\\n\\t6. Yellow ink\\n\\t7. Spot color\\n\\t8. Lubricant/n\";\r\n // context.ShowInfo(box_msg);\r\n//\r\n\t//\tread_pressure_sensor(2);\r\n\r\n\t\t\t\t\t//\tvoltage_array[3,2]=2.5;\r\n\t\t\r\n//\t\tbox_msg = \"Add another 700cc for ink and TI \\nFor Lubbricant add 500cc only.\"; \r\n//\t\tcontext.ShowInfo(box_msg);\r\n//\t\tread_pressure_sensor(3);\r\n//\t\t\t\tcontext.Send<StubFpgaWriteRegResponse>(\"stubFpgaWriteRegRequest\" ,F3_VALVE_OUT, 0x0000);\t\t// close all valve air and ink of midtank\r\n\t\t\t\t\t\t\t\t\t//\t\t\tvoltage_array[3,3]=4.5;\r\n\tclose_valve(midtankno,1,1)\t\t;\t//close Air valve\r\n\tclose_valve(midtankno,0,1)\t\t;\t//close Ink valve\r\n\r\n//\t\tcalc_slop();\r\n//\t\tprint_table();\r\n\t\t\r\n//\t\tinsert_slop_t_eeprom(Full_Point, midtankno);\r\n\t\tinsert_slop_t_eeprom(Full_Point, midtankno);\r\n\t\tbox_msg =\"Turn Power Off and On to finish the calibration.\";\r\n context.ShowInfo(box_msg);\r\n\t\r\n\t}\r\n\r\nint calc_slop()\r\n\t{\r\n\tcontext.Write(\"\\n \");\r\n\t\t\r\n\tdouble delta;\r\n\tfor (uint i=1;i<9;i++)\r\n\t\t{\r\n\t\t\tdelta=voltage_array[i,3]-voltage_array[i,2];\r\n\t\t\r\n\t\t\tcontext.Write(\"\\nMidtank No:\"+i +\"=\"+delta);\r\n//\t\t\tif (i==8)\r\n\t\t\t\tdelta=CartSizeLiter/delta;\t\t\t\t\t\t\t\t\t\t\t\t//0.5 litter on lubricant\t\t\t\r\n//\t\t\telse \r\n//\t\t\t\tdelta=CartSizeLiter/delta;\t\t\t\t\t\t\t\t\t\t\t\t//0.7 litter\r\n\t\t\t\t\r\n\t\t\tif ((delta<MIN_SLOP) || (delta >MAX_SLOP)) \r\n\t\t\t{\r\n\t\t\t\tvoltage_array[i,4]=ERROR_SLOP;\r\n\t\t//\t\tcontext.Write(\"123\");\r\n\t\t\t}\r\n\t\telse if\t((voltage_array[i,2]<MIN_50cc_on_volt) || (voltage_array[i,2]>MAX_50cc_on_volt ))\r\n\t\t\t\t\tvoltage_array[i,4]=ERROR_SLOP;\r\n\t\telse\r\n\t\tvoltage_array[i,4]=delta;\r\n\t\t}\r\n\treturn 1;\r\n\t}\r\n\r\n\r\n\tint\tinsert_slop_t_eeprom( double FullPoint,Int32 midtankno)\r\n{\r\n//\tcontext.Write(\"\\n \");\r\n\r\n\tMidTankDataSetupRequest midTankDataSetupRequest = new MidTankDataSetupRequest();\r\n\r\n\r\n//\tfor (uint i=1;i<9;i++)\r\n//\t{\r\n//\t\tif (voltage_array[i,4]!= ERROR_SLOP)\r\n//\t\t{\r\n\t\tMidTankData midTankData = new MidTankData();\r\n\t\tmidTankData.MidTankId = Convert.ToUInt32 (midtankno-1);\r\n\t\tmidTankData.InitialOffsetA =FullPoint - (Full_Cartridge-0.1)/Slop;\r\n\t\tmidTankData.SlopeB = Slop;\r\n\t\t\r\n\t\tcontext.Write(\"\\nMidtank No:\" + midtankno + \"=\\tVoltage Zero is =\"+(FullPoint - (Full_Cartridge-0.1)/Slop)+\"\\tSlop=\"+ Slop);\r\n\t\tcontext.AppendToFile(File_name,\"\\nMidtank No:\" + midtankno + \"=\\tVoltage Zero is =\"+(FullPoint - (Full_Cartridge-0.1)/Slop)+\"\\tSlop=\"+ Slop);\r\n\r\n\t\t\r\n\t\tmidTankDataSetupRequest.MidTankInfo.Add(midTankData);\r\n\t\r\n\t//\t}\r\nvar response = context.Send<MidTankDataSetupResponse>(midTankDataSetupRequest);\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t//}\r\n\r\n\r\nreturn\t1;\r\n}\r\n\r\n//\r\n//\r\n//int\t\tprint_table()\r\n//\t\t{\r\n//\r\n//\t\tfor (uint i=0;i<5;i++)\r\n//\t\t\t{\r\n//\t\t\t\tcontext.AppendToFile(File_name,Parameter[i]+\"\\t\"+voltage_array[1,i]+\"\\t\"+voltage_array[2,i]+\"\\t\"+voltage_array[3,i]+\"\\t\"+voltage_array[4,i]+\"\\t\"+voltage_array[5,i]+\"\\t\"+voltage_array[6,i]+\"\\t\"+voltage_array[7,i]+\"\\t\"+voltage_array[8,i]) ;\r\n// } \r\n// \r\n//\t\r\n//\t\t\treturn 1;\r\n//\r\n//\t\t}\r\n\r\n//start mat\r\n\r\nint adc_configuration(uint I2C_Slave_Add,uint channel ) \r\n\t{\r\n\tStubI2CWriteBytesRequest stubI2CWriteBytesRequest = new StubI2CWriteBytesRequest();\r\n\tstubI2CWriteBytesRequest.I2CId = I2C_ID;\r\n\tstubI2CWriteBytesRequest.SlaveAddress = I2C_Slave_Add;\r\n\t\r\n\tUInt32 uInt32 = new UInt32();\r\n\tstubI2CWriteBytesRequest.BytesTWrite.Add(0x00);//Byte 0 to write\r\n\tstubI2CWriteBytesRequest.BytesTWrite.Add(channel);//Byte 1 to Write, must be 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02 or 0x01 for different channels\r\n\tstubI2CWriteBytesRequest.BytesTWrite.Add(0x80);//Byte 2 to Write\r\n\t\r\n\tvar response = context.Send<StubI2CWriteBytesResponse>(stubI2CWriteBytesRequest);\r\n\t\r\n\treturn 1;\r\n\t}\r\n\r\n\r\nint adc_set_for_read_ch(uint I2C_Slave_Add) \r\n\t{\r\n\tStubI2CWriteBytesRequest stubI2CWriteBytesRequest = new StubI2CWriteBytesRequest();\r\n\tstubI2CWriteBytesRequest.I2CId = I2C_ID;\r\n\tstubI2CWriteBytesRequest.SlaveAddress = I2C_Slave_Add;\r\n\t\r\n\tUInt32 uInt32 = new UInt32();\r\n\tstubI2CWriteBytesRequest.BytesTWrite.Add(0x01);//Byte 0 to write\r\n\r\n\tvar response = context.Send<StubI2CWriteBytesResponse>(stubI2CWriteBytesRequest);\r\n\t\r\n\treturn 1;\r\n\t}\r\n\r\n\r\n\r\n\r\ndouble adc_read_ch(uint I2C_Slave_Add) \r\n\t{\r\n\tStubI2CReadBytesRequest stubI2CReadBytesRequest = new StubI2CReadBytesRequest();\r\n\tstubI2CReadBytesRequest.I2CId = I2C_ID;\r\n\tstubI2CReadBytesRequest.SlaveAddress = I2C_Slave_Add;\r\n\tstubI2CReadBytesRequest.NumberOfBytesToRead = 2; // Number of bytes to read\r\n\r\n\tvar response1 = context.Send<StubI2CReadBytesResponse>(stubI2CReadBytesRequest);\r\n\tuint temph=0;\r\n\tuint templ=0;\r\n\tuint temp;\r\n\tdouble calc;\r\n\tdouble calc1;\r\n\tdouble calc2;\r\n\t\t\ttemph=response1.ReadBytes[0];\r\n\t\t\ttempl=response1.ReadBytes[1];\r\n\t\t\ttemp = (temph << 8) | templ;\r\n\t\t\ttemp=temp & 0x0fff;\r\n\t\t\t\t\r\n\t\t\tcalc = (double)temp *2.5 / 4096.0;\r\n//\t\t\tcontext.Write(\"ADC [volts]:\\t\");\r\n//\t\t\tcontext.Write(calc+\"\\t\");\r\n\t\t\r\n\t\t\tcalc1 = (1.96- calc) * 4.64 + 1.96;\r\n\t\t\tcontext.Write(\"Vsensor [volts]:\\t\");\r\n\t\t\tcontext.Write(calc1 + \"\\n\");\r\n\r\n\t//\t\tvoltage_array[table_index_x,table_index_y]=calc1;\r\n\t\r\n\treturn calc1;\r\n\t}\r\n\r\ndouble\t\tread_pressure_sensor(Int32 i )\r\n\t{\r\ndouble resualt =0 ;\r\n\t\t switch (i)\r\n {\r\n case 1:\r\n\t\t\tadc_configuration(0x44,0x20);\t\t//a2d_address 0x44 channel channel 2\r\n\t\t\tadc_set_for_read_ch(0x44);\r\n\t\t\tresualt=adc_read_ch(0x44);\r\n\t\tbreak;\r\n\t\t\r\n\t\tcase 2:\r\n\t\t\tadc_configuration(0x44,0x08);\t\t//a2d_address 0x44 channel channel 4\r\n\t\t\tadc_set_for_read_ch(0x44);\r\n\t\t\tresualt=adc_read_ch(0x44);\r\n\t\tbreak;\r\n\t\t\r\n\t\tcase 3:\r\n\t\t\tadc_configuration(0x46,0x80);\t\t//a2d_address 0x46 channel channel 0\r\n\t\t\tadc_set_for_read_ch(0x46);\r\n\t\t\tresualt=adc_read_ch(0x46);\r\n\t\tbreak;\r\n\t\t\r\n\t\tcase 4:\r\n\t\t\tadc_configuration(0x46,0x20);\t\t//a2d_address 0x46 channel channel 2\r\n\t\t\tadc_set_for_read_ch(0x46);\r\n\t\t\tresualt=adc_read_ch(0x46);\r\n\t\tbreak;\r\n\t\t\r\n\t\tcase 5:\r\n\t\t\tadc_configuration(0x44,0x10);\t\t//a2d_address 0x44 channel channel 3\r\n\t\t\tadc_set_for_read_ch(0x44);\r\n\t\t\tresualt=adc_read_ch(0x44);\r\n\t\tbreak;\r\n\t\t\r\n\t\tcase 6:\r\n\t\t\tadc_configuration(0x44,0x04);\t\t//a2d_address 0x44 channel channel 5\r\n\t\t\tadc_set_for_read_ch(0x44);\r\n\t\t\tresualt=adc_read_ch(0x44);\r\n\t\tbreak;\r\n\t\t\r\n\t\tcase 7:\r\n\t\t\tadc_configuration(0x46,0x40);\t\t//a2d_address 0x46 channel channel 1\r\n\t\t\tadc_set_for_read_ch(0x46);\r\n\t\t\tresualt=adc_read_ch(0x46);\r\n\t\tbreak;\r\n\t\t\r\n\t\tcase 8:\r\n\t\t\tadc_configuration(0x46,0x10);\t\t//a2d_address 0x46 channel channel 3\r\n\t\t\tadc_set_for_read_ch(0x46);\r\n\t\t\tresualt=adc_read_ch(0x46);\r\n\t\tbreak;\r\n\t\t\r\n default:\r\n context.Write(\"Error\");\r\n\r\n break;\r\n\t }\t\r\n\t\t\r\n\t\treturn resualt;\r\n\t}\t\r\n\r\n\r\n//--------------------------------\r\nint open_valve (int valve_nm,int valve_type,int check_valve)\t\t//valve_type=0 is Air ,1 is Ink ; check_valve=1 send feedbak\r\n{\r\n\tint temp1=Convert_Midtank_No[valve_nm-1]\t;\r\n\r\n\tstring temp;\r\n\tSetBit (F3_VALVE_OUT,(((valve_type+1)*8)- temp1), 1);\t\r\n\t\r\n\t\tif (check_valve!=0)\r\n\t\t{\r\n\t\t\ttemp=\"Air\";\r\n\t\t\tif (valve_type==1)\r\n\t\t\ttemp=\"Ink\";\r\n\t\t\t\t\r\n\t\t\tif(!context.ShowWarningQuestion(\"Did \" + temp + \"Valve of Midtank \" + valve_nm +\" open?\"))\r\n\t\t\t\t{\r\n//\t\t\t\t\tUnits_status[(valve_nm-1)*3+valve_type,1]=\"Fail\";\r\n\t\t\t\t\tcontext.Write(temp +\"Valve\\tFail\\n\");\t\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t}\r\n\t\t\telse \r\n\t\t\t\t{\r\n//\t\t\t\t\tUnits_status[(valve_nm-1)*3+valve_type,1]=\"Pass\";\r\n\t\t\t\t\tcontext.Write(temp +\"Valve\\tOpen\\n\");\t\r\n\t\t\t\t\treturn 1;\r\n\t\t\t\t}\r\n\t\t\t\r\n\t\t}\r\n\t\treturn 1;\r\n\r\n}\r\n//--------------------------------\t\r\nint close_valve (int valve_nm,int valve_type,int check_valve)\r\n{\r\n\tint temp1=Convert_Midtank_No[valve_nm-1];\t\r\n\r\n\tstring temp;\r\n\tSetBit (F3_VALVE_OUT,(((valve_type+1)*8)- temp1), 0);\r\n\tif (check_valve!=0)\r\n\t\t{\r\n\t\t\ttemp=\"Air\";\r\n\t\t\tif (valve_type==1)\r\n\t\t\ttemp=\"Ink\";\r\n\t\t\t\t\r\n\t\t\tif(!context.ShowWarningQuestion(\"Did \" + temp +\" Valve of Midtank \" + valve_nm +\" close?\"))\r\n\t\t\t\t{\r\n//\t\t\t\t\tUnits_status[(valve_nm-1)*3+valve_type,1]=\"Fail\";\r\n\t\t\t\t\tcontext.Write(temp +\"Valve\\tFail\\n\");\t\r\n\t\t\t\t\treturn 0;\r\n\t\t\t\t}\r\n\t\t\telse \r\n\t\t\t\t{\r\n//\t\t\t\t\tUnits_status[(valve_nm-1)*3+valve_type,1]=\"Pass\";\r\n\t\t\t\t\tcontext.Write(temp +\"Valve\\tclose\\n\");\t\r\n\t\t\t\t\treturn 1;\r\n\t\t\t\t}\t\t\t\r\n\t\t}\r\n\treturn 1;\r\n\r\n}\r\n\r\npublic Int32 SetBit(Int32 Adr, Int32 BitNo, Int32 Bit)\r\n{\r\n\tInt32 BitMask;\r\n\tvar RetVal = Fpga_Read_Reg(Adr);\r\n\tInt32 RV = (Int32) RetVal.Value;\r\n\t\r\n\tif (Bit == 0x1) \r\n\t{\r\n\t\tBitMask = 0x1 << BitNo;\r\n\t\tRV = RV | BitMask;\r\n\t\tFpga_Write_Reg( Adr, RV );\r\n\t}\r\n\telse if (Bit == 0x0)\r\n\t{\r\n\t\tBitMask = ~(0x1 << BitNo);\r\n\t\tRV = RV & BitMask;\r\n\t\tFpga_Write_Reg(Adr, RV );\t\r\n\t}\r\n\treturn 1;\r\n}\r\n\r\nint Fpga_Write_Reg(Int32 Addr, Int32 Data)\r\n{\r\n\tvar response = context.Send<StubFpgaWriteRegResponse>(\"StubFpgaWriteRegRequest\" ,Addr, Data);\r\n\t\r\n\treturn 1;\r\n}\r\n\r\n\r\n\r\nStubFpgaReadRegResponse Fpga_Read_Reg(Int32 Addr)\r\n{\r\n var response = context.Send<StubFpgaReadRegResponse>(\"StubFpgaReadRegRequest\" ,Addr);\r\n\tresponse.Value = response.Value & 0xffff;\r\n\t\r\n\treturn response;\r\n}\r\n}"},{"$id":"28","Name":"Service.csx","IsEntryPoint":false,"Code":"using System;\r\nusing System.Collections.Generic;\r\nusing System.Collections.ObjectModel;\r\nusing System.ComponentModel;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading;\r\nusing System.Threading.Tasks;\r\nusing Google.Protobuf;\r\nusing Tango.BL.Enumerations;\r\nusing Tango.PMR.Stubs;\r\nusing Tango.PMR.Diagnostics;\r\nusing Tango.FSE.Common.Diagnostics;\r\nusing Tango.FSE.Procedures;\r\n\r\npublic class Service\r\n{\r\n public double Calc(double a, double b)\r\n {\r\n return a + b;\r\n }\r\n}"}]}}
\ No newline at end of file +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; +} + + + +}
\ No newline at end of file diff --git a/Software/Stubs Collection/Procedures/Priming1.pproj b/Software/Stubs Collection/Procedures/Priming1.pproj new file mode 100644 index 000000000..adfed3f3e --- /dev/null +++ b/Software/Stubs Collection/Procedures/Priming1.pproj @@ -0,0 +1,1015 @@ +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.Diagnostics; +using System.Windows.Forms; + + +public class Program +{ + + +private IProcedureContext context; + +//---------------------Start Command ---------------- +const Int32 CMD_RUN = 0; //Run on Pulse Per Secound .positive run Up and negative run Down b +const Int32 CMD_STOP= 1; //0;Hard stop(Defualt);1-Soft stop;2-Hard Hiz;3-Soft Hiz +const Int32 CMD_VALVE= 2; //0-to Midtank ,1-to head +const Int32 CMD_DLY = 3; //delay in Seconds . +const Int32 CMD_TIME= 4; //Print Time . +const Int32 CMD_PRESS= 5; //return from Delay loop when pressure is high (on mBAR) . +const Int32 CMD_LOOP_NM=6; //NUMBER OF counter +const Int32 CMD_LOOP= 7; //jump up(+) or down(-) command u +const Int32 CMD_MTV_OPEN = 8; //0 Air ; 1 Ink +const Int32 CMD_MTV_CLOSE= 9; //0 Air ; 1 Ink +const Int32 CMD_LBL= 10; //label for user +const Int32 CMD_SMP= 11; //sample rate ,defualt 100msec (1); for 1 second is 10. +const Int32 CMD_PRESL= 12; //return from Delay loop when pressure is low (on mBAR) . + +const Int32 CMD_END = 13; //end loop . + + +Int32[] BuildUp_Table = new int [] +{ + CMD_VALVE,1, + CMD_PRESL,200, + CMD_DLY,200, + + CMD_LOOP_NM,3, + + CMD_VALVE,0, + CMD_DLY,1, + CMD_VALVE,1, + CMD_DLY,1, + CMD_LOOP,-4, + + CMD_VALVE,0, + CMD_RUN,1068, + CMD_PRESS,1000, //mbar --> 1000 = 100% work, 4000 = 200% work, 350 = 20% work + CMD_DLY,150, + CMD_LBL,1, + CMD_PRESS,2000, //mbar --> 2000 = 100% work, 4000 = 200% work, 350 = 20% work + CMD_DLY,60, + CMD_LBL,2, + CMD_PRESS,3000, + CMD_DLY,60, // to limit + CMD_STOP,0, + CMD_VALVE,1, + CMD_END,3, +}; + + +Int32[] Up_Table = new int [] +{ + CMD_VALVE,1, + CMD_PRESL,200, + CMD_DLY,200, + + CMD_PRESS,3000, //mbar --> 1000 = 100% work, 4000 = 200% work, 350 = 20% work + CMD_RUN,534, // 100% + CMD_DLY,120, + CMD_STOP,0, + CMD_END,3, +}; +Int32 Dispenser_sample_rate= 1; + + string path = @"C:\Dispenser_setup\Log\"; +//---------------------- +const UInt32 I2C_ID = 4; //MCU_I2C4 +const UInt32 TCA9548A_address = 0xE2; +const UInt32 I2C_Slave_Low_Add = 0xA0; //eeprom address - 64k low +const UInt32 I2C_Slave_High_Add = 0xA2; //eeprom address - 64k High +//---------------------- +byte [] EEPROM_Data = new byte [128]; + + +//---------------------End Command ---------------- + +const Int32 Dispenser_Motor1 = 6; +const Int32 Dispenser_Motor2 = 7; +const Int32 Dispenser_Motor3 = 8; +const Int32 Dispenser_Motor4 = 9; +const Int32 Dispenser_Motor5 = 10; +const Int32 Dispenser_Motor6 = 11; +const Int32 Dispenser_Motor7 = 12; +const Int32 Dispenser_Motor8 = 13; + +const Int32 AN_IDS_PRESSENS_1 = 2; +const Int32 AN_IDS_PRESSENS_2 = 3; +const Int32 AN_IDS_PRESSENS_3 = 4; +const Int32 AN_IDS_PRESSENS_4 = 5; +const Int32 AN_IDS_PRESSENS_5 = 6; +const Int32 AN_IDS_PRESSENS_6 = 7; +const Int32 AN_IDS_PRESSENS_7 = 8; +const Int32 AN_IDS_PRESSENS_8 = 9; + +const Int32 F2_LS_01_Direct = 0x60000420 ; // Reads the direct values that are currently being sent to the fpga. rsv rsv rsv rsv F2_LS_DISPENSER_UP_2 F2_LS_DISPENSER_25_2 F2_LS_DISPENSER_75_2 F2_LS_DISPENSER_DOWN_2 F2_LS_DISPENSER_50_2 F2_LS_DISPENSER_SPARE_2 F2_LS_DISPENSER_UP_1 F2_LS_DISPENSER_25_1 F2_LS_DISPENSER_75_1 F2_LS_DISPENSER_DOWN_1 F2_LS_DISPENSER_50_1 F2_LS_DISPENSER_SPARE_1 +const Int32 F2_LS_02_Direct = 0x60000430 ; // Reads the direct values that are currently being sent to the fpga. rsv rsv rsv rsv F2_LS_DISPENSER_UP_4 F2_LS_DISPENSER_25_4 F2_LS_DISPENSER_75_4 F2_LS_DISPENSER_DOWN_4 F2_LS_DISPENSER_50_4 F2_LS_DISPENSER_SPARE_4 F2_LS_DISPENSER_UP_3 F2_LS_DISPENSER_25_3 F2_LS_DISPENSER_75_3 F2_LS_DISPENSER_DOWN_3 F2_LS_DISPENSER_50_3 F2_LS_DISPENSER_SPARE_3 +const Int32 F2_LS_03_Direct = 0x60000440 ; // Reads the direct values that are currently being sent to the fpga. rsv rsv rsv rsv F2_LS_DISPENSER_UP_6 F2_LS_DISPENSER_25_6 F2_LS_DISPENSER_75_6 F2_LS_DISPENSER_DOWN_6 F2_LS_DISPENSER_50_6 F2_LS_DISPENSER_SPARE_6 F2_LS_DISPENSER_UP_5 F2_LS_DISPENSER_25_5 F2_LS_DISPENSER_75_5 F2_LS_DISPENSER_DOWN_5 F2_LS_DISPENSER_50_5 F2_LS_DISPENSER_SPARE_5 +const Int32 F2_LS_04_Direct = 0x60000480 ; // Reads the direct values that are currently being sent to the fpga. rsv rsv rsv rsv F2_LS_DISPENSER_UP_8 F2_LS_DISPENSER_25_8 F2_LS_DISPENSER_75_8 F2_LS_DISPENSER_DOWN_8 F2_LS_DISPENSER_50_8 F2_LS_DISPENSER_SPARE_8 F2_LS_DISPENSER_UP_7 F2_LS_DISPENSER_25_7 F2_LS_DISPENSER_75_7 F2_LS_DISPENSER_DOWN_7 F2_LS_DISPENSER_50_7 F2_LS_DISPENSER_SPARE_7 + +const Int32 Dispenser_Valve1 = 0; +const Int32 Dispenser_Valve2 = 1; +const Int32 Dispenser_Valve3 = 2; +const Int32 Dispenser_Valve4 = 3; +const Int32 Dispenser_Valve5 = 4; +const Int32 Dispenser_Valve6 = 5; +const Int32 Dispenser_Valve7 = 6; +const Int32 Dispenser_Valve8 = 7; + +const ushort MinPress_Mbar_Add =0x5c ; +const ushort MaxPress_Mbar_Add =0x60 ; + +const Int32 F3_VALVE_OUT = 0x600000e2; + +//string path = "C:\\Dispenser_setup\\Log\\"; + + +//Int32[] Start_Table; + +Int32[] Start_Table = new Int32 [10000]; + +UInt32 [] Motor_Dir=new UInt32 [8] {0,0,0,0,0,0,0,0}; + +string Dispenser_Fname ; + +Int32 Dispenser_ptr =-1; + +Int32 [] Dispenser_press= new Int32[8]{0,0,0,0,0,0,0,0}; +Int32 max_pressure_level = 20000; +Int32 min_pressure_level = -20000; + +Int32 [] A2D_Dispenser= new Int32[8]{0,0,0,0,0,0,0,0}; +Int32 Loop_cnt= 1; +Int32 Loop_length=1; + +Int32 PressureSensorType= 1; //1- new -1up +10 . 0-old 0 to +10 +Int32 Temp_Delay=0; + + +UInt32 RD_LS_01_Direct; +UInt32 RD_LS_02_Direct; +UInt32 RD_LS_03_Direct; +UInt32 RD_LS_04_Direct; + +long Lebel1_time; +long Lebel2_time; + +long time_Table; + +Int32 msec_index=0; + +Int32 MaxPress_Mbar; +Int32 MinPress_Mbar; +string state; + + public Int32 OnExecute(IProcedureContext context) + { + long Max_PBU; + Int32 Index=0; + Int32 speed=0; + Int32 Dispenser_Nm; + this.context = context; + + string box_msg = "Make sure Mixer Hot "; + MessageBox.Show(box_msg); + + var response1 = context.RequestUserInputFor<String>("Dispenser Number", "Enter Dispenser number to make priming (1-8):"); + context.WriteLine(response1); + Dispenser_Nm = Int32.Parse(response1); + + check_Min_Max_Mbar(Dispenser_Nm); + + if (Dispenser_Nm==8) + Max_PBU=6000; + else + Max_PBU=4000; + + + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + context.WriteLine(path); + + context.Send<ProgressResponse>("ProgressRequest" ,0xe0, 1); + + Dispenser_Fname=path + "Dispenser_Nm_" + Dispenser_Nm+"_" + DateTime.Now.ToString("MM-dd-yy hh-mm")+ ".csv" ; + + context.WriteLine(Dispenser_Fname); + + context.WriteToFile(Dispenser_Fname,"Dispenser Nm," + Dispenser_Nm + "\n" ); + context.AppendToFile(Dispenser_Fname,"Pressure,Command,Value,DateTime,Remark\n" ); + for(int j=0; j<2;j++) + { + for(int i=0; i<4;i++) + { + state="PBU No. "+ (4*j+i+1 ); + Start_Table=BuildUp_Table; + Table_Run(Dispenser_Nm ); + if (time_Table>300000) + { + context.AddResult(ResultType.Failed,"PBU", "PBU No."+ (4*j+i+1 ) + " Fail"); + return 0; + } + context.AddResult(ResultType.Passed,"PBU","PBU No."+ (4*j+i+1 ) + " Pass"); + + } + state="Flow No."+ (j+1 ) ; + Start_Table=Up_Table; + Table_Run(Dispenser_Nm ); + if (time_Table<115000) + { + context.WriteLine("time_Table= " +time_Table); + context.AddResult(ResultType.Failed,"Flow", "Flow No."+ (j+1) + " Fail"); + return 0; + } + context.AddResult(ResultType.Passed,"Flow","Flow No."+ (j+1 ) + " Pass"); + + } + state="Last PBU " ; + Start_Table=BuildUp_Table; + Table_Run(Dispenser_Nm ); + long Time=Lebel2_time-Lebel1_time; + if (Time>Max_PBU) + { + context.AddResult(ResultType.Failed,"PBU", "PBU = " +Time + "msec "); + state="PBU = " +Time + "msec \tFail"; + } + else + { + context.AddResult(ResultType.Passed,"PBU", "PBU = " +Time + "msec "); + state="PBU = " +Time + "msec \tPass"; + } + return 0; + + } + +///////////////////////////////////////////// +void check_Min_Max_Mbar(Int32 i ) +{ + int k; + string s ; + i--; + + context.WriteLine("-------------- write Enable Channel ------------"); //debug + enable_channel(i); // Chanel 0-7 => Disp0enser 0-7 + context.WriteLine("-------------- Read_header ------------"); //debug + + context.WriteLine("-------------- write_address_eeprom ------------"); //debug + write_address_eeprom (I2C_Slave_Low_Add,MinPress_Mbar_Add); + context.WriteLine("-------------- read_data_from_eeprom ------------"); //debug + read_data_from_eeprom (I2C_Slave_Low_Add,1); + if (EEPROM_Data[0]==0 ) + { PressureSensorType=0; + context.WriteLine("PressureSensorType=0" ); //debug + } + else + { + PressureSensorType=1; + context.WriteLine("PressureSensorType=1" ); //debug + } + +} +//----------------write address eeprom ------------------------- +public void write_address_eeprom (UInt32 I2C_Add, UInt32 Eeprom_Add) +{ + StubI2CWriteBytesRequest stubI2CWriteBytesRequest = new StubI2CWriteBytesRequest(); + stubI2CWriteBytesRequest.I2CId = I2C_ID; + stubI2CWriteBytesRequest.SlaveAddress = I2C_Add; + + UInt32 uInt32 = new UInt32(); + stubI2CWriteBytesRequest.BytesTWrite.Add(Convert.ToByte( (Eeprom_Add & 0xff00) >>8)); //Byte High add to write + stubI2CWriteBytesRequest.BytesTWrite.Add(Convert.ToByte(Eeprom_Add & 0xff)); //Byte Low add to write + context.WriteLine( (Eeprom_Add & 0xff00) >>8) ; //debug + context.WriteLine( Eeprom_Add & 0xff); //debug + + context.Send<StubI2CWriteBytesResponse>(stubI2CWriteBytesRequest); +} +//------------------- read Data from EEprom-------------------------- + +public void read_data_from_eeprom ( UInt32 I2C_Add, UInt32 cnt ) +{ + StubI2CReadBytesRequest stubI2CReadBytesRequest = new StubI2CReadBytesRequest(); + stubI2CReadBytesRequest.I2CId = I2C_ID; + stubI2CReadBytesRequest.SlaveAddress = (I2C_Add + 1); + stubI2CReadBytesRequest.NumberOfBytesToRead = cnt; // Number of bytes to read + + var response1 = context.Send<StubI2CReadBytesResponse>(stubI2CReadBytesRequest); + + for(int i=0; i<cnt;i++) + { + EEPROM_Data[i]=Convert.ToByte(response1.ReadBytes[i]); + context.WriteLine(EEPROM_Data[i] ); //debug + + } +} + + +/////////////////////////////////////////////// +//----------- enable I2c channel -------------- +public int enable_channel(Int32 Channel_ID) +{ + uint Const_temp = 0x01; + + StubI2CWriteBytesRequest stubI2CWriteBytesRequest = new StubI2CWriteBytesRequest(); + stubI2CWriteBytesRequest.I2CId = I2C_ID; + stubI2CWriteBytesRequest.SlaveAddress = TCA9548A_address; + + Const_temp = Const_temp << Channel_ID; + stubI2CWriteBytesRequest.BytesTWrite.Add(Const_temp);//enable i2c channel 0 Dispenser 1 + + var response = context.Send<StubI2CWriteBytesResponse>(stubI2CWriteBytesRequest); + + return 1; +} + + +////////////////////////////////////////////////////////////// +Int32 Table_Run(Int32 Dispenser ) + +{ + Int32 COMMAND=0; + Int32 Data=0; + Int32 count=0; + + Dispenser--; //check from 0-7 + + int j=0; + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + long elapsed_time = stopwatch.ElapsedMilliseconds; + context.WriteLine(elapsed_time); + + while (count!=-1) + { + msec_index=msec_index+1; + + if (Dispenser<2) + { + var response1 = context.Send<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F2_LS_01_Direct); + RD_LS_01_Direct=response1.Value ; + } + else if ( (Dispenser<4) ) + { + var response1 = context.Send<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F2_LS_02_Direct); + RD_LS_02_Direct=response1.Value ; + } + else if ( (Dispenser<6) ) + { + var response1 = context.Send<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F2_LS_03_Direct); + RD_LS_03_Direct=response1.Value ; + } + else + { + var response1 = context.Send<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F2_LS_04_Direct); + RD_LS_04_Direct=response1.Value ; + } + if (Dispenser<4) + { + var response2 = context.Send<StubIntADCReadResponse>("StubIntADCReadRequest" ,0x8000 + AN_IDS_PRESSENS_1); + A2D_Dispenser[0]=(response2.SamplingInBits)>>16; + A2D_Dispenser[1] =(response2.SamplingInBits) & 0x0000ffff; + A2D_Dispenser[2] =(response2.VoltageSamplingMv)>>16; + A2D_Dispenser[3] =(response2.VoltageSamplingMv) & 0x0000ffff; + } + else + { + var response3 = context.Send<StubIntADCReadResponse>("StubIntADCReadRequest" ,0x8000 + AN_IDS_PRESSENS_5); + A2D_Dispenser[4] =(response3.SamplingInBits)>>16; + A2D_Dispenser[5] =(response3.SamplingInBits)& 0x0000ffff; + A2D_Dispenser[6] =(response3.VoltageSamplingMv)>>16; + A2D_Dispenser[7] =(response3.VoltageSamplingMv)& 0x0000ffff; + } + + COMMAND=Start_Table[count]; + Data=Start_Table[(count+1)]; + //Index=Index+2; + switch (COMMAND) + { + case CMD_RUN: + Motor_Run(Data,Dispenser); + count = count+2; + break; + + case CMD_VALVE: + Valve_3W(Data,Dispenser); + count = count+2; + break; + + case CMD_STOP: + Motor_Stop(Data,Dispenser); + count = count+2; + break; + + case CMD_DLY: + Delay_on_second(Data,Dispenser); + if (Temp_Delay ==0) + { + max_pressure_level=20000; + min_pressure_level=-20000; + count = count+2; + } + break; + + case CMD_TIME: + Print_Time(); + count = count+2; + break; + + case CMD_PRESS: + max_pressure_level=Data; + context.AppendToFile(Dispenser_Fname,",Max_pressure_level is, " + Data +","+DateTime.Now+"\n"); + count = count+2; + break; + + case CMD_PRESL: + min_pressure_level=Data; + context.AppendToFile(Dispenser_Fname,",Min_pressure_level is, " + Data +","+DateTime.Now+"\n"); + count = count+2; + break; + + case CMD_LBL: + context.AppendToFile(Dispenser_Fname,",Label," + Data+","+DateTime.Now+"\n"); + if(Data==1) + Lebel1_time=stopwatch.ElapsedMilliseconds; + if(Data==2) + Lebel2_time=stopwatch.ElapsedMilliseconds; + count = count+2; + break; + + + case CMD_SMP: + context.AppendToFile(Dispenser_Fname,",SampleRate," + Data+","+DateTime.Now+"\n"); + Dispenser_sample_rate =Data; + count = count+2; + break; + + case CMD_END: + count=-1; + context.AppendToFile(Dispenser_Fname,",End testing,,"+DateTime.Now+"\n"); + break; + + case CMD_MTV_OPEN: + open_midtank_valve(Data,Dispenser); + context.AppendToFile(Dispenser_Fname,",OPEN MIDTANK, " + Dispenser+","+DateTime.Now+"\n"); + count = count+2; + break; + + case CMD_MTV_CLOSE: + close_midtank_valve(Data,Dispenser); + context.AppendToFile(Dispenser_Fname,",CLOSE MIDTANK, " + Dispenser+","+DateTime.Now+"\n"); + count = count+2; + break; + + case CMD_LOOP_NM: + + Loop_cnt=Data-1; + context.AppendToFile(Dispenser_Fname,",Counter Loop,"+ Data+","+DateTime.Now +"\n"); + count = count+2; + break; + + case CMD_LOOP: + + if (Loop_cnt!=0) + { + context.AppendToFile(Dispenser_Fname,"Counter Loop,"+ Loop_cnt+","+DateTime.Now+"\n" ); + count = count+2*Data; + Loop_cnt--; + + } + else + { + context.AppendToFile(Dispenser_Fname,",End loop,,"+DateTime.Now +"\n"); + count = count+2; + } + break; + + default: + break; + + } + + long elapsed_time1 = stopwatch.ElapsedMilliseconds; + long elapsed_time2= elapsed_time1-elapsed_time; + if (elapsed_time2>95) + elapsed_time2=95; //minimum time + Thread.Sleep(100-(int )(elapsed_time2)); + + elapsed_time = stopwatch.ElapsedMilliseconds; + + + j++; + if (j==10) + { + j=0; + context.WriteLine(Dispenser_press[Dispenser]+ " mBar\t"+state + "\tTime-" + (elapsed_time/1000)); + } + } + time_Table=elapsed_time; + return 0; +} + +/////////////////////////////////////////////////////////////////// +Int32 Motor_Run(Int32 speed,Int32 Dispenser) + +{ + + switch (Dispenser) + { + case 0: + if ( speed<0) + { + Motor_Dir[0]=2; + if ((RD_LS_01_Direct & 0x04)!=0x04) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now +",Warning Motor on Limit\n"); + return 0; + } + + context.Send<StubMotorRunResponse>("StubMotorRunRequest" ,Dispenser_Motor1, false, (-speed)); + } + else + { + Motor_Dir[0]=1; + if ((RD_LS_01_Direct & 0x20)!=0x20) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now +",Warning Motor on Limit\n"); + return 0; + } + context.Send<StubMotorRunResponse>("StubMotorRunRequest" ,Dispenser_Motor1, true, (speed)); + } + break; + + case 1: + if ( speed<0) + { + Motor_Dir[1]=2; + if ((RD_LS_01_Direct & 0x100)!=0x100) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now +",Warning Motor on Limit\n"); + return 0; + } + context.Send<StubMotorRunResponse>("StubMotorRunRequest" ,Dispenser_Motor2, false, (-speed)); + } + else + { + Motor_Dir[1]=1; + if ((RD_LS_01_Direct & 0x800)!=0x800) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now +",Warning Motor on Limit\n"); + return 0; + } + context.Send<StubMotorRunResponse>("StubMotorRunRequest" ,Dispenser_Motor2, true, (speed)); + } + break; + + case 2: + if ( speed<0) + { + Motor_Dir[2]=2; + if ((RD_LS_02_Direct & 0x04)!=0x04) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now +",Warning Motor on Limit\n"); + return 0; + } + context.Send<StubMotorRunResponse>("StubMotorRunRequest" ,Dispenser_Motor3, false, (-speed)); + } + else + { + Motor_Dir[2]=1; + if ((RD_LS_02_Direct & 0x20)!=0x20) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now+ ",Warning Motor on Limit\n"); + return 0; + } + context.Send<StubMotorRunResponse>("StubMotorRunRequest" ,Dispenser_Motor3, true, (speed)); + } + break; + + case 3: + if ( speed<0) + { + Motor_Dir[3]=2; + + if ((RD_LS_02_Direct & 0x100)!=0x100) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now+ ",Warning Motor on Limit\n"); + return 0; + } + context.Send<StubMotorRunResponse>("StubMotorRunRequest" ,Dispenser_Motor4, false, (-speed)); + } + else + { + Motor_Dir[3]=1; + + if ((RD_LS_02_Direct & 0x800)!=0x800) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now +",Warning Motor on Limit\n"); + return 0; + } + context.Send<StubMotorRunResponse>("StubMotorRunRequest" ,Dispenser_Motor4, true, (speed)); + } + break; + + case 4: + if ( speed<0) + { + Motor_Dir[4]=2; + if ((RD_LS_03_Direct & 0x04)!=0x04) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now+ ",Warning Motor on Limit\n"); + return 0; + } + + context.Send<StubMotorRunResponse>("StubMotorRunRequest" ,Dispenser_Motor5, false, (-speed)); + } + else + { + Motor_Dir[4]=1; + if ((RD_LS_03_Direct & 0x20)!=0x20) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now+ ",Warning Motor on Limit\n"); + return 0; + } + context.Send<StubMotorRunResponse>("StubMotorRunRequest" ,Dispenser_Motor5, true, (speed)); + } + break; + + case 5: + if ( speed<0) + { + Motor_Dir[5]=2; + if ((RD_LS_03_Direct & 0x100)!=0x100) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now +",Warning Motor on Limit\n"); + return 0; + } + context.Send<StubMotorRunResponse>("StubMotorRunRequest" ,Dispenser_Motor6, false, (-speed)); + } + else + { + Motor_Dir[5]=1; + if ((RD_LS_03_Direct & 0x800)!=0x800) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now+ ",Warning Motor on Limit\n"); + return 0; + } + context.Send<StubMotorRunResponse>("StubMotorRunRequest" ,Dispenser_Motor6, true, (speed)); + } + break; + + case 6: + if ( speed<0) + { + Motor_Dir[6]=2; + if ((RD_LS_04_Direct & 0x04)!=0x04) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now +",Warning Motor on Limit\n"); + return 0; + } + context.Send<StubMotorRunResponse>("StubMotorRunRequest" ,Dispenser_Motor7, false, (-speed)); + } + else + { + Motor_Dir[6]=1; + if ((RD_LS_04_Direct & 0x20)!=0x20) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now +",Warning Motor on Limit\n"); + return 0; + } + context.Send<StubMotorRunResponse>("StubMotorRunRequest" ,Dispenser_Motor7, true, (speed)); + } + break; + + case 7: + if ( speed<0) + { + Motor_Dir[7]=2; + + if ((RD_LS_04_Direct & 0x100)!=0x100) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now +",Warning Motor on Limit\n"); + return 0; + } + context.Send<StubMotorRunResponse>("StubMotorRunRequest" ,Dispenser_Motor8, false, (-speed)); + } + else + { + Motor_Dir[7]=1; + + if ((RD_LS_04_Direct & 0x800)!=0x800) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now +",Warning Motor on Limit\n"); + return 0; + } + context.Send<StubMotorRunResponse>("StubMotorRunRequest" ,Dispenser_Motor8, true, (speed)); + } + break; + + default: + break; + + } + context.AppendToFile(Dispenser_Fname,",Run," +speed+","+DateTime.Now +"\n" ); + + return 1; +} + + + Int32 Valve_3W(Int32 Valve_Value,Int32 Dispenser) +{ + if ( Valve_Value==1) + context.Send<StubValveResponse>("StubValveRequest" ,Dispenser_Valve1+Dispenser, 3, true); //3 3Way + else + context.Send<StubValveResponse>("StubValveRequest" ,Dispenser_Valve1+Dispenser, 3, false); //3 3Way + + context.AppendToFile(Dispenser_Fname,",Dispenser Valve position is, " + Valve_Value+","+DateTime.Now +"\n" ); + + return 1; +} +//--------------------------------------- + + Int32 Motor_Stop(Int32 Stop_Value,Int32 Dispenser ) +{ + context.Send<StubMotorStopResponse>("StubMotorStopRequest" ,Dispenser_Motor1+Dispenser, Stop_Value); + + context.AppendToFile(Dispenser_Fname,",Motor Stop," + Stop_Value+","+DateTime.Now +"\n"); + Motor_Dir[Dispenser]=0; + return 1; +} + +//--------------------------------------- + + Int32 Delay_on_second(Int32 Delay,Int32 Dispenser ) +{ +//Int32 temp1; +Int32 pressure_om_mBAR=0; + if (Temp_Delay ==0) + { + context.AppendToFile(Dispenser_Fname,",DLY, " + Delay +","+DateTime.Now+"\n"); + Temp_Delay = Delay *10 -1; +// context.Write("A"); //debug + } + else + Temp_Delay--; + + if ( LimitSW_Dispenser(Dispenser)==0) + { + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now+",Warning Motor on Limit\n"); + MotorStop(Dispenser); + Temp_Delay =0; //end delay +// context.Write("C"); //debug + + return 0 ; + } + + pressure_om_mBAR=Calc_mBAR(Dispenser,true); + if (pressure_om_mBAR > max_pressure_level) + { + // MotorStop(Dispenser); + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now +",Warning Pressure too high\n"); + Temp_Delay =0; //end delay +// context.Write("D"); //debug + + return 0; + } + if (pressure_om_mBAR < min_pressure_level) + { + // MotorStop(Dispenser); + context.AppendToFile(Dispenser_Fname,",,,"+DateTime.Now +",Warning Pressure too low\n"); + Temp_Delay =0; //end delay +// context.Write("D"); //debug + + return 0; + } + + + return 1; +} + +Int32 LimitSW_Dispenser(Int32 Dispenser) +{ + + if (Dispenser==0) + + { + +// var response1 = context.Send<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F2_LS_01_Direct); + + if (((RD_LS_01_Direct & 0x04)!=0x04) && (Motor_Dir[0]==2)) + return 0; + else + if (((RD_LS_01_Direct & 0x20)!=0x20) && (Motor_Dir[0]==1)) + return 0; + else + return 1; + } + + if (Dispenser==1) + + { +// var response2 = context.Send<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F2_LS_01_Direct); + if (((RD_LS_01_Direct & 0x100)!=0x100) && (Motor_Dir[1]==2)) + return 0; + else + if (((RD_LS_01_Direct & 0x800)!=0x800) && (Motor_Dir[1]==1)) + return 0; + else + return 1; + } + + + if (Dispenser==2) + + { + + //var response3 = context.Send<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F2_LS_02_Direct); + if (((RD_LS_02_Direct & 0x04)!=0x04) && (Motor_Dir[2]==2)) + return 0; + else + if (((RD_LS_02_Direct & 0x20)!=0x20) && (Motor_Dir[2]==1)) + return 0; + else + return 1; + + } + + if (Dispenser==3) + + { + var response4 = context.Send<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F2_LS_02_Direct); + if (((RD_LS_02_Direct & 0x100)!=0x100) && (Motor_Dir[3]==2)) + return 0; + else + if (((RD_LS_02_Direct & 0x800)!=0x800) && (Motor_Dir[3]==1)) + return 0; + else + return 1; + } + + + + + if (Dispenser==4) + + { + +// var response1 = context.Send<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F2_LS_01_Direct); + if (((RD_LS_03_Direct & 0x04)!=0x04) && (Motor_Dir[4]==2)) + return 0; + else + if (((RD_LS_03_Direct & 0x20)!=0x20) && (Motor_Dir[4]==1)) + return 0; + else + return 1; + } + + if (Dispenser==5) + + { +// var response2 = context.Send<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F2_LS_01_Direct); + if (((RD_LS_03_Direct & 0x100)!=0x100) && (Motor_Dir[5]==2)) + return 0; + else + if (((RD_LS_03_Direct & 0x800)!=0x800) && (Motor_Dir[5]==1)) + return 0; + else + return 1; + } + + + if (Dispenser==6) + + { + + //var response3 = context.Send<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F2_LS_02_Direct); + if (((RD_LS_04_Direct & 0x04)!=0x04) && (Motor_Dir[6]==2)) + return 0; + else + if (((RD_LS_04_Direct & 0x20)!=0x20) && (Motor_Dir[6]==1)) + return 0; + else + return 1; + + } + + if (Dispenser==7) + + { +// var response4 = context.Send<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F2_LS_02_Direct); + if (((RD_LS_04_Direct & 0x100)!=0x100) && (Motor_Dir[7]==2)) + return 0; + else + if (((RD_LS_04_Direct & 0x800)!=0x800) && (Motor_Dir[7]==1)) + return 0; + else + return 1; + } + + + return 0; +} + + +Int32 Print_Time() +{ + context.AppendToFile(Dispenser_Fname,",Time is\t,,"+ DateTime.Now +"\n" ); + + return 1; +} + + + +Int32 Calc_mBAR(Int32 Dispenser, bool save_press) +{ +Int32 Data; +Int32 Sense1; +Int32 temp=0; + + Data =A2D_Dispenser[Dispenser]; + if (Data<100) + temp=-1; + Data=Data-710; + if (Data<0) + Data=0; + + Data=Data*(10000+PressureSensorType*1000)/2840; // for -1 to 10 bar Press_Sensor_Type=1 else 0 + Data=Data-1000*PressureSensorType; // for -1 to 10 bar + + if (temp==-1) //if SamplingInBits <100 then No pressure sensor exist + Sense1=-9999 ; + else + Sense1=Data ; + if ( ((msec_index) % (Dispenser_sample_rate)) == 0) + { + context.AppendToFile(Dispenser_Fname,"" + Sense1+"\n"); + } + Dispenser_press[Dispenser]=Sense1; + return Sense1; + + } + + +//-------------------------------- +int open_midtank_valve (Int32 valve_type,Int32 valve_nm) //valve_type=0 is Air ,1 is Ink ; valve_nm 0-7 +{ + SetBit (F3_VALVE_OUT,((valve_type+1)*8)- valve_nm-1, 1); + return 1; + +} +//-------------------------------- +int close_midtank_valve (Int32 valve_type,Int32 valve_nm) //valve_type=0 is Air ,1 is Ink ; valve_nm 0-7 +{ + SetBit (F3_VALVE_OUT,((valve_type+1)*8)- valve_nm-1, 0); + return 1; +} +//-------------------------------- +Int32 SetBit(Int32 Adr, Int32 BitNo, Int32 Bit) +{ + Int32 BitMask; + + var response = context.Send<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" , F3_VALVE_OUT); + Int32 RV = (Int32) response.Value & 0xffff; + + + if (Bit == 0x1) + { + BitMask = 0x1 << BitNo; + RV = RV | BitMask; + context.Send<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,F3_VALVE_OUT , RV); + } + else if (Bit == 0x0) + { + BitMask = ~(0x1 << BitNo); + RV = RV & BitMask; + context.Send<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,F3_VALVE_OUT , RV); + } + return 1; +} +//---------------------------------- + void MotorStop(Int32 i) +{ + +context.Send<StubMotorStopResponse>("StubMotorStopRequest" ,Dispenser_Motor1+i, 2); +Motor_Dir[i]=0; //0 stop 1- up 2-dn + +} + +}
\ No newline at end of file diff --git a/Software/Stubs Collection/Procedures/WHS_waste_Tank_Calibration_Save_V0.pproj b/Software/Stubs Collection/Procedures/WHS_waste_Tank_Calibration_Save_V0.pproj new file mode 100644 index 000000000..3bd4b1f84 --- /dev/null +++ b/Software/Stubs Collection/Procedures/WHS_waste_Tank_Calibration_Save_V0.pproj @@ -0,0 +1,107 @@ +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; + + +public class Program +{ + double V0_default_ml = 8.7433; + + public void OnExecute(IProcedureContext context) + { + + var response1 = context.RequestUserInputFor<String>("Warning - you are going to change the value of Vo in the eeprom !!!\nPlease Enter Password to confirme:",""); + if (response1=="Aa123456") + { + context.WriteLine(response1); + + //Write_0_Vo_in_ml_to_eeprom + context.WriteLine("\nWrite_0_Vo_in_ml_to_eeprom"); + StubWhsEEpromRequest stubWhsEEpromRequest = new StubWhsEEpromRequest(); + stubWhsEEpromRequest.BurnRequest = true; //write + StubWhsEEpromData stubWhsEEpromData = new StubWhsEEpromData(); + stubWhsEEpromData.Orifice1Flow = 0; + stubWhsEEpromRequest.WhsEEprom = stubWhsEEpromData; + var response = context.Send<StubWhsEEpromResponse>(stubWhsEEpromRequest); + + //wait_10mSec + context.WriteLine("\nwait_10mSec"); + Thread.Sleep(100); //Sleep for 10 milli. + + //Read_Vo_in_ml_from_eeprom & verify it is 0 + context.WriteLine("\nRead_Vo_in_ml_from_eeprom & verify it is 0"); + stubWhsEEpromRequest.BurnRequest = false; //write + stubWhsEEpromRequest.WhsEEprom = stubWhsEEpromData; + var response2 = context.Send<StubWhsEEpromResponse>(stubWhsEEpromRequest); + + //Read_Vo_in_mV + context.WriteLine("\nRead_Vo_in_mV"); + var response3 = context.Send<ProgressResponse>("ProgressRequest" ,0x3EC, 0x01); + //Print_Vo_in_mV + context.WriteLine(response3.Progress); + + //check validity + context.WriteLine("\ncheck validity"); + if((response3.Progress <= 800) || (response3.Progress >=1200)) + { + response3.Progress = 1076; //default + context.Write("\nERROR ------ Vreading value outside the defined range !!! ------"); + context.AddResult(ResultType.Failed , "Error", "ERROR ------ Vreading value outside the defined range !!! ------"); + } + else + { + //calculate_V0_in_ml + context.WriteLine("\ncalculate_V0_in_ml"); + V0_default_ml = V0_default_ml * response3.Progress; + + //print_Vo_in_ml + context.WriteLine("\nprint_Vo_in_ml"); + context.WriteLine(V0_default_ml); + context.WriteLine(""); + + //Write_Vo_in_ml_to_eeprom + context.WriteLine("\nWrite_Vo_in_ml_to_eeprom"); + stubWhsEEpromRequest.BurnRequest = true; //write + + stubWhsEEpromData.Orifice1Flow = V0_default_ml; + stubWhsEEpromRequest.WhsEEprom = stubWhsEEpromData; + var response4 = context.Send<StubWhsEEpromResponse>(stubWhsEEpromRequest); + + //wait_10mSec + context.WriteLine("\nwait_10mSec"); + Thread.Sleep(100); //Sleep for 10 milli. + + //Read_Vo_in_ml_from_eeprom + context.WriteLine("\nRead_Vo_in_ml_from_eeprom"); + stubWhsEEpromRequest.BurnRequest = false; //write + stubWhsEEpromRequest.WhsEEprom = stubWhsEEpromData; + var response5 = context.Send<StubWhsEEpromResponse>(stubWhsEEpromRequest); + + //Check if we read the correct value + context.WriteLine("\nVerify that we read the correct value of Orifice1Flow!!"); + context.AddResult(ResultType.Passed , "Pass", "Calibration Pass."); + + } + } + else + { + context.AddResult(ResultType.Failed , "Error", "Password Fail."); + } + context.WriteLine("\n -- END OF SCRIPT -- "); + } +} + |
