TYFangKuaiChaXiaoJi.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564
  1. #include "global.h"
  2. #if TONG_YONG_MACHINE
  3. unsigned char FKCX_cGeiLiaoNum,FKCX_bStopOver,FKCX_bStopXiao,FKCX_bStopFang,FKCX_bStopXiaCong = 0,FKCX_bXiaCong;
  4. unsigned short cCountOutTime;
  5. /**************************************
  6. ** 函数名称:void ChaXiaoJi(void)
  7. ** 函数功能:方块插稍机动作函数
  8. ** 输入输出说明:
  9. 输入:
  10. X0 插销启动
  11. X1 停止开关
  12. X2 方块启动
  13. X3 手动钩针
  14. X4 手动压带
  15. X5 方块.插销选择
  16. X6 手动给料
  17. X7 手动夹料
  18. X10 手动送料
  19. X11 手动下冲
  20. X12 过链接近开关
  21. X13 下冲感应接近开关
  22. X14 夹插销光电开关
  23. X15 夹方块光电开关
  24. X16 送插销到位磁感
  25. X17 退送插销到位磁感
  26. X20 送方块到位磁感
  27. X21 退送方块到位磁感
  28. X22 压带磁感
  29. X23 给插销磁感
  30. X24 给方块磁感
  31. X25 冲针选择
  32. X26 冲针保护
  33. X27 打单边
  34. 输出:
  35. Y0 离合器
  36. Y1 计数
  37. Y2 插销运行指示 (触摸屏时为振动盘)
  38. Y3 方块运行指示 (触摸屏时为警告蜂鸣器)
  39. Y4 方块垫块电磁阀
  40. Y5 压带电磁阀
  41. Y6 下冲电磁阀
  42. Y7 插销垫块电磁阀
  43. Y10 给插销电磁阀
  44. Y11 夹插销电磁阀
  45. Y12 送插销电磁阀
  46. Y13 送方块电磁阀
  47. Y14 夹方块电磁阀
  48. Y15 给方块电磁阀
  49. Y16 勾针电磁阀
  50. Y017 冲子选择电磁阀
  51. D0 给插销(方块)到位后延时退回
  52. D1 送插捎(方块)到位夹打开延时退回
  53. D2 下冲输出时间
  54. D3 给料次数
  55. D4 给料故障后下一次给料时间
  56. D5 给料到前点的最长时间
  57. D6 延时停离合
  58. D7 延时上勾针
  59. D8 普通方块插销设置(2.55)
  60. 上下拉方块插销设置(0.55)
  61. D9 加速时间
  62. D10 起动速度
  63. D11 最高速度
  64. D12 下冲感应方式(0 老方式 1 新常亮方式)
  65. ***************************************/
  66. unsigned char FKCX_cReady,FKCX_cHalfRun,FKCX_cYaDai,FKCX_cSelectXiaChong,FKCX_YaDaiError,FKCX_cXiaChongStep = 0,FKCX_bRunning,FKCX_bStop;
  67. unsigned long FKCX_cErrorTime,FKCX_cErrorTime1,FKCX_cStartKeyDelay,FKCX_cTotal,FKCX_cTestNum,FKCX_cErrorTime2;
  68. unsigned long FKCX_JiaXiao(unsigned long En_Dis);
  69. unsigned long FKCX_SongXiao(unsigned long En_Dis);
  70. unsigned long FKCX_Motor(unsigned long En_Dis);
  71. unsigned long FKCX_JiaFang(unsigned long En_Dis);
  72. unsigned long FKCX_SongFang(unsigned long En_Dis);
  73. void FKCX_XiaChongStep(void);
  74. //故障报警
  75. void FKCX_SetAlarmCode(unsigned alarm_code)
  76. {
  77. SetAlarmCode(FKCX_ALARM_ADDR,alarm_code);
  78. FKCX_bStop = 1;
  79. }
  80. void FKCX_InitAction(void)
  81. {
  82. XGearRatio = 1;
  83. YGearRatio = 1;
  84. }
  85. void FKCX_XiaChongStep(void)
  86. {
  87. static unsigned long dwXiaChongDelay;
  88. unsigned short ch,i;
  89. switch(FKCX_cXiaChongStep)
  90. {
  91. case 1:
  92. {
  93. if(FKCX_XC_ENABLE)
  94. {
  95. AxisMoveTwoPos(Y_AXIS,FKCX_XC_SPEED,2000,1,9999999,0);
  96. SETY006();
  97. }
  98. else
  99. FKCX_cXiaChongStep = 0;
  100. }
  101. break;
  102. case 2:
  103. {
  104. if(X13_UP)
  105. {
  106. dwXiaChongDelay = dwTickCount + user_datas[17]*10;
  107. FKCX_cXiaChongStep = 3;
  108. }
  109. else if(dwTickCount >= dwXiaChongDelay)
  110. {
  111. FKCX_SetAlarmCode(16);
  112. }
  113. }
  114. break;
  115. case 3:
  116. {
  117. if(dwTickCount >= dwXiaChongDelay)
  118. {
  119. AxisEgmStop(Y_AXIS);
  120. CLRY006();
  121. FKCX_cXiaChongStep = 4;
  122. }
  123. }
  124. break;
  125. case 4:
  126. {
  127. if(!Y_DRV) FKCX_cXiaChongStep = 0;
  128. }
  129. break;
  130. case 10:
  131. {
  132. AxisMoveTwoPos(Y_AXIS,FKCX_XC_SPEED,2000,1,0,0);
  133. SETY006();
  134. dwXiaChongDelay = dwTickCount + 50;
  135. FKCX_cXiaChongStep = 11;
  136. }
  137. break;
  138. case 11:
  139. {
  140. if(dwTickCount >= dwXiaChongDelay)
  141. {
  142. AxisEgmStop(Y_AXIS);
  143. CLRY006();
  144. FKCX_cXiaChongStep = 0;
  145. }
  146. }
  147. break;
  148. case 20:
  149. {
  150. AxisContinueMove(Y_AXIS,FKCX_XC_SPEED,FKCX_DIR_P);
  151. FKCX_cXiaChongStep = 21;
  152. SETY006();
  153. }
  154. break;
  155. default:;
  156. }
  157. }
  158. void FKCX_Action(void)
  159. {
  160. unsigned long i,j;
  161. static unsigned long c10msDelay = 0;
  162. if(FKCX_bRunning)
  163. {
  164. if(FKCX_cHalfRun == 0)
  165. {
  166. M00 = 0;
  167. M01 = 0;
  168. M03 = 0;
  169. M04 = 0;
  170. M05 = 0;
  171. M06 = 0;
  172. M07 = 0;
  173. M08 = 0;
  174. M09 = 0;
  175. M10 = 0;
  176. M11 = 0;
  177. M12 = 0;
  178. M13 = 0;
  179. M14 = 0;
  180. }
  181. }
  182. else
  183. {
  184. if(M12 == 0)SETDR();
  185. }
  186. if(dwTickCount >= c10msDelay)
  187. {
  188. c10msDelay = dwTickCount+10;
  189. if(cCountOutTime > 0)
  190. {
  191. cCountOutTime--;
  192. if(cCountOutTime == 0)CLRY001();
  193. }
  194. }
  195. if(!FKCX_bRunning)
  196. {
  197. if(M25)
  198. {
  199. M25 = 0; //M25
  200. if(FKCX_cXiaChongStep==0)FKCX_cXiaChongStep = 10;
  201. }
  202. if(M12)
  203. {
  204. if((cStepMByte2==0)&& !X_DRV)
  205. {
  206. MoveAction_Const_AccDec(X_AXIS, FKCX_DIR_P, user_datas[11],user_datas[10],user_datas[9],10);
  207. }
  208. }
  209. else
  210. {
  211. if((cStepMByte2==0) && X_DRV)
  212. {
  213. AxisEgmStop(X_AXIS);
  214. }
  215. }
  216. if(M27)
  217. {
  218. M27 = 0; //M27
  219. if(FKCX_cXiaChongStep==0)FKCX_cXiaChongStep = 20;
  220. }
  221. }
  222. if(M15) //M15 故障确定
  223. {
  224. M15 = 0;
  225. user_datas[100] = 0;
  226. cDelayTime7 = dwTickCount + 1010;
  227. CLRY003();
  228. }
  229. if(M09) //清产量
  230. {
  231. if(dwTickCount >= cDelayTime8)
  232. {
  233. M09 = 0;
  234. ClrcToTal(76);
  235. }
  236. }
  237. else
  238. {
  239. cDelayTime8 = dwTickCount + 200*10;
  240. }
  241. if(user_datas[71])
  242. SETY02();
  243. else
  244. CLRY02();
  245. //手动模式
  246. //手条件
  247. if((!X01 || Y04 || Y07) && !FKCX_bRunning)
  248. {
  249. if(!M10)
  250. {
  251. //变为插稍方式
  252. if(Y010) //插稍给料
  253. {
  254. M19 = 1;
  255. }
  256. if(Y011) //插稍夹料
  257. {
  258. M20 = 1;
  259. }
  260. if(Y012) //插稍夹料
  261. {
  262. M21 = 1;
  263. }
  264. }
  265. else
  266. {
  267. //变为方块方式
  268. if(Y015) //方块给料
  269. {
  270. M19 = 1;
  271. }
  272. if(Y014) //方块夹料
  273. {
  274. M20 = 1;
  275. }
  276. if(Y013) //方块夹料
  277. {
  278. M21 = 1;
  279. }
  280. }
  281. //手动下冲
  282. if(X11_UP || M08)
  283. {
  284. M08 = 0;
  285. if(dwTickCount >= cDelayTime7)
  286. {
  287. cDelayTime7 = dwTickCount + 10*10;
  288. // 送插销 送方块 退送插销到位 退送方块到位
  289. if((Y012 == 0) && (Y013 == 0) && (X017 != 0) && (X021 != 0)
  290. //勾针电磁阀 压带磁感 手动下冲 上升延
  291. &&(Y016 == 0) && (X022 != 0) && ((user_datas[12] == 0) || X013) )
  292. {
  293. //方块\插销选择
  294. if(X005 || (M10 == 0))//插销
  295. {
  296. SETY007();
  297. CLRY004();
  298. }
  299. else //方块
  300. {
  301. SETY004();
  302. CLRY007();
  303. }
  304. SETY006(); //下冲电磁阀
  305. if(FKCX_cXiaChongStep==0)FKCX_cXiaChongStep=1;
  306. cDelayTime1 = dwTickCount + user_datas[2]*10;
  307. FKCX_cErrorTime = dwTickCount + FKCX_ERRORTIME;
  308. M14 = 1; //M14
  309. }
  310. else //下冲条件不满足警告
  311. {
  312. SETY003();
  313. if(Y005 == 0)FKCX_SetAlarmCode(ERY05);
  314. else if(Y012 != 0)FKCX_SetAlarmCode(ERY12);
  315. else if(Y013 != 0)FKCX_SetAlarmCode(ERY13);
  316. else if(Y016 != 0)FKCX_SetAlarmCode(ERY16);
  317. else if(X017 == 0)FKCX_SetAlarmCode(ERX17);
  318. else if(X021 == 0)FKCX_SetAlarmCode(ERX21);
  319. else if(X013 == 0)FKCX_SetAlarmCode(ERX13);
  320. else FKCX_SetAlarmCode(ERX22);
  321. }
  322. }
  323. }
  324. if((Y006 != 0))
  325. {
  326. if(X13_DW || ((user_datas[12] == 0) && (dwTickCount >= cDelayTime1)))
  327. {
  328. if(!FKCX_XC_ENABLE)CLRY006(); //下冲
  329. cDelayTime1 = dwTickCount + 50;
  330. }
  331. }
  332. if((X013 != 0) && ((user_datas[12] == 0) || ((dwTickCount >= cDelayTime1) && !Y006)))
  333. {
  334. CLRY004(); //方块垫片
  335. CLRY007(); //方块垫片
  336. if(!FKCX_XC_ENABLE)CLRY006(); //下冲
  337. M16 = 0; //M16
  338. M14 = 0;
  339. }
  340. else if(M14 && (dwTickCount >= FKCX_cErrorTime) && (FKCX_XC_ENABLE==0)) //下冲故障警告
  341. {
  342. M14 = 0;
  343. FKCX_SetAlarmCode(12);
  344. SETY003();
  345. CLRY004(); //方块垫片
  346. CLRY007(); //方块垫片
  347. if(!FKCX_XC_ENABLE)CLRY006(); //下冲
  348. }
  349. //手动勾针
  350. if(X003 || (M3))
  351. {
  352. M3 = 0;
  353. if(dwTickCount >= cDelayTime7)
  354. {
  355. cDelayTime7 = dwTickCount + 60;
  356. if(Y016)CLRY016();
  357. // 方块垫片 插稍垫片 下冲
  358. else if((Y004 == 0) && (Y007 == 0) && (Y006 == 0) &&
  359. // 送插稍 送方块 送插稍到位 送方块到位
  360. (Y012 == 0) && (Y013 == 0) && (X016 == 0) && (X020 == 0))
  361. {
  362. SETY016();
  363. }
  364. else //勾针条件不满足警告
  365. {
  366. SETY003();
  367. if(Y004 != 0)FKCX_SetAlarmCode(ERY04);
  368. else if(Y006 != 0)FKCX_SetAlarmCode(ERY06);
  369. else if(Y007 != 0)FKCX_SetAlarmCode(ERY07);
  370. else if(Y012 != 0)FKCX_SetAlarmCode(ERY12);
  371. else if(Y013 != 0)FKCX_SetAlarmCode(ERY13);
  372. else if(X016 != 0)FKCX_SetAlarmCode(ERX16);
  373. else FKCX_SetAlarmCode(ERX20);
  374. }
  375. }
  376. }
  377. //手动勾针完成
  378. //手动压带
  379. if(X004 || M4)
  380. {
  381. M4 = 0;
  382. if(dwTickCount >= cDelayTime7)
  383. {
  384. cDelayTime7 = dwTickCount + 8*10;
  385. if(Y005)CLRY005();
  386. else
  387. {
  388. SETY005();
  389. FKCX_cErrorTime1 = dwTickCount + FKCX_ERRORTIME;
  390. FKCX_YaDaiError = 1;
  391. }
  392. }
  393. if(Y005) //压带
  394. FKCX_cYaDai = 1;
  395. else
  396. FKCX_cYaDai = 0;
  397. }
  398. if(X022)
  399. {
  400. FKCX_YaDaiError = 0;
  401. }
  402. if(FKCX_YaDaiError && Y005 && (!X022) && (dwTickCount >= FKCX_cErrorTime1))
  403. {
  404. SETY003();
  405. FKCX_SetAlarmCode(13);
  406. FKCX_YaDaiError = 0;
  407. }
  408. //手动压带完成
  409. //手动送料
  410. // 手动送料
  411. if(FKCX_SongXiao(FKCX_TRUE) == FKCX_TRUE)cStepMByte5 = 0;
  412. if(FKCX_SongFang(FKCX_TRUE) == FKCX_TRUE)cStepMByte6 = 0;
  413. if(X010 || M7)
  414. {
  415. SETDR();
  416. M7 = 0;
  417. if(dwTickCount >= cDelayTime7)
  418. {
  419. cDelayTime7 = dwTickCount + 10*10;
  420. if(X005 || (M10 == 0)) //手动送插销
  421. {
  422. CLRY013();
  423. if(Y012)
  424. {
  425. cStepMByte5 = 3;
  426. cDelayTime5 = dwTickCount + 5;
  427. }
  428. // 方块有料 勾针阀 插销垫片 方块垫片 下冲阀 给料电磁阀 给料前点
  429. else if((X015 != 0) && (Y016 == 0) && (Y007 == 0) && (Y004 == 0) && (Y006 == 0) && (Y010 == 0) && (X023 == 0))
  430. {
  431. SETY012();
  432. }
  433. else //送料不满足条件
  434. {
  435. SETY003();
  436. if(Y004 != 0)FKCX_SetAlarmCode(ERY04);
  437. else if(Y006 != 0)FKCX_SetAlarmCode(ERY06);
  438. else if(Y007 != 0)FKCX_SetAlarmCode(ERY07);
  439. else if(Y010 != 0)FKCX_SetAlarmCode(ERY10);
  440. else if(Y016 != 0)FKCX_SetAlarmCode(ERY16);
  441. else if(X015 == 0)FKCX_SetAlarmCode(ERX15);
  442. else if(X023 != 0)FKCX_SetAlarmCode(ERX23);
  443. }
  444. }
  445. else //手动送方块
  446. {
  447. CLRY012();
  448. if(Y13)
  449. {
  450. cStepMByte6 = 3;
  451. cDelayTime6 = dwTickCount + 5;
  452. }
  453. // 勾针阀 插销垫片 方块垫片 下冲阀 给料电磁阀 给料前点
  454. else if((Y016 == 0) && (Y007 == 0) && (Y004 == 0) && (Y006 == 0) && (Y015 == 0) && (X024 == 0))
  455. {
  456. SETY013();
  457. }
  458. else //送料不满足条件
  459. {
  460. SETY003();
  461. if(Y004 != 0)FKCX_SetAlarmCode(ERY04);
  462. else if(Y006 != 0)FKCX_SetAlarmCode(ERY06);
  463. else if(Y007 != 0)FKCX_SetAlarmCode(ERY07);
  464. else if(Y015 != 0)FKCX_SetAlarmCode(ERY15);
  465. else if(Y016 != 0)FKCX_SetAlarmCode(ERY16);
  466. else if(X024 != 0)FKCX_SetAlarmCode(ERX24);
  467. }
  468. }
  469. }
  470. }
  471. //手动送料完成
  472. //手动给料
  473. if(FKCX_JiaXiao(FKCX_TRUE) == FKCX_TRUE)cStepMByte3 = 0;
  474. if(FKCX_JiaFang(FKCX_TRUE) == FKCX_TRUE)cStepMByte4 = 0;
  475. if(X006 || M5)
  476. {
  477. M5 = 0;
  478. if(dwTickCount >= cDelayTime7)
  479. {
  480. cDelayTime7 = dwTickCount + 10*10;
  481. if(X005 || (M10 == 0)) //给插销
  482. {
  483. CLRY014();
  484. CLRY015();
  485. if(Y010)
  486. {
  487. CLRY011(); //夹插稍
  488. cStepMByte3 = 3;
  489. cDelayTime5 = dwTickCount + 50;
  490. }
  491. //送料在原点 在夹紧情况下无料 或夹张开 送料
  492. else if((X017 != 0) && (((Y011 == 0) && (X014 != 0)) || Y011) && (Y012 == 0)
  493. && (Y015 == 0) && (X021 != 0))
  494. {
  495. SETY010(); //给插稍
  496. SETY011(); //夹插稍
  497. }
  498. else //不满足给料
  499. {
  500. CLRY010();
  501. SETY003();
  502. if(((Y011 == 0) && (X014 == 0))) FKCX_SetAlarmCode(ERX14);
  503. else if(Y012 != 0) FKCX_SetAlarmCode(ERY12);
  504. else if(X017 == 0) FKCX_SetAlarmCode(ERX17);
  505. else FKCX_SetAlarmCode(ERX21);
  506. }
  507. }
  508. else //给方块
  509. {
  510. CLRY010();
  511. CLRY011();
  512. if((Y015))
  513. {
  514. CLRY014(); //夹方块
  515. cStepMByte4 = 3;
  516. cDelayTime6 = dwTickCount + 50;
  517. }
  518. //送料在原点 在夹紧情况下无料 或夹张开 送料
  519. else if((X021 != 0) && (((Y014 == 0) && (X015 != 0)) || Y014) && (Y013 == 0) &&(X017 != 0))
  520. {
  521. SETY015(); //给方块
  522. SETY014(); //夹方块
  523. }
  524. else //不满足给料
  525. {
  526. CLRY015();
  527. SETY003();
  528. if(((Y014 == 0) && (X015 == 0)))FKCX_SetAlarmCode(ERX15);
  529. else if(Y013 != 0) FKCX_SetAlarmCode(ERY13);
  530. else if(X021 == 0) FKCX_SetAlarmCode(ERX21);
  531. else FKCX_SetAlarmCode(ERX17);
  532. }
  533. }
  534. }
  535. }
  536. //手动给料完成
  537. //手动夹料
  538. if(X007 || M6)
  539. {
  540. M6 = 0;
  541. if(dwTickCount >= cDelayTime7)
  542. {
  543. cDelayTime7 = dwTickCount + 10*10;
  544. if(X005 || (M10 == 0) ) //给插销
  545. {
  546. CLRY014();
  547. if(Y011)
  548. CLRY011();
  549. else
  550. SETY011();
  551. }
  552. else //给方块
  553. {
  554. CLRY011();
  555. if(Y014)
  556. CLRY014();
  557. else
  558. SETY014();
  559. }
  560. }
  561. }
  562. //手动夹料完成
  563. }
  564. //互锁保护
  565. if((Y004 != 0) || (Y007 != 0))
  566. {
  567. CLRY012();
  568. CLRY013();
  569. }
  570. if((Y012 != 0) || (Y013 != 0))
  571. {
  572. CLRY004();
  573. CLRY007();
  574. }
  575. //新功能选择(冲针选择)
  576. if(X25_UP && (X27 == 0))
  577. {
  578. if(FKCX_cSelectXiaChong == 0)
  579. {
  580. FKCX_cSelectXiaChong = 1;
  581. if(Y007) //由垫片判断插稍还是方块
  582. {
  583. SETY017(); //插稍
  584. user_datas[88] = 1;
  585. }
  586. else
  587. {
  588. CLRY017();
  589. user_datas[88] = 0;
  590. }
  591. }
  592. else
  593. FKCX_cSelectXiaChong = 0;
  594. }
  595. else if(X027)
  596. {
  597. CLRY017(); //插稍
  598. }
  599. //手动下冲完成
  600. //自动
  601. //
  602. // 手动钩针 钩针输出 手动下冲 下冲输出
  603. if((FKCX_bRunning == 0) && (X003 == 0) && (Y016 == 0) && (X011 == 0) && (Y006 == 0) &&
  604. //手动给料 插稍给料 方块给料 手动夹料
  605. (X006 == 0) && (Y010 == 0) && (Y015 == 0) && (X007 == 0) &&
  606. //插稍夹料 方块夹料 手动送料 插稍送料 方块送料
  607. (Y011 == 0) && (Y014 == 0) && (X010 == 0) && (Y012 == 0) && (Y013 == 0) &&
  608. //方块选择 插稍送料原点 方块送料原点
  609. (X017 != 0) && (X021 != 0))
  610. {
  611. FKCX_cReady = 1;
  612. }
  613. else
  614. FKCX_cReady = 0;
  615. FKCX_XiaChongStep();
  616. //停止 故障停机 按停止键
  617. if((FKCX_bStop) || M2 || ((X01_UP) && (FKCX_cStartKeyDelay == 0)))
  618. {
  619. if(M2 || (X01_UP))
  620. CLRY003();
  621. FKCX_cStartKeyDelay = 8;
  622. FKCX_cHalfRun = 0;
  623. FKCX_bRunning = 0;
  624. AxisEgmStop(X_AXIS);
  625. if(FKCX_cXiaChongStep == 21)
  626. {
  627. AxisEgmStop(Y_AXIS);
  628. CLRY006();
  629. FKCX_cXiaChongStep = 0;
  630. }
  631. SETDR(); //电机放松
  632. M2 = 0;
  633. if(FKCX_bStopOver < 2)
  634. {
  635. FKCX_bStopOver++;
  636. }
  637. else
  638. FKCX_bStopOver = 0;
  639. FKCX_bStop = 0;
  640. //完全停止
  641. if((X022 == 0) || (FKCX_bStopOver == 0) || (X04_DW))
  642. {
  643. cStepMByte = 0;
  644. cStepMByte1 = 0;
  645. cStepMByte2 = 0;
  646. cStepMByte3 = 0;
  647. cStepMByte4 = 0;
  648. cStepMByte5 = 0;
  649. cStepMByte6 = 0;
  650. FKCX_bStopOver = 2;
  651. FKCX_bStopXiao = 0;
  652. FKCX_bStopFang = 0;
  653. FKCX_bStopXiaCong = 0;
  654. AxisEgmStop(X_AXIS);
  655. Y00 = 0;
  656. Y01 = 0;
  657. Y05 = 0;
  658. Y10 = 0;
  659. Y11 = 0;
  660. Y12 = 0;
  661. Y13 = 0;
  662. Y14 = 0;
  663. Y15 = 0;
  664. Y16 = 0;
  665. if((X004 != 0) || FKCX_cYaDai)
  666. {
  667. SETY005();
  668. }
  669. else if(Y017)
  670. {
  671. if(FKCX_cXiaChongStep==0)FKCX_cXiaChongStep=1;
  672. SETY006(); //下冲电磁阀
  673. cDelayTime1 = dwTickCount + user_datas[2]*10;
  674. FKCX_cErrorTime = dwTickCount + FKCX_ERRORTIME;
  675. }
  676. }
  677. else //故障停止
  678. {
  679. cStepMByte = 0;
  680. cStepMByte1 = 0;
  681. cStepMByte2 = 0;
  682. cStepMByte3 = 0;
  683. cStepMByte4 = 0;
  684. cStepMByte5 = 0;
  685. cStepMByte6 = 0;
  686. FKCX_bStopOver = 2;
  687. FKCX_bStopXiao = 0;
  688. FKCX_bStopFang = 0;
  689. FKCX_bStopXiaCong = 0;
  690. AxisEgmStop(X_AXIS);
  691. Y00 = 0;
  692. Y01 = 0;
  693. Y05 = 0;
  694. Y10 = 0;
  695. Y11 = 0;
  696. Y12 = 0;
  697. Y13 = 0;
  698. Y14 = 0;
  699. Y15 = 0;
  700. Y16 = 0;
  701. SETY005();
  702. }
  703. }
  704. //下冲时判断是否出错
  705. // 压带磁感
  706. //按插销起动 急停 方块工作指示
  707. if((X00_UP || M0 || (M11 && (M10 == 0))) && (FKCX_cReady != 0) && (X001 == 0)
  708. && ((FKCX_bStopFang) == 0) && ((X015 != 0) || FKCX_bStopXiaCong) && (FKCX_bRunning == 0))
  709. {
  710. SetAlarmCode(FKCX_ALARM_ADDR,0);
  711. if(M11)FKCX_cHalfRun = 1;
  712. M0 = 0;
  713. M11 = 0;
  714. FKCX_bStopXiao = 0;
  715. FKCX_bStopOver = 0;
  716. FKCX_bRunning = 1;
  717. cStepMByte2 = 0;
  718. cStepMByte3 = 0;
  719. FKCX_cGeiLiaoNum = 0;
  720. if(FKCX_bStopXiaCong != 0)
  721. {
  722. cStepMByte = 4;
  723. if(X015 != 0)
  724. cStepMByte4 = 1; //给方块开始
  725. else
  726. cStepMByte4 = 10;
  727. if(user_datas[8] != 55)
  728. {
  729. if(FKCX_cXiaChongStep==0)FKCX_cXiaChongStep=1;
  730. SETY006(); //下冲
  731. SETY007(); //垫片
  732. cDelayTime1 = dwTickCount + user_datas[2]*10;
  733. FKCX_cErrorTime = dwTickCount + FKCX_ERRORTIME;
  734. M14 = 1;
  735. }
  736. FKCX_bStopXiao = 0;
  737. }
  738. else
  739. cStepMByte = 1; //从插销开始
  740. }
  741. //按方块起动指示
  742. if(((X02_UP) || M1 || (M11 && M10 && X022 && Y005)) && (FKCX_cReady != 0) && (X001 == 0)
  743. && (FKCX_bRunning == 0) && (FKCX_bStopXiao == 0) && ((FKCX_bStopFang) != 0))
  744. {
  745. SetAlarmCode(FKCX_ALARM_ADDR,0);
  746. if(M11)FKCX_cHalfRun = 1;
  747. M1 = 0;
  748. M11 = 0;
  749. FKCX_bStopOver = 0;
  750. FKCX_bRunning = 1;
  751. cStepMByte3 = 0;
  752. cStepMByte2 = 0;
  753. FKCX_cGeiLiaoNum = 0;
  754. FKCX_bStopFang = 1;
  755. //之前已经送好料 直接下冲
  756. if((FKCX_bStopXiaCong) != 0)
  757. {
  758. cStepMByte4 = 0;
  759. cStepMByte = 7;
  760. SETY006(); //下冲
  761. if(FKCX_cXiaChongStep==0)FKCX_cXiaChongStep=1;
  762. SETY004(); //方块垫片
  763. cDelayTime1 = dwTickCount + user_datas[2]*10;
  764. FKCX_cErrorTime = dwTickCount + FKCX_ERRORTIME;
  765. M14 = 1;
  766. }
  767. else
  768. {
  769. cStepMByte = 5; //从方块开始
  770. if((X015 != 0))
  771. cStepMByte4 = 1;
  772. else
  773. cStepMByte4 = 10; //已经有料
  774. }
  775. }
  776. else
  777. {
  778. M1 = 0;
  779. if(M10)M11 = 0;
  780. }
  781. //从插销步开始工作
  782. if((cStepMByte == 1))
  783. {
  784. //电机开始
  785. if((Y005) && (X022 != 0)) //先压带
  786. {
  787. cStepMByte2 = 10;
  788. }
  789. else
  790. cStepMByte2 = 1;
  791. //给销开始
  792. cStepMByte3 = 1;
  793. FKCX_cGeiLiaoNum = 0;
  794. //转下一步
  795. cStepMByte = 2;
  796. FKCX_bStopXiaCong = 0;
  797. if(X014 == 0)cStepMByte3 = 10;
  798. }
  799. //等待给料,电机拖带
  800. if((cStepMByte == 2))
  801. {
  802. i = FKCX_Motor(FKCX_TRUE);
  803. FKCX_bStopXiao = 1;
  804. //没料
  805. j = FKCX_JiaXiao(FKCX_TRUE);
  806. //拖带和给料已完成
  807. if((i == FKCX_TRUE) && (j == FKCX_TRUE))
  808. {
  809. cStepMByte = 3;
  810. cStepMByte5 = 1; //送梢启动
  811. }
  812. }
  813. //送插销
  814. if((cStepMByte == 3))
  815. {
  816. if((user_datas[12] == 0) || X013)
  817. i = FKCX_SongXiao(FKCX_TRUE);
  818. //送料完毕(销)
  819. if(i == FKCX_TRUE)
  820. {
  821. cStepMByte = 4;
  822. if((FKCX_cHalfRun == 0) && (Y007 == 0)) //半
  823. {
  824. if((X015 != 0) && (X027 == 0)) //打单边
  825. cStepMByte4 = 1;
  826. else
  827. cStepMByte4 = 10; //已经有料
  828. FKCX_cGeiLiaoNum = 0;
  829. }
  830. FKCX_cErrorTime = dwTickCount + FKCX_ERRORTIME;
  831. if(user_datas[8] != 55)
  832. {
  833. if(Y007)
  834. {
  835. if(dwTickCount >= cDelayTime1)
  836. {
  837. cStepMByte = 4;
  838. SETY006(); //下冲
  839. if(FKCX_cXiaChongStep==0)FKCX_cXiaChongStep=1;
  840. cDelayTime1= dwTickCount + user_datas[2]*10;
  841. }
  842. }
  843. else
  844. {
  845. cStepMByte = 3;
  846. SETY007(); //垫片
  847. cDelayTime1= dwTickCount + user_datas[13]*10;
  848. }
  849. M14 = 1;
  850. }
  851. }
  852. }
  853. //下冲动作
  854. if((cStepMByte == 4))
  855. {
  856. if(Y006 != 0)
  857. {
  858. if(X13_DW || ((user_datas[12] == 0) && (dwTickCount >= cDelayTime1)))
  859. {
  860. if(!FKCX_XC_ENABLE)CLRY006(); //下冲
  861. if(X027 == 0)
  862. FKCX_bStopFang = 1;
  863. FKCX_bStopXiao = 0;
  864. FKCX_bStopXiaCong = 0;
  865. cDelayTime1 = dwTickCount + 40;
  866. }
  867. }
  868. //下冲感应开关
  869. if((((X013 != 0)&&(FKCX_cXiaChongStep==0)) && ((user_datas[12] == 0) || ((dwTickCount >= cDelayTime1) && !Y006)))
  870. || (user_datas[8] == 55))
  871. {
  872. M14 = 0;
  873. if(!FKCX_XC_ENABLE)CLRY006(); //下冲
  874. CLRY007(); //插销垫片
  875. cDelayTime1 = dwTickCount + 60;
  876. if(X027 == 0)
  877. {
  878. FKCX_bStopFang = 1;
  879. cStepMByte = 5;
  880. }
  881. else
  882. cStepMByte = 8;
  883. FKCX_bStopXiao = 0;
  884. FKCX_bStopXiaCong = 0;
  885. if(FKCX_cHalfRun) //半
  886. {
  887. cStepMByte = 0;
  888. FKCX_bRunning = 0;
  889. FKCX_cHalfRun = 0;
  890. CLRY002();
  891. }
  892. }
  893. if(dwTickCount >= FKCX_cErrorTime)
  894. {
  895. SETY003();
  896. SetAlarmCode(FKCX_ALARM_ADDR,16);
  897. CLRY007(); //插销垫片
  898. if(!FKCX_XC_ENABLE)CLRY006();
  899. }
  900. //给方块开始
  901. j = FKCX_JiaFang(FKCX_TRUE);
  902. }
  903. if((cStepMByte == 5))
  904. {
  905. j = FKCX_JiaFang(FKCX_TRUE);
  906. if(j == FKCX_TRUE) //给方块已经完成
  907. {
  908. cStepMByte = 6;
  909. cStepMByte6 = 1; //送方块开始
  910. }
  911. }
  912. if((cStepMByte == 6))
  913. {
  914. j = FKCX_SongFang(FKCX_TRUE);
  915. //送料完毕(销)
  916. if(j == FKCX_TRUE)
  917. {
  918. cStepMByte4 = 0;
  919. if(Y004)
  920. {
  921. if(dwTickCount >= cDelayTime1)
  922. {
  923. cStepMByte = 7;
  924. SETY006(); //下冲
  925. if(FKCX_cXiaChongStep==0)FKCX_cXiaChongStep=1;
  926. cDelayTime1 = dwTickCount + user_datas[2]*10;
  927. FKCX_cErrorTime = dwTickCount + FKCX_ERRORTIME;
  928. }
  929. }
  930. else
  931. {
  932. SETY004(); //方块垫片
  933. cDelayTime1 = dwTickCount + user_datas[13]*10;
  934. }
  935. M14 = 1;
  936. }
  937. else if((user_datas[12] == 1) && !X013) //证明没法卡住
  938. {
  939. SETY003();
  940. SetAlarmCode(FKCX_ALARM_ADDR,16);
  941. CLRY007(); //插销垫片
  942. CLRY013();
  943. }
  944. }
  945. //下冲动作
  946. if((cStepMByte == 7))
  947. {
  948. if(Y006 != 0)
  949. {
  950. if(X13_DW || ((user_datas[12] == 0) && (dwTickCount >= cDelayTime1)))
  951. {
  952. if(!FKCX_XC_ENABLE)CLRY006(); //下冲
  953. cDelayTime1 = dwTickCount + 40;
  954. }
  955. }
  956. //下冲感应开关
  957. if((X013 != 0) && ((user_datas[12] == 0) || ((dwTickCount >= cDelayTime1) && !Y006)))
  958. {
  959. CLRY004(); //方块垫片
  960. cStepMByte = 8;
  961. FKCX_bStopFang = 0;
  962. FKCX_bStopXiaCong = 0;
  963. FKCX_bStopFang = 0;
  964. M14 = 0;
  965. }
  966. if(dwTickCount >= FKCX_cErrorTime)
  967. {
  968. SETY003();
  969. CLRY004(); //方块垫片
  970. SetAlarmCode(FKCX_ALARM_ADDR,16);
  971. if(!FKCX_XC_ENABLE)CLRY006();
  972. }
  973. }
  974. //一个周期完成 方块没插在拉链上带出来
  975. if(((cStepMByte == 8)))
  976. {
  977. cStepMByte3 = 0;
  978. cStepMByte4 = 0;
  979. cStepMByte5 = 0;
  980. cStepMByte6 = 0;
  981. //计数器
  982. if(FKCX_cHalfRun == 0) //半循环不用计数
  983. {
  984. cCountOutTime = 8;
  985. SETY001();
  986. }
  987. //在先手动压带情况下
  988. if(FKCX_cYaDai || FKCX_cHalfRun)
  989. {
  990. CLRY002();
  991. FKCX_bRunning = 0;
  992. FKCX_cHalfRun = 0;
  993. cStepMByte = 0;
  994. }
  995. //在其它启动情况下,启动下一周期
  996. else
  997. {
  998. SETY002();
  999. CLRY005(); //松压带
  1000. cStepMByte = 9;
  1001. }
  1002. }
  1003. if(((cStepMByte == 9)))
  1004. {
  1005. if(X022 == 0)
  1006. {
  1007. cStepMByte = 1; //开始
  1008. cStepMByte4 = 0;
  1009. cStepMByte3 = 0;
  1010. cStepMByte5 = 0;
  1011. cStepMByte6 = 0;
  1012. cStepMByte1 = 0;
  1013. cStepMByte2 = 0;
  1014. FKCX_cTotal++;
  1015. SetData32bits(76,FKCX_cTotal);
  1016. CalProSP(78); //计算生产速度
  1017. }
  1018. }
  1019. }
  1020. //电机控制
  1021. unsigned long FKCX_Motor(unsigned long En_Dis)
  1022. {
  1023. if(En_Dis == 0)
  1024. {
  1025. CLRY000();
  1026. AxisEgmStop(X_AXIS);
  1027. SETDR(); //电机放松
  1028. return FKCX_TRUE;
  1029. }
  1030. switch(cStepMByte2)
  1031. {
  1032. case 1: //离合器起动
  1033. cStepMByte2 = 2;
  1034. SETY000(); //离合器输出
  1035. if(user_datas[90] == 55)cDelayTime3 = dwTickCount + 300;
  1036. //步进启动
  1037. CLRDR();
  1038. MoveAction_Const_AccDec(X_AXIS, FKCX_DIR_P, user_datas[11],user_datas[10],user_datas[9],1);
  1039. break;
  1040. case 2: //过链接近下降沿
  1041. if((X12_DW) || ((user_datas[90] == 55) && (dwTickCount >= cDelayTime3)))
  1042. {
  1043. cStepMByte2 = 3;
  1044. cDelayTime3 = dwTickCount + 7;
  1045. cDelayTime4 = dwTickCount + user_datas[7]; // 延时上勾针
  1046. FKCX_cErrorTime = dwTickCount + FKCX_ERRORTIME;
  1047. MoveChangSpeed(X_AXIS,user_datas[10]);
  1048. }
  1049. break;
  1050. case 3: //要加延时上勾针
  1051. if(dwTickCount >= cDelayTime4)SETY016(); //上勾针
  1052. //过链接近上升沿 //拖带到
  1053. if(((X12_UP) || (user_datas[90] == 55)) && (dwTickCount >= cDelayTime3))
  1054. {
  1055. SETY016(); //上勾针
  1056. cStepMByte2 = 4;
  1057. cDelayTime3 = dwTickCount + 250;
  1058. }
  1059. if(dwTickCount >= FKCX_cErrorTime) //拖带警告
  1060. {
  1061. SETY003();
  1062. FKCX_SetAlarmCode(1);
  1063. }
  1064. break;
  1065. case 4:
  1066. if(X026)
  1067. {
  1068. cStepMByte2 = 5;
  1069. cDelayTime3 = dwTickCount + user_datas[6]*5;
  1070. }
  1071. else if(dwTickCount >= cDelayTime3)
  1072. {
  1073. FKCX_SetAlarmCode(9);
  1074. SETY003();
  1075. }
  1076. break;
  1077. case 5:
  1078. if(dwTickCount >= cDelayTime3)
  1079. {
  1080. cStepMByte2 = 6;
  1081. CLRY000(); //离合停
  1082. SETY005();
  1083. FKCX_cErrorTime = dwTickCount + FKCX_ERRORTIME;
  1084. AxisEgmStop(X_AXIS); //步进电机停
  1085. }
  1086. break;
  1087. case 6: //压带到
  1088. if(X022 != 0)
  1089. {
  1090. cStepMByte2 = 7; //拖带完成
  1091. cDelayTime3 = dwTickCount + 30;
  1092. }
  1093. else if(dwTickCount >= FKCX_cErrorTime) //压带警告
  1094. {
  1095. SETY003();
  1096. FKCX_SetAlarmCode(2);
  1097. }
  1098. break;
  1099. case 7:
  1100. if(dwTickCount >= cDelayTime3)
  1101. {
  1102. CLRY016(); //下勾针
  1103. cStepMByte2 = 10; //拖带完成
  1104. }
  1105. break;
  1106. case 10:
  1107. return FKCX_TRUE;
  1108. }
  1109. return FKCX_FALSE;
  1110. }
  1111. //夹销.给销动作
  1112. unsigned long FKCX_JiaXiao(unsigned long En_Dis)
  1113. {
  1114. //
  1115. if(En_Dis == 0)
  1116. return FKCX_TRUE;
  1117. switch(cStepMByte3) //离合器起动
  1118. {
  1119. case 0:
  1120. break;
  1121. case 1:
  1122. if(X017 != 0) //退送插销到位磁感
  1123. {
  1124. cStepMByte3 = 2;
  1125. SETY010(); //给插销打开
  1126. SETY011(); //夹插销打开
  1127. FKCX_cErrorTime1 = dwTickCount + user_datas[5]*10;
  1128. cDelayTime5 = dwTickCount + 1200;
  1129. }
  1130. else
  1131. CLRY010();
  1132. CLRY012();
  1133. break;
  1134. case 2: //给销到位
  1135. if(X023 != 0) //给销到位
  1136. {
  1137. if(X23_UP)
  1138. cDelayTime5 = dwTickCount + 25;
  1139. if(dwTickCount >= cDelayTime5)
  1140. {
  1141. CLRY011(); //夹插销夹
  1142. cStepMByte3 = 6;
  1143. cDelayTime5 = dwTickCount + 50;
  1144. }
  1145. }
  1146. else if(dwTickCount >= FKCX_cErrorTime1)
  1147. {
  1148. CLRY011(); //夹方块夹
  1149. cStepMByte3 = 0;
  1150. FKCX_cGeiLiaoNum++;
  1151. if(FKCX_cGeiLiaoNum >= user_datas[3]) //给料次数到卡料警告
  1152. {
  1153. FKCX_cGeiLiaoNum = 0;
  1154. SETY003();
  1155. FKCX_SetAlarmCode(3);
  1156. cStepMByte3 = 0;
  1157. }
  1158. else
  1159. {
  1160. cStepMByte3 = 4;
  1161. CLRY010(); //给插稍退回
  1162. }
  1163. }
  1164. break;
  1165. case 3: //给料到位成功
  1166. if(dwTickCount >= cDelayTime5)
  1167. {
  1168. cStepMByte3 = 0; //不用料自动运行
  1169. if((X014 != 0) && (user_datas[90] != 55) && (FKCX_bRunning != 0)) //没料
  1170. {
  1171. FKCX_cGeiLiaoNum++;
  1172. if(FKCX_cGeiLiaoNum >= user_datas[3]) //送三次没料
  1173. {
  1174. FKCX_cGeiLiaoNum = 0;
  1175. SETY003();
  1176. FKCX_SetAlarmCode(5);
  1177. }
  1178. else
  1179. {
  1180. cStepMByte3 = 4;
  1181. }
  1182. }
  1183. else
  1184. {
  1185. cStepMByte3 = 10;
  1186. FKCX_cGeiLiaoNum = 0;
  1187. CLRY010(); //给插销退回
  1188. }
  1189. }
  1190. break;
  1191. case 4: //给料不成功
  1192. if(X023 == 0)
  1193. {
  1194. cStepMByte3 = 5;
  1195. cDelayTime5 = dwTickCount + user_datas[4]*10;
  1196. }
  1197. break;
  1198. case 5:
  1199. if((dwTickCount >= cDelayTime5))
  1200. {
  1201. if(X014 != 0)
  1202. {
  1203. cStepMByte3 = 2;
  1204. SETY010(); //给插销打开
  1205. SETY011(); //夹插销打开
  1206. FKCX_cErrorTime1 = dwTickCount + user_datas[5]*10;
  1207. cDelayTime5 = dwTickCount + 1200;
  1208. }
  1209. else
  1210. {
  1211. FKCX_cGeiLiaoNum = 0;
  1212. SETY003();
  1213. FKCX_SetAlarmCode(3);
  1214. }
  1215. }
  1216. break;
  1217. case 6:
  1218. if(dwTickCount >= cDelayTime5)
  1219. {
  1220. CLRY010(); //给插销退回
  1221. CLRY011(); //夹插销夹
  1222. cStepMByte3 = 3;
  1223. cDelayTime5 = dwTickCount + user_datas[0]*10 + 30;
  1224. }
  1225. break;
  1226. case 10:
  1227. return FKCX_TRUE;
  1228. }
  1229. return FKCX_FALSE;
  1230. }
  1231. //送销动作
  1232. unsigned long FKCX_SongXiao(unsigned long En_Dis)
  1233. {
  1234. //
  1235. if(En_Dis == 0)
  1236. return FKCX_TRUE;
  1237. switch(cStepMByte5)
  1238. {
  1239. case 0:
  1240. break;
  1241. case 1:
  1242. cStepMByte5 = 2;
  1243. FKCX_cErrorTime1 = dwTickCount + 10*FKCX_ERRORTIME;
  1244. if((X014 == 0) || (user_datas[90] == 55) || (FKCX_bRunning == 0)) //方块
  1245. SETY012(); //送销打开
  1246. else
  1247. break;
  1248. case 2: //送销到位
  1249. if((X016 != 0) && (X017 == 0))
  1250. {
  1251. cStepMByte5 = 3;
  1252. cDelayTime5 = dwTickCount + 20;
  1253. }
  1254. else if((dwTickCount >= FKCX_cErrorTime1) && (FKCX_cHalfRun == 0)) //送销不到位故障
  1255. {
  1256. cStepMByte5 = 0;
  1257. SETY003();
  1258. FKCX_SetAlarmCode(7);
  1259. }
  1260. break;
  1261. case 3:
  1262. if(dwTickCount >= cDelayTime5)
  1263. {
  1264. cStepMByte5 = 4;
  1265. SETY011(); //夹插销打开
  1266. cDelayTime5 = dwTickCount + user_datas[1]*10;
  1267. }
  1268. break;
  1269. case 4:
  1270. if(dwTickCount >= cDelayTime5)
  1271. {
  1272. cStepMByte5 = 5;
  1273. CLRY012(); //退送插销
  1274. if(FKCX_bRunning != 0)FKCX_bStopXiaCong = 1;
  1275. FKCX_cErrorTime1 = dwTickCount + FKCX_ERRORTIME;
  1276. }
  1277. break;
  1278. case 5:
  1279. if((X017 != 0) && (X016 == 0))
  1280. {
  1281. cStepMByte5 = 6;
  1282. CLRY011(); //夹插销关
  1283. cDelayTime5 = dwTickCount + 500;
  1284. }
  1285. else if(dwTickCount >= FKCX_cErrorTime1) //退送出错警告
  1286. {
  1287. SETY003();
  1288. FKCX_SetAlarmCode(7);
  1289. }
  1290. break;
  1291. case 6:
  1292. if(X014 != 0)
  1293. {
  1294. cStepMByte5 = 7;
  1295. if(FKCX_bRunning != 0)FKCX_bStopXiaCong = 1;
  1296. }
  1297. else if(dwTickCount >= cDelayTime5) //带料出来警告
  1298. {
  1299. cStepMByte5 = 0;
  1300. FKCX_cTestNum = 35;
  1301. FKCX_bStopXiaCong = 0;
  1302. SETY003();
  1303. FKCX_SetAlarmCode(11);
  1304. }
  1305. break;
  1306. case 7:
  1307. return FKCX_TRUE;
  1308. }
  1309. return FKCX_FALSE;
  1310. }
  1311. //夹方块.给方块动作
  1312. unsigned long FKCX_JiaFang(unsigned long En_Dis)
  1313. {
  1314. //
  1315. if(En_Dis == 0)
  1316. return FKCX_TRUE;
  1317. switch(cStepMByte4)
  1318. {
  1319. case 0:
  1320. break;
  1321. case 1:
  1322. if(X021 != 0)
  1323. {
  1324. cStepMByte4 = 2;
  1325. SETY015(); //给方块打开
  1326. SETY014(); //夹方块打开
  1327. FKCX_cErrorTime2 = dwTickCount + user_datas[5]*10;
  1328. cDelayTime6 = dwTickCount + 1200;
  1329. }
  1330. else
  1331. CLRY015();
  1332. CLRY013();
  1333. break;
  1334. case 2: //给方块到位
  1335. if(X024 != 0)
  1336. {
  1337. if(X24_UP)
  1338. {
  1339. cDelayTime6 = dwTickCount + 20;
  1340. }
  1341. if(dwTickCount >= cDelayTime6)
  1342. {
  1343. CLRY014(); //夹方块夹
  1344. cStepMByte4 = 6;
  1345. cDelayTime6 = dwTickCount + 50;
  1346. }
  1347. }
  1348. else if(dwTickCount >= FKCX_cErrorTime2)
  1349. {
  1350. CLRY014(); //夹方块夹
  1351. cStepMByte4 = 0;
  1352. FKCX_cGeiLiaoNum++;
  1353. if(FKCX_cGeiLiaoNum >= user_datas[3]) //给料三次错误
  1354. {
  1355. FKCX_cGeiLiaoNum = 0;
  1356. SETY003();
  1357. FKCX_SetAlarmCode(4);
  1358. }
  1359. else
  1360. {
  1361. cStepMByte4 = 4;
  1362. CLRY015(); //给方块退回
  1363. }
  1364. }
  1365. break;
  1366. case 3: //已给料到前面
  1367. if(dwTickCount >= cDelayTime6)
  1368. { //没带空打
  1369. if((X015 != 0) && (user_datas[90] != 55) && (FKCX_bRunning != 0)) //没料
  1370. {
  1371. cStepMByte4 = 0;
  1372. FKCX_cGeiLiaoNum++;
  1373. if(FKCX_cGeiLiaoNum >= user_datas[3]) //没料三次警告
  1374. {
  1375. FKCX_cGeiLiaoNum = 0;
  1376. SETY003();
  1377. FKCX_SetAlarmCode(6);
  1378. }
  1379. else
  1380. {
  1381. cStepMByte4 = 4;
  1382. }
  1383. }
  1384. else
  1385. {
  1386. cStepMByte4 = 10; //完成
  1387. FKCX_cGeiLiaoNum = 0;
  1388. CLRY015(); //给方块退回
  1389. }
  1390. }
  1391. break;
  1392. case 4://出错退回
  1393. if(X024 == 0)
  1394. {
  1395. cStepMByte4 = 5;
  1396. cDelayTime6 = dwTickCount + user_datas[4]*10;
  1397. }
  1398. break;
  1399. case 5:
  1400. if((dwTickCount >= cDelayTime6))
  1401. {
  1402. if(X015 != 0)
  1403. {
  1404. cStepMByte4 = 2;
  1405. SETY014(); //给插销打开
  1406. SETY015(); //夹插销打开
  1407. FKCX_cErrorTime2 = dwTickCount + user_datas[5]*10;
  1408. cDelayTime6 = dwTickCount + 1200;
  1409. }
  1410. else
  1411. {
  1412. FKCX_cGeiLiaoNum = 0;
  1413. SETY003();
  1414. FKCX_SetAlarmCode(4);
  1415. }
  1416. }
  1417. break;
  1418. case 6:
  1419. if(dwTickCount >= cDelayTime6)
  1420. {
  1421. CLRY015(); //给方块退回
  1422. cStepMByte4 = 3;
  1423. cDelayTime6 = dwTickCount + user_datas[0]*10 + 30;
  1424. }
  1425. break;
  1426. case 10:
  1427. return FKCX_TRUE;
  1428. }
  1429. return FKCX_FALSE;
  1430. }
  1431. //送方块动作
  1432. unsigned long FKCX_SongFang(unsigned long En_Dis)
  1433. {
  1434. //
  1435. if(En_Dis == 0)return FKCX_TRUE;
  1436. switch(cStepMByte6)
  1437. {
  1438. case 0:
  1439. break;
  1440. case 1:
  1441. if((X015 == 0) || (user_datas[90] == 55) || (FKCX_bRunning == 0))
  1442. {
  1443. cStepMByte6 = 2;
  1444. SETY013(); //送方块打开
  1445. FKCX_cErrorTime2 = dwTickCount + 10*FKCX_ERRORTIME;
  1446. }
  1447. break;
  1448. case 2: //送销到位
  1449. if((X020 != 0) && (X021 == 0))
  1450. {
  1451. cStepMByte6 = 3;
  1452. cDelayTime6 = dwTickCount + 20;
  1453. }
  1454. else if((dwTickCount >= FKCX_cErrorTime2) && (FKCX_cHalfRun == 0)) //送销不到位故障
  1455. {
  1456. cStepMByte6 = 0;
  1457. FKCX_SetAlarmCode(6);
  1458. SETY003();
  1459. }
  1460. break;
  1461. case 3:
  1462. if(dwTickCount >= cDelayTime6)
  1463. {
  1464. cStepMByte6 = 4;
  1465. SETY014(); //夹方块打开
  1466. cDelayTime6 = dwTickCount + user_datas[1]*10;
  1467. }
  1468. break;
  1469. case 4:
  1470. if(dwTickCount >= cDelayTime6)
  1471. {
  1472. cStepMByte6 = 5;
  1473. CLRY013(); //退送方块
  1474. if(FKCX_bRunning != 0)FKCX_bStopXiaCong = 1;
  1475. FKCX_cErrorTime2 = dwTickCount + FKCX_ERRORTIME;
  1476. }
  1477. break;
  1478. case 5:
  1479. if((X021 != 0) && (X020 == 0))
  1480. {
  1481. cStepMByte6 = 6;
  1482. CLRY014(); //夹方块关
  1483. cDelayTime6 = dwTickCount + 500;
  1484. }
  1485. else if(dwTickCount >= FKCX_cErrorTime2) //退送方块出错警告
  1486. {
  1487. SETY003();
  1488. FKCX_SetAlarmCode(8);
  1489. }
  1490. break;
  1491. case 6:
  1492. if(X015 != 0)
  1493. {
  1494. cStepMByte6 = 7;
  1495. if(FKCX_bRunning != 0)
  1496. FKCX_bStopXiaCong = 1;
  1497. }
  1498. else if(dwTickCount >= cDelayTime6) //带料出来警告
  1499. {
  1500. cStepMByte6 = 0;
  1501. FKCX_bStopXiaCong = 0;
  1502. SETY003();
  1503. FKCX_SetAlarmCode(11);
  1504. }
  1505. break;
  1506. case 7:
  1507. return FKCX_TRUE;
  1508. }
  1509. return FKCX_FALSE;
  1510. }
  1511. #endif