private void btnOK_Click(object sender, EventArgs e) { sUrl = sUrlHead; //CallInformationFromServer(); try { //获取ID // GetIdForCallFunction(); CsConst.MyQuene = new Queue <byte[]>(); CsConst.MyBlnCapture = true; if (thread == null) { thread = new Thread(CrossThreadFlush); thread.IsBackground = true; thread.Start(); } HDLUDP.GetRightIPAndPort(); CsConst.mySends.IniTheSocket(CsConst.myLocalIP); timerCall.Enabled = false; #region //if (threadDisplayMessages == null) //{ // threadDisplayMessages = new Thread(ThreadHttpFunction); // threadDisplayMessages.IsBackground = true; // threadDisplayMessages.Start(); //} //if (threadHttp == null) //{ // socketwatch = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // //服务端发送信息需要一个IP地址和端口号 // IPAddress address = IPAddress.Parse(CsConst.myLocalIP); // //将IP地址和端口号绑定到网络节点point上 // IPEndPoint point = new IPEndPoint(address, 88); // //此端口专门用来监听的 // //监听绑定的网络节点 // socketwatch.Bind(point); // //将套接字的监听队列长度限制为20 // socketwatch.Listen(20); // //负责监听客户端的线程:创建一个监听线程 // Thread threadwatch = new Thread(WaitReceiveHttpPostInformation); // //将窗体线程设置为与后台同步,随着主线程结束而结束 // threadwatch.IsBackground = true; // //启动线程 // threadwatch.Start(); //} #endregion } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void frmMain_Load(object sender, EventArgs e) { Control.CheckForIllegalCrossThreadCalls = false; CsConst.mstrINIDefault = new IniFile(System.Windows.Forms.Application.StartupPath + @"\ini\Default.ini"); CsConst.myLocalIP = GetLocalIP(); HDLUDP.GetRightIPAndPort(); DisplayBasicInformation(); DislayLockInformationWhenFirstLoad(); timerCall = new System.Timers.Timer(); timerCall.Interval = 5000 * 1; timerCall.Elapsed += new System.Timers.ElapsedEventHandler(timerCall_Elapsed); bIsWaitingFeedback = false; }
private void AddDeviceToList() { Int16 iSendCount = 0; try { Resend: DateTime d1, d2; d1 = DateTime.Now; d2 = DateTime.Now; List <Byte> listSendBuf = new List <byte>(); listSendBuf.AddRange(randomSearchBuffer); while (CsConst.MySimpleSearchQuene.Count > 0 || HDLUDP.Compare(d2, d1) < 2000) { #region d2 = DateTime.Now; if (CsConst.MySimpleSearchQuene.Count == 0) { continue; } if (CsConst.MySimpleSearchQuene[0] != null) { byte[] readData = CsConst.MySimpleSearchQuene[0]; int index = 1; if (messagesSupportInProject != null && messagesSupportInProject.Count > 0) { index = messagesSupportInProject.Count + 1; } int iDeviceType = readData[19] * 256 + readData[20]; //简易编程操作码返回 Boolean isAdd = true; // 是否要增加 #region Byte bSubNetId = readData[17]; Byte bDeviceId = readData[18]; if (messagesSupportInProject.Count > 0) { foreach (messagesAutoGet tmp in messagesSupportInProject) { if (bSubNetId == tmp.bSubNetId && bDeviceId == tmp.bDeviceId) { isAdd = false; break; } } } else { isAdd = true; } #endregion if (isAdd) { listSendBuf.Add(bSubNetId); listSendBuf.Add(bDeviceId); if (readData[21] == 0xE5 && readData[22] == 0x49 && readData.Length >= 20) { #region AddSimpleFUnctionListToPublicClasses(readData); #endregion } else if (readData[21] == 0x00 && readData[22] == 0x0E && CsConst.AudioBoxDeviceTypeList.Contains(iDeviceType)) { #region messagesAutoGet temp = new messagesAutoGet(); index = index + 1; byte[] arayRemark = new byte[20]; Array.Copy(readData, 25, arayRemark, 0, 20); temp.sMessage = System.Text.ASCIIEncoding.ASCII.GetString(arayRemark); temp.bSubNetId = readData[17]; temp.bDeviceId = readData[18]; temp.bChnId = readData[25]; temp.bigType = 9; temp.bIsNeedReadRemark = false; messagesSupportInProject.Add(temp); #endregion } } } #endregion CsConst.MySimpleSearchQuene.RemoveAt(0); } iSendCount++; if (iSendCount < 4) { CsConst.mySends.AddBufToSndList(listSendBuf.ToArray(), 0xE548, 255, 255, false, false, false, false); goto Resend; } GoOnSearchingDifferentType(); DisplayLockInformationToListview(); } catch { } }