private void btnRun_Click(object sender, RoutedEventArgs e) { var idText = tbId.Text; if (string.IsNullOrWhiteSpace(idText)) { MessageBox.Show("灯箱id为空"); } var runTimeText = tbRunTime.Text; if (string.IsNullOrWhiteSpace(runTimeText)) { MessageBox.Show("运行时间为空"); } var keepTimeText = tbKeepTime.Text; if (string.IsNullOrWhiteSpace(keepTimeText)) { MessageBox.Show("停留时间为空"); } try { var runTime = Convert.ToInt32(runTimeText); var keepTime = Convert.ToInt32(keepTimeText); LBMsg box = new LBMsg(); box.Id = Convert.ToInt32(idText); box.RunTime = runTime; box.KeepTime = keepTime; MessageHelper.ins.startRunBox(box); //DataComm.ins.startRunBox(box); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public WidLightBoxEdit(LBMsg lBMsg) { InitializeComponent(); this.lBMsg = lBMsg; tbWaitTime.Text = Convert.ToString(lBMsg.WaitTime); tbRunTime.Text = Convert.ToString(lBMsg.RunTime); tbKeepTime.Text = Convert.ToString(lBMsg.KeepTime); tbRepeatCount.Text = Convert.ToString(lBMsg.RepeatCount); }
//发送字节数据 public void runBox(object obj) { LBMsg lBMsg = obj as LBMsg; int canId = createCanId(lBMsg.Id); byte[] by = new byte[8]; //正转时间 int runTime = (int)(lBMsg.RunTime); //保持时间 int keepTime = (int)lBMsg.KeepTime; //Console.WriteLine("id:" + lBMsg.Id +"-" + runTime + ":" + keepTime); //灯箱属于 canid-电机id对应表中的那一列, 共4列 int boxColumnInCanIdTable = createBoxByteIndex(lBMsg.Id); //正转 //运转命令 00保留, 01正转, 10反转, 11停留 CanDataWithInfo can = createRunBySend(boxColumnInCanIdTable, canId, 1, runTime); can.info = "id:" + lBMsg.Id + " 正 time:" + runTime; ECANHelper.ins.sendMessageWithInfo(can); //Console.WriteLine("send " + Untils.ToHexString(can.bytes)); //sendMessageWithInfo(bySend, "id:" + lBMsg.Id + " 正"); //Console.WriteLine("id:" + lBMsg.Id + "-正"); // if (runTime > 1) { // Thread.Sleep((runTime - 1) * 1000); // } // //停留 // CanDataWithInfo can1 = createRunBySend(boxColumnInCanIdTable, canId, 3, keepTime); // can1.info = "id:" + lBMsg.Id + " 停"; // ECANHelper.ins.sendMessageWithInfo(can1); //// Console.WriteLine("send " + Untils.ToHexString(can1.bytes)); // //sendMessageWithInfo(bySend1, "id:" + lBMsg.Id + " 停"); // //Console.WriteLine("id:" + lBMsg.Id + "-停"); // if (keepTime > 1) { // Thread.Sleep((keepTime - 1) * 1000); // } Thread.Sleep((runTime + keepTime) * 1000); //反转, 反转时间+2 , 保证转到底 CanDataWithInfo can2 = createRunBySend(boxColumnInCanIdTable, canId, 2, runTime + 2); can2.info = "id:" + lBMsg.Id + " 反 "; ECANHelper.ins.sendMessageWithInfo(can2); //Thread.Sleep(runTime * 1000); //boxEndCount = boxEndCount + 1; //Console.WriteLine("boxEndCount " + boxEndCount); //sendMessageWithInfo(bySend2, "id:" + lBMsg.Id + " 反"); //Console.WriteLine("id:" + lBMsg.Id + "-反"); }
public static void updateModelLBMsg(LBMsg lBMsg) { foreach (LBModel model in listModel) { if (model.ModelName.Equals(SelectedModel.ModelName)) { LBMsg msg = model.getLightBoxMsg(lBMsg.Id); msg.RunTime = lBMsg.RunTime; msg.KeepTime = lBMsg.KeepTime; msg.WaitTime = lBMsg.WaitTime; break; } } }
private void Ins_eventBoxStateChanged(object sender, BoxStateEventArgs e) { if (e.stateCode != 0) { LBMsg msg = LightBoxHelper.SelectedModel.getLightBoxMsg(e.boxId); string info = "id=" + e.boxId; if (null != msg) { info += ",\n" + msg.Row1 + "行" + msg.Column + "列,\n" + e.getStateInfo(); } logger.Error(info); SmsComm.ins.sendMessage(info); } }
public static LBModel createInitModel() { LBModel model = new LBModel(); for (int i = 1; i <= BaseConfig.ins.Rows; i++) { for (int j = 1; j <= BaseConfig.ins.Columns; j++) { LBMsg lBMsg = new LBMsg(); lBMsg.Id = getLightBoxId(i, j); lBMsg.Row1 = i; lBMsg.Column = j; model.ListLBMsg.Add(lBMsg); } } return(model); }
public LightBox(LBMsg lBMsg) { InitializeComponent(); this.lBMsg = lBMsg; //cbAddr.Content = lBMsg.Row1 + "-" + lBMsg.Column; labelAddr.Content = lBMsg.Row1 + "-" + lBMsg.Column; labelId.Content = lBMsg.Id; labelWaitTime.Content = lBMsg.WaitTime; labelWaitTime.Background = new SolidColorBrush(Color.FromArgb(150, 10, 10, 10)); labelAddr.Background = new SolidColorBrush(Color.FromArgb(150, 10, 10, 10)); labelId.Background = new SolidColorBrush(Color.FromArgb(150, 10, 10, 10)); //Point p = new Point(this.Width * lBMsg.Column + lBMsg.Column * 1 + 1, // this.Height * lBMsg.Row1 + lBMsg.Row1 * 1 + 1); //Canvas.SetLeft(this, this.Width * lBMsg.Column + lBMsg.Column * 1 + 2); //Canvas.SetTop(this, this.Height * lBMsg.Row1 + lBMsg.Row1 * 1 + 200); }
private static void changeModel(LBModel nextModel) { SelectedModel.ModelName = nextModel.ModelName; SelectedModel.MWaitTime = nextModel.MWaitTime; SelectedModel.runAll = nextModel.runAll; foreach (LBMsg lb in nextModel.ListLBMsg) { LBMsg lBMsg = SelectedModel.getLightBoxMsg(lb.Row1, lb.Column); if (null != lBMsg) { lBMsg.Id = lb.Id; lBMsg.WaitTime = lb.WaitTime; lBMsg.RunTime = lb.RunTime; lBMsg.KeepTime = lb.KeepTime; lBMsg.RepeatCount = lb.RepeatCount; } } nextModel.getListWaitTime(); modelChanged?.Invoke(nextModel, null); }
public void runBoxRepeat(object obj) { LBMsg lBMsg = obj as LBMsg; Console.WriteLine(">>>>一个灯箱运行开始, id= " + lBMsg.Id); if (lBMsg.RunTime > 0) { int canId = createCanId(lBMsg.Id); Thread.Sleep((int)lBMsg.WaitTime * 1000); for (int i = 0; i < lBMsg.RepeatCount; i++) { byte[] by = new byte[8]; //正转时间 int runTime = (int)(lBMsg.RunTime); //保持时间 int keepTime = (int)lBMsg.KeepTime; //灯箱属于 canid-电机id对应表中的那一列, 共4列 int boxColumnInCanIdTable = createBoxByteIndex(lBMsg.Id); //正转 //运转命令 00保留, 01正转, 10反转, 11停留 CanDataWithInfo can = createRunBySend(boxColumnInCanIdTable, canId, 1, runTime); can.info = "id:" + lBMsg.Id + " 正 time:" + runTime; ECANHelper.ins.sendMessageWithInfo(can); Thread.Sleep((runTime + keepTime) * 1000); //反转, 反转时间+2 , 保证转到底 CanDataWithInfo can2 = createRunBySend(boxColumnInCanIdTable, canId, 2, runTime + 1); can2.info = "id:" + lBMsg.Id + " 反 "; ECANHelper.ins.sendMessageWithInfo(can2); Thread.Sleep((runTime + 1) * 1000); Console.WriteLine(">>>>id= " + lBMsg.Id + " 的灯箱运行完 " + (i + 1) + " 次"); } } boxEndCount = boxEndCount + 1; Console.WriteLine("====一个灯箱运行结束, id= " + lBMsg.Id + ", boxEndCount = " + boxEndCount); }
//发送字节数据 public void runBox(object obj) { LBMsg lBMsg = obj as LBMsg; int canId = createCanId(lBMsg.Id); byte[] by = new byte[8]; //正转时间 int runTime = (int)(lBMsg.RunTime); //保持时间 int keepTime = (int)lBMsg.KeepTime; //Console.WriteLine("id:" + lBMsg.Id +"-" + runTime + ":" + keepTime); //灯箱属于 canid-电机id对应表中的那一列, 共4列 int boxColumnInCanIdTable = createBoxByteIndex(lBMsg.Id); //正转 //运转命令 00保留, 01正转, 10反转, 11停留 byte[] bySend = createRunBySend(boxColumnInCanIdTable, canId, 1, runTime); sendMessageWithInfo(bySend, "id:" + lBMsg.Id + " 正"); //Console.WriteLine("id:" + lBMsg.Id + "-正"); if (runTime > 1) { Thread.Sleep((runTime - 1) * 1000); } //停留 byte[] bySend1 = createRunBySend(boxColumnInCanIdTable, canId, 3, keepTime); sendMessageWithInfo(bySend1, "id:" + lBMsg.Id + " 停"); //Console.WriteLine("id:" + lBMsg.Id + "-停"); if (keepTime > 1) { Thread.Sleep((keepTime - 1) * 1000); } //反转 byte[] bySend2 = createRunBySend(boxColumnInCanIdTable, canId, 2, runTime); sendMessageWithInfo(bySend2, "id:" + lBMsg.Id + " 反"); //Console.WriteLine("id:" + lBMsg.Id + "-反"); }
private void btnAllRun_Click(object sender, RoutedEventArgs e) { var idText = tbId.Text; if (string.IsNullOrWhiteSpace(idText)) { MessageBox.Show("灯箱id为空"); } var runTimeText = tbRunTime.Text; if (string.IsNullOrWhiteSpace(runTimeText)) { MessageBox.Show("运行时间为空"); } var keepTimeText = tbKeepTime.Text; if (string.IsNullOrWhiteSpace(keepTimeText)) { MessageBox.Show("停留时间为空"); } try { var runTime = Convert.ToInt32(runTimeText); var keepTime = Convert.ToInt32(keepTimeText); LBMsg box = new LBMsg(); box.Id = Convert.ToInt32(idText); box.RunTime = runTime; box.KeepTime = keepTime; byte time = (byte)(box.RunTime); CanDataWithInfo can1 = new CanDataWithInfo(0x700, new byte[] { time, 0x40, }, "can:0x700, len:7 全网正"); ECANHelper.ins.sendMessageWithInfo(can1); Thread.Sleep((int)(box.RunTime * 1000)); Thread.Sleep((int)(box.KeepTime * 1000)); CanDataWithInfo can3 = new CanDataWithInfo(0x700, new byte[] { time, 0x80, }, "can:0x700, len:7 全网反"); ECANHelper.ins.sendMessageWithInfo(can3); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private static void analysis2() { LBMsg lastLBMsg = null; while (!quit && isRunning) { try { //BaseConfig.ins.IsPowerOn = true; //如果开机时间没到,不往下运行 if (!BaseConfig.ins.IsPowerOn || WAITED) { logger.Info(" Power Off"); try { Thread.Sleep(1000); } catch (Exception) { return; } continue; } logger.Info(" Power On"); //videoBegin = true; if (ConfigHelper.IS_WAIT_VIDEO) { //视频未开始, 等待 if (!videoBegin) { Thread.Sleep(200); continue; } else { videoBegin = false; } } if (null == SelectedModel) { //Thread.Sleep(1000); nextModel(null); continue; } MessageHelper.ins.beginModel(); //获取模式中延时时间的集合 if (SelectedModel.runAll) { LBMsg lBMsg = SelectedModel.ListLBMsg[0]; byte time = (byte)(lBMsg.RunTime); CanDataWithInfo can1 = new CanDataWithInfo(0x700, new byte[] { time, 0x40, }, "can:0x700, len:7 全网正"); ECANHelper.ins.sendMessageWithInfo(can1); Thread.Sleep((int)(lBMsg.RunTime * 1000)); CanDataWithInfo can2 = new CanDataWithInfo(0x700, new byte[] { time, 0xC0, }, "can:0x700, len:7 全网停"); ECANHelper.ins.sendMessageWithInfo(can2); Thread.Sleep((int)(lBMsg.KeepTime * 1000)); CanDataWithInfo can3 = new CanDataWithInfo(0x700, new byte[] { time, 0x80, }, "can:0x700, len:7 全网反"); ECANHelper.ins.sendMessageWithInfo(can3); Thread.Sleep((int)((lBMsg.RunTime + 2) * 1000)); } else { foreach (LBMsg lbMsg in SelectedModel.ListLBMsg) { MessageHelper.ins.startRunBox(lbMsg); lastLBMsg = lbMsg; } while (!MessageHelper.ins.modelIsEnd()) { Thread.Sleep(200); } } Console.WriteLine("model运行结束!"); if (RUN_ONCE) { //临时运行一次结束 RUN_ONCE = false; //暂停 MainWindow.ins.pasued(); } else { int modelWaitTime = SelectedModel.getWaitTimeMS(); byte backTime = 1; if (modelWaitTime > 1) { backTime = (byte)(modelWaitTime - 1); } //全网反转 CanDataWithInfo can = new CanDataWithInfo(0x700, new byte[] { backTime, 0x80, }, "can:0x700, len:7 退全网"); //ECANHelper.ins.sendMessageWithInfo(can); //Debug.Log("进入等待时间 :" + modelWaitTime); if (!ConfigHelper.IS_WAIT_VIDEO) { Thread.Sleep(modelWaitTime); } nextModel(null); } //Thread.Sleep(2000); //Debug.Log("等待时间结束 :" + modelWaitTime); } catch (Exception e) { Console.WriteLine(e.StackTrace + ":" + e.Message); return; } } }
private static void analysis() { LBMsg lastLBMsg = null; while (!quit && isRunning) { try { //BaseConfig.ins.IsPowerOn = true; //如果开机时间没到,不往下运行 if (!BaseConfig.ins.IsPowerOn || WAITED) { //Console.WriteLine(" off time"); Console.WriteLine(" Power Off"); logger.Info(" Power Off"); try { Thread.Sleep(1000); } catch (Exception) { return; } continue; } Console.WriteLine(" Power On"); logger.Info(" Power On"); //videoBegin = true; if (ConfigHelper.IS_WAIT_VIDEO) { //视频未开始, 等待 if (!videoBegin) { Thread.Sleep(200); continue; } else { videoBegin = false; } } if (null == SelectedModel) { //Thread.Sleep(1000); nextModel(null); continue; } //MessageHelper.ins.beginModel(); //CanDataWithInfo can = new CanDataWithInfo((uint)0x02, new byte[] {0x02, 0, 0 }, "can:0x02, len:3 停全网"); //Debug.Log("模式开始:" + SelectedModel.ModelName); //SelectedModel.cleanEndCount(); //获取模式中延时时间的集合 //List<double> listWaitTime = SelectedModel.listWaitTime; if (SelectedModel.runAll) { LBMsg lBMsg = SelectedModel.ListLBMsg[0]; byte time = (byte)(lBMsg.RunTime); CanDataWithInfo can1 = new CanDataWithInfo(0x700, new byte[] { time, 0x40, }, "can:0x700, len:7 全网正"); ECANHelper.ins.sendMessageWithInfo(can1); Thread.Sleep((int)(lBMsg.RunTime * 1000)); CanDataWithInfo can2 = new CanDataWithInfo(0x700, new byte[] { time, 0xC0, }, "can:0x700, len:7 全网停"); ECANHelper.ins.sendMessageWithInfo(can2); Thread.Sleep((int)(lBMsg.KeepTime * 1000)); CanDataWithInfo can3 = new CanDataWithInfo(0x700, new byte[] { time, 0x80, }, "can:0x700, len:7 全网反"); ECANHelper.ins.sendMessageWithInfo(can3); Thread.Sleep((int)((lBMsg.RunTime + 2) * 1000)); } else { List <double> listWaitTime = SelectedModel.getListWaitTime(); for (int i = 0; i < listWaitTime.Count; i++) { double waitTime = 0; double totalTime = listWaitTime[i]; if (i == 0) { waitTime = totalTime; } else { waitTime = totalTime - listWaitTime[i - 1]; } Thread.Sleep((int)(waitTime * 1000)); foreach (LBMsg lbMsg in SelectedModel.ListLBMsg) { if (lbMsg.WaitTime == totalTime) { //Debug.Log("灯箱 :" + lbMsg.Row1 + ":" + lbMsg.Column + " 开始"); //lbMsg.runAble = true; //DataComm.ins.startRunBox(lbMsg); if (lbMsg.RunTime > 0) { MessageHelper.ins.startRunBox(lbMsg); lastLBMsg = lbMsg; } } } } if (null != lastLBMsg) { int lastTime = (int)(lastLBMsg.RunTime * 2 + lastLBMsg.KeepTime); Thread.Sleep(lastTime * 1000); } } //等待灯箱转完 //while (!MessageHelper.ins.modelIsEnd()) { // Thread.Sleep(20); //} //Console.WriteLine("model is end "); //int outTimeCount = 0; //while (!SelectedModel.isRunEnd() && outTimeCount < 60) { // Thread.Sleep(2000); // outTimeCount++; //} if (RUN_ONCE) { //临时运行一次结束 RUN_ONCE = false; //暂停 MainWindow.ins.pasued(); } else { int modelWaitTime = SelectedModel.getWaitTimeMS(); byte backTime = 1; if (modelWaitTime > 1) { backTime = (byte)(modelWaitTime - 1); } //nextModelThread(); //nextModel(null); //全网反转 CanDataWithInfo can = new CanDataWithInfo(0x700, new byte[] { backTime, 0x80, }, "can:0x700, len:7 退全网"); //ECANHelper.ins.sendMessageWithInfo(can); //Debug.Log("进入等待时间 :" + modelWaitTime); //这里的模式停留时间要从最后一个灯箱转完算起 Thread.Sleep(modelWaitTime); nextModel(null); } //Thread.Sleep(2000); //Debug.Log("等待时间结束 :" + modelWaitTime); } catch (Exception e) { Console.WriteLine(e.StackTrace + ":" + e.Message); return; } } }
/// <summary> /// 开线程发送灯箱运行命令, 灯箱运行一个周期的所有命令, 包括正转\ 停留\ 反转 /// </summary> /// <param name="box"></param> public void startRunBox(LBMsg box) { ThreadPool.QueueUserWorkItem(new WaitCallback(runBoxRepeat), box); }