/// <summary> /// 读取预分拣DB块 /// </summary> /// <param name="index"></param> /// <param name="groupno"></param> void ReadDBinfo(int index, decimal groupno) { ListmbInfo.Clear(); //清空list // dgvSortingBeltInfo = null; panelCig.Controls.Clear(); int ReadIndex = 0; for (int i = 0; i < 40; i++) //从电控读取数据 填充 listmbinfo { Sortnum = ListSort[index - 1].ReadD(ReadIndex).CastTo <int>(0); //任务号 if (Sortnum > 0) //任务号不为0 { MainBeltInfo info = new MainBeltInfo(); info.SortNum = Sortnum; //任务号 info.Place = (ListSort[index - 1].ReadD((ReadIndex + 1)).CastTo <decimal>(-1) / 1000); //位置(米) info.Quantity = ListSort[index - 1].ReadD((ReadIndex + 2)).CastTo <int>(-1); //数量 info.GroupNO = groupno; //组号 ListmbInfo.Add(info); } ReadIndex = ReadIndex + 4; } MainBeltInfoService.GetSortMainBeltInfo(ListmbInfo); //填充完成之后传进方法 计算 , ListmbInfo = ListmbInfo.OrderBy(a => a.Place).ToList(); //对距离任务号进行排序 pbLoading.Visible = false; }
/// <summary> /// 读取预分拣DB块 /// </summary> /// <param name="index"></param> /// <param name="groupno"></param> void ReadDBinfo(decimal groupno) { ListmbInfoA.Clear(); //清空list ListmbInfoB.Clear(); for (int j = 0; j < 1; j++) { // dgvSortingBeltInfo = null; panebelt.Controls.Clear(); int ReadIndex = 0; for (int i = 0; i < 40; i++) //从电控读取数据 填充 listmbinfo { Sortnum = ListSort[j].ReadD(ReadIndex).CastTo <int>(0); //任务号 if (Sortnum > 0) //任务号不为0 { MainBeltInfo info = new MainBeltInfo(); info.SortNum = Sortnum; //任务号 info.Place = (ListSort[j].ReadD((ReadIndex + 1)).CastTo <decimal>(-1) / 1000); //位置(米) info.Quantity = ListSort[j].ReadD((ReadIndex + 2)).CastTo <int>(-1); //数量 info.GroupNO = groupno; //组号 info.DeviceName = ""; if (j == 0) { ListmbInfoA.Add(info); } else { ListmbInfoB.Add(info); } } ReadIndex = ReadIndex + 4; } if (j == 0) { MainBeltInfoService.GetSortMainBeltInfo(ListmbInfoA); //填充完成之后传进方法 计算 , ListmbInfoA = ListmbInfoA.OrderBy(a => a.Place).ToList(); //对距离任务号进行排序 GetDviceName(ListmbInfoA, "btnA"); } else { MainBeltInfoService.GetSortMainBeltInfo(ListmbInfoB); //填充完成之后传进方法 计算 , ListmbInfoB = ListmbInfoA.OrderBy(a => a.Place).ToList(); //对距离任务号进行排序 GetDviceName(ListmbInfoB, "btnB"); } } if (isOnLine) { panel3.Visible = false; } else { lblloading.Text = "服务器连接失败!请检查网络"; } }
/// <summary> /// 预分拣皮带 /// </summary> /// <param name="GroupNo"></param> /// <returns></returns> public string GetSortBelt(int GroupNo) { string conncetionGroupStr = "S7:[FJConnectionGroup1]";//默认为第一组 if (GroupNo == 1 || GroupNo == 2) { conncetionGroupStr = "S7:[FJConnectionGroup1]"; } else if (GroupNo == 3 || GroupNo == 4) { conncetionGroupStr = "S7:[FJConnectionGroup2]"; } else if (GroupNo == 5 || GroupNo == 6) { conncetionGroupStr = "S7:[FJConnectionGroup3]"; } else if (GroupNo == 7 || GroupNo == 8) { conncetionGroupStr = "S7:[FJConnectionGroup4]"; } try { OpcServer.Connect(1, conncetionGroupStr); } catch (Exception ex) { return("远程连接失败,请检查网络"); } List <MainBeltInfo> ListmbInfo = new List <MainBeltInfo>(); if (GroupNo == 1 || GroupNo == 3 || GroupNo == 5 || GroupNo == 7) { int ReadIndex = 0; for (int i = 0; i < 40; i++) //从电控读取数据 填充 listmbinfo { decimal Sortnum = OpcServer.listUnionTaskGroup[7].ReadD(ReadIndex).CastTo <int>(0); //任务号 if (Sortnum > 0) //任务号不为0 { MainBeltInfo info = new MainBeltInfo(); info.SortNum = Sortnum; //任务号 info.Place = (OpcServer.listUnionTaskGroup[7].ReadD((ReadIndex + 1)).CastTo <decimal>(-1) / 1000); //位置(米) info.Quantity = OpcServer.listUnionTaskGroup[7].ReadD((ReadIndex + 2)).CastTo <int>(-1); //数量 info.GroupNO = GroupNo; //组号 ListmbInfo.Add(info); } ReadIndex = ReadIndex + 4; } } else { int ReadIndex = 0; for (int i = 0; i < 40; i++) //从电控读取数据 填充 listmbinfo { decimal Sortnum = OpcServer.listUnionTaskGroup[8].ReadD(ReadIndex).CastTo <int>(0); //任务号 if (Sortnum > 0) //任务号不为0 { MainBeltInfo info = new MainBeltInfo(); info.SortNum = Sortnum; //任务号 info.Place = (OpcServer.listUnionTaskGroup[8].ReadD((ReadIndex + 1)).CastTo <decimal>(-1) / 1000); //位置(米) info.Quantity = OpcServer.listUnionTaskGroup[8].ReadD((ReadIndex + 2)).CastTo <int>(-1); //数量 info.GroupNO = GroupNo; //组号 ListmbInfo.Add(info); } ReadIndex = ReadIndex + 4; } } MainBeltInfoService.GetSortMainBeltInfo(ListmbInfo); //填充完成之后传进方法 计算 , ListmbInfo = ListmbInfo.OrderBy(a => a.Place).ToList(); //对距离任务号进行排序 if (ListmbInfo.Count > 0) { if (ListmbInfo != null && ListmbInfo.Count > 0) { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List <MainBeltInfo>)); using (MemoryStream ms = new MemoryStream()) { ser.WriteObject(ms, ListmbInfo); string s = Encoding.UTF8.GetString(ms.ToArray()); s = s.Replace("\\", ""); writeLog.Write("\r查询分拣:第" + GroupNo + "组\r"); return(s); } } else { writeLog.Write("GetSortBelt(" + GroupNo + ")查询结果集为空"); return("当前分拣组无数据,请重新查询!"); } } else { writeLog.Write("GetSortBelt(" + GroupNo + ")读取DB块数据异常"); return("从电控获取数据失败,请重新查询"); } }