void niuli() { if (Card.mathineTyple == MathineTyple.fendu) { int st1 = PCI408.PCI408_read_inbit(Card.cardNo, Card.servoAlarm); if (st1 == Card.Off) { if (StrongPressEventHandler != null) { zhuanpanStateRuning = false; zhuanPanIsRun = false; StrongPressEventHandler(); } } int state = PCI408.PCI408_read_inbit(Card.cardNo, Card.zhizhenSensor); if (state != Card.Off && zhuanPanIsRun && zhuanpanStateRuning) { lackStop(); zhuanpanStateRuning = false; } else if (state == Card.Off && zhuanPanIsRun && !zhizhenLowSensor.timer.IsRunning && !zhuanpanStateRuning) { lackStart(); } } }
void zhizhenLowSensor_OnTimerEvent(object sender, EventArgs e) { int state = PCI408.PCI408_read_inbit(Card.cardNo, Card.zhizhenSensor); if (state != Card.On) { SpeedTime.Start(); PCI408.PCI408_write_SEVON_PIN(Card.cardNo, Card.On); PCI408.PCI408_set_profile(Card.cardNo, Card.minspeed, Card.maxspeed, Card.acc, Card.acc); PCI408.PCI408_vmove(Card.cardNo, 0, Card.maxspeed); PCI408.PCI408_write_outbit(Card.cardNo, Card.chuiqizongkaiguan, Card.On); zhuanpanStateRuning = true; zhizhenLowSensor.timer.Stop(); } }
private void kongzhiwaibu() { kzwbmlt11 = DateTime.Now; kzwbmlts = kzwbmlt11 - kzwbmlt12; int kzwbml; kzwbml = kzwbmlts.Days * 86400 + kzwbmlts.Hours * 3600 + kzwbmlts.Minutes * 60 + kzwbmlts.Seconds; if (kzwbml > 240) { Onwuliao(); baojing = new Thread(bjzx); baojing.Start(); isStart = false; } djzt = PCI408.PCI408_check_done(Card.cardNo); if (djzt == 1) { if (kzwbhdzt == 1) { PCI408.PCI408_write_outbit(Card.cardNo, Card.hd, Card.On); PCI408.PCI408_write_outbit(Card.cardNo, Card.shakePan, Card.Off); kzwbhdzt = 0; } if (kzwbldzt == 1) { PCI408.PCI408_write_outbit(Card.cardNo, Card.ld, Card.Off); kzwbldzt = 1; } } else { if (kzwbldzt == 1) { PCI408.PCI408_write_outbit(Card.cardNo, Card.ld, Card.On); kzwbldzt = 0; } if (kzwbhdzt == 0) { PCI408.PCI408_write_outbit(Card.cardNo, Card.hd, Card.Off); kzwbhdzt = 1; } } if (sc == 1) { s4 = PCI408.PCI408_read_inbit(Card.cardNo, Card.jsqm); if (s4 == 0) { PCI408.PCI408_write_outbit(Card.cardNo, Card.jsqqg, Card.Off); sc = 0; } } if (sc == 0) { s5 = PCI408.PCI408_read_inbit(Card.cardNo, Card.jsqfw); if (s5 == 0) { PCI408.PCI408_write_outbit(Card.cardNo, Card.jsqqg, Card.On); sc = 1; lmxh2 = DateTime.Now; } } lmxhts = lmxh1 - lmxh2;//20170622 lmxh1 = DateTime.Now; int lmxh; lmxh = lmxhts.Days * 86400 + lmxhts.Hours * 3600 + lmxhts.Minutes * 60 + lmxhts.Seconds; if (lmxh > 60 && sc == 1) { //baojing = new Thread(bjzx); //baojing.Start(); //isStart = false; //lackStop(); ////zhuanpanStateRuning = false; //SpeedTime.Stop(); //Turntable.Instance.Stop(); //zhuanpanStateRuning = false; ////zhizhenLowSensor.timer.Start(); //SpeedTime.Enabled = false; PCI408.PCI408_decel_stop(Card.cardNo, Card.acc); PCI408.PCI408_write_outbit(Card.cardNo, Card.chuiqizongkaiguan, Card.Off); //zhuanPanIsRun = false; //zhizhenLowSensor.timer.Stop(); } }
void Run() { //将当前线程绑定到指定的cpu核心上 GetCpu.SetThreadAffinityMask(GetCpu.GetCurrentThread(), new UIntPtr(0x4)); kzwbmlt12 = DateTime.Now; string path = PathHelper.currentProductPath + @"\" + "spd" + ".txt"; DateTime t1; int xjfwi; spd = Card.maxspeed; int preSignal = 0, signal = 0; PCI408.PCI408_counter_config(0, 3); PCI408.PCI408_set_encoder(0, 0); int fwjs1 = 0, fwjs2 = 0; sdkz3 = 100000; long cuowu = PCI408.PCI408_compare_set_filter_Extern(Card.cardNo, 100000); PCI408.PCI408_config_latch_mode(Card.cardNo, Card.zhouhao); sdkzt1 = DateTime.Now; sdkzt2 = DateTime.Now; sdkzt4 = DateTime.Now; sdkzt3 = DateTime.Now; long jcqbz; for (int xjh = 0; xjh < PosArray.Count(); xjh++) { PCI408.PCI408_compare_clear_points_Extern(0, (ushort)(xjh + 1)); PCI408.PCI408_compare_config_Extern(Card.cardNo, (ushort)(xjh + 1), 1, Card.zhouhao, IOs[xjh]); PCI408.PCI408_compare_set_pulsetimes_Extern(0, (ushort)(xjh + 1), 20); } PCI408.PCI408_reset_latch_flag(Card.cardNo); long s5; currentPos = (int)PCI408.PCI408_get_encoder(Card.cardNo); int[] sigci = new int[5], psigci = new int[5]; for (int sigfi = 0; sigfi < 5; sigfi++) { sigci[sigfi] = 0; psigci[sigfi] = 0; } //? int zdwy = 40000; while (isStart) { try { // for (xjfwi = 1; xjfwi < cameraCount + 1; xjfwi++) //{ // xjfws[xjfwi].t2 = DateTime.Now; // //if (xjfws[xjfwi].tsc() > 200000 && copos[xjfwi].pos.Count() > 0) // //if (xjfws[xjfwi].tsc() > 200000) // // { // // //copos[0].pos.Clear(); // // //copos[1].pos.Clear(); // // //copos[2].pos.Clear(); // // //copos[3].pos.Clear(); // // //copos[4].pos.Clear(); // // //copos[5].pos.Clear(); // // //copos[6].pos.Clear(); // // nutqueue.Clear(); // // xjfws.Initialize(); // // copos.Initialize(); // // timers.Initialize(); // // xjfws = new xjfw[7]; // // //for (xjfwi = 0; xjfwi < 5; xjfwi++) // // //{ // // // xjfws[xjfwi] = new xjfw(); // // // xjfws[xjfwi].ID = xjfwi; // // // xjfws[xjfwi].t1 = DateTime.Now; // // // xjfws[xjfwi].t2 = DateTime.Now; // // //} // // copos = new coppos[7]; // // //for (int k = 0; k < 5; k++) // // //{ // // // copos[k] = new coppos(); // // // copos[k].ID = k; // // // //copos[k].onwrite = false; // // //} // // timers = new MyTimer[7]; // // //for (int i = 0; i < timers.Length; i++) // // //{ // // // timers[i] = new MyTimer(); // // // timers[i].ID = i; // // // //timers[i].OnTimerEvent += new MyTimer.OnTimerEventHandler(OnTimer); // // //} // // //Thread.Sleep(1000); // // } //} // t1 = DateTime.Now; currentPos = (int)PCI408.PCI408_get_encoder(Card.zhouhao); for (int sr = 0; sr < cameraCount; sr++) { sigci[sr] = PCI408.PCI408_read_inbit(Card.cardNo, (ushort)xjzsr[sr]); if (sigci[sr] == 0 && psigci[sr] == 1) { int length1 = dpdl[sr].Count(), jr = 200, jr1 = 5000; for (int listi = 0; listi < length1; listi++) { int ssg = Math.Abs(dpdl[sr][listi] + PosArray[sr] - currentPos); if (ssg < jr1) { jr1 = ssg; jr = listi; } } if (jr != 200 && jr1 < 5000) { copos[sr].pos.Add(dpdl[sr][jr]); // Console.WriteLine("trun " + DateTime.Now.ToString("mm-ss-fff")); dpdl[sr].RemoveAt(jr); } } psigci[sr] = sigci[sr]; } for (int sr1 = 0; sr1 < cameraCount; sr1++) { int length2 = dpdl[sr1].Count(); for (int listi1 = 0; listi1 < length2; listi1++) { if (Math.Abs(currentPos - dpdl[sr1][listi1]) > zdwy) { dpdl[sr1].RemoveAt(listi1); } } } jcqbz = PCI408.PCI408_get_latch_flag(Card.cardNo); //读取锁存器状态 if ((jcqbz & 0xf00) > 0) { PCI408.PCI408_reset_latch_flag(Card.cardNo); signal = PCI408.PCI408_get_latch_value(Card.zhouhao); } if (fwjs1 - fwjs2 > 4000) { fwjs1 = fwjs2; for (int sr = 0; sr < cameraCount; sr++) { sigci[sr] = 0; psigci[sr] = 0; dpdl[sr].Clear(); copos[sr].pos.Clear(); } for (int xjh = 0; xjh < PosArray.Count(); xjh++) { PCI408.PCI408_set_encoder(0, 0); PCI408.PCI408_compare_clear_points_Extern(0, (ushort)(xjh + 1)); PCI408.PCI408_compare_config_Extern(Card.cardNo, (ushort)(xjh + 1), 1, Card.zhouhao, IOs[xjh]); PCI408.PCI408_compare_set_pulsetimes_Extern(0, (ushort)(xjh + 1), 5); } for (int xjs = 0; xjs < cameraCount; xjs++) { jcqdls[xjs].clear(); //File.AppendAllText(path,signal.ToString()+" ", Encoding.Default); } PCI408.PCI408_reset_latch_flag(Card.cardNo); preSignal = signal; if (isStart) { nutqueue.Clear(); } } if (signal != preSignal) { kzwbmlt12 = DateTime.Now; s5 = PCI408.PCI408_compare_get_points_remained_Extern(0, 1); if (s5 > cameraCount + 3) { Nut nut = new Nut(); fwjs1 += 1; nut.initialPos = signal; nutqueue.Add(nut); nut.cas = cameraCount; pn.totalCount++; speedTemp++; ss = pn.totalCount; for (int xjs = 0; xjs < cameraCount; xjs++) { PCI408.PCI408_compare_config_Extern(Card.cardNo, (ushort)(xjs + 1), 1, Card.zhouhao, 1); PCI408.PCI408_compare_add_point_Extern(Card.cardNo, (ushort)(xjs + 1), PosArray[xjs] + (int)signal, 1, 9, IOs[xjs]); // copos[nut.posNo + 1].pos.Add (nut.initialPos); // copos[nut.posNo + 1].onwrite = true; dpdl[xjs].Add(signal); // Console.WriteLine("ss" + signal); //File.AppendAllText(path,signal.ToString()+" ", Encoding.Default); } } } niuli(); for (int i = nutqueue.Count - 1; i > -1; i--) { Nut nutc = new Nut(); nutc = nutqueue[i]; //if (currentPos < nutc.initialPos) //{ // nutqueue.Remove(nutc); // break; //} if (currentPos - nutc.initialPos > PosArray[cameraCount] - 1000) { int a = nutc.getTheHole(); switch (a.ToString()) { case "1": //pn.mnum++; //Console.WriteLine("cipin" + pn.mnum); PCI408.PCI408_compare_config_Extern(Card.cardNo, (ushort)(cameraCount + 1), 1, Card.zhouhao, 1); PCI408.PCI408_compare_set_pulsetimes_Extern(0, (ushort)(cameraCount + 1), 10); PCI408.PCI408_compare_add_point_Extern(Card.cardNo, (ushort)(cameraCount + 1), PosArray[cameraCount] + (int)nutc.initialPos, 1, 9, IOs[cameraCount]); break; //case "3": //pn.nnum++; //Console.WriteLine("未识别" + pn.nnum); //PCI408.PCI408_compare_config_Extern(Card.cardNo, (ushort)(cameraCount + 1), 1, Card.zhouhao, 1); //PCI408.PCI408_compare_set_pulsetimes_Extern(0, (ushort)(cameraCount + 1), 20); //PCI408.PCI408_compare_add_point_Extern(Card.cardNo, (ushort)(cameraCount + 1), PosArray[cameraCount] + (int)nutc.initialPos, 1, 9, IOs[cameraCount]); //break; case "2": pn.goodNum++; fwjs2 = fwjs1; PCI408.PCI408_compare_config_Extern(Card.cardNo, (ushort)(cameraCount + 2), 1, Card.zhouhao, 1); PCI408.PCI408_compare_set_pulsetimes_Extern(0, (ushort)(cameraCount + 2), 10); PCI408.PCI408_compare_add_point_Extern(Card.cardNo, (ushort)(cameraCount + 2), PosArray[cameraCount + 1] + (int)nutc.initialPos, 1, 9, IOs[cameraCount + 1]); break; } jcjg2 = nutc.jiance; Thread ccjcjg = new Thread(cunchujiancejieguo); ccjcjg.Start(); nutqueue.Remove(nutc); pn.badNum = pn.totalCount - pn.goodNum; } } preSignal = signal; kongzhiwaibu(); sdkzt1 = DateTime.Now; sdkzt4 = DateTime.Now; if (Card.sjc(sdkzt3, sdkzt4) < sdkz3) { sdkz3 = Card.sjc(sdkzt3, sdkzt4); } sdkzt3 = DateTime.Now; //if (Card.sjc(sdkzt2, sdkzt1) > 60000) //{ // sdkzt2 = DateTime.Now; // if (sdkz3 < 10) // { // spd = spd + 100; // PCI408.PCI408_change_speed(Card.cardNo, spd); // File.AppendAllText(path, spd.ToString() + " ", Encoding.Default); // } //} } catch (Exception e) { MyDebug.ShowMessage(e, "运动控制出错"); } finally { //MyDebug.ShowMessage(nutqueue.Count.ToString()); } } }