private void btnClose_Click(object sender, EventArgs e) { if (mUdp != null) { mUdp.fUdpClose(); mUdp = null; } if (SendThread != null) { SendThread.Abort(); SendThread = null; } tc = null; this.Close(); this.Dispose(); }
private void SendModeSet(int startId, int endId) { SetBtnEnable(btnSend, false); int i;// startId, endId; string remotHost = " "; string[] tempStr; mUdp = new cUdpSock(10000); mUdp.mDataReciveString += new cUdpSock.mDataReciveStringEventHandle(mUdp_mDataReciveString); string ModeStr = ""; ModeStr = DataClassToStr(modeSet); tempStr = cMain.RemoteHostName.Split('.'); if (tempStr.Length == 4) { remotHost = tempStr[0] + "." + tempStr[1] + "." + tempStr[2] + "."; } long startTime = 0; listBox1.BeginInvoke(new EventHandler(listAdditem), "Clear"); for (i = startId; i <= endId; i++) { for (int k = 0; k < 3; k++) { listBox1.BeginInvoke(new EventHandler(listAdditem), " " + string.Format("{0}{1}#", "", i) + "开始发送数据...."); is_B_Ok = false; mUdp.fUdpSend(string.Format("{0}{1}", remotHost, i + 160), 3000, ModeStr); startTime = Environment.TickCount; is_TimeOut = false; do { Thread.Sleep(20); if (Environment.TickCount - startTime > timeOut) { is_TimeOut = true; } } while (!is_B_Ok && !is_TimeOut); if (is_B_Ok) { k = 3; listBox1.BeginInvoke(new EventHandler(listAdditem), " " + i.ToString() + "#检测数据发送成功...."); } else { listBox1.BeginInvoke(new EventHandler(listAdditem), " " + i.ToString() + "#检测数据发送失败.................."); } } } SetBtnEnable(btnSend, true); SetBtnEnable(btnStop, false); if (mUdp != null) { mUdp.fUdpClose(); mUdp = null; } }
private void SendModeSet(int startId, int endId) { SetBtnEnable(btnSend, false); //btnSend.Enabled = false;// Invoke(new EventHandler(isEnableSendButton), "false"); int i;// startId, endId; string remotHost = " "; string[] tempStr; //startId = Convert.ToInt16(readText(cbbStart)); //endId = Convert.ToInt16(readText(cbbEnd)); mUdp = new cUdpSock(10000); mUdp.mDataReciveString += new cUdpSock.mDataReciveStringEventHandle(mUdp_mDataReciveString); string ModeStr = ""; //string SnStr = ""; //SnStr = DataClassToStr(cSnSet.DataXmlToClass(modeSet.mId)); ModeStr = DataClassToStr(modeSet); tempStr = cMain.RemoteHostName.Split('.'); if (tempStr.Length == 4) { remotHost = tempStr[0] + "." + tempStr[1] + "." + tempStr[2] + "."; } long startTime = 0; listBox1.BeginInvoke(new EventHandler(listAdditem), "Clear"); for (i = startId; i <= endId; i++) { for (int j = 0; j < 3; j++) { is_P_Ok = false; mUdp.fUdpSend(remotHost + i.ToString(), 3000, "P"); listBox1.BeginInvoke(new EventHandler(listAdditem), string.Format("正在第{0}次连接{1}号小车", j + 1, remotHost + i.ToString())); startTime = Environment.TickCount; is_TimeOut = false; do { //Application.DoEvents(); Thread.Sleep(20); if (Environment.TickCount - startTime > timeOut) { is_TimeOut = true; } } while (!is_P_Ok && !is_TimeOut); if (is_P_Ok) { j = 3; listBox1.BeginInvoke(new EventHandler(listAdditem), " " + remotHost + i.ToString() + "号连接成功,开始发送数据...."); for (int k = 0; k < 3; k++) { is_B_Ok = false; mUdp.fUdpSend(remotHost + i.ToString(), 3000, ModeStr); startTime = Environment.TickCount; is_TimeOut = false; do { //Application.DoEvents(); Thread.Sleep(20); if (Environment.TickCount - startTime > timeOut) { is_TimeOut = true; } } while (!is_B_Ok && !is_TimeOut); if (is_B_Ok) { k = 3; listBox1.BeginInvoke(new EventHandler(listAdditem), " " + remotHost + i.ToString() + "号检测数据发送成功...."); } else { listBox1.BeginInvoke(new EventHandler(listAdditem), " " + remotHost + i.ToString() + "号检测数据发送失败.................."); } } Thread.Sleep(100); //for (int k = 0; k < 3; k++) //{ // is_C_Ok = false; // mUdp.fUdpSend(remotHost + i.ToString(), 3000, SnStr); // startTime = Environment.TickCount; // is_TimeOut = false; // do // { // //Application.DoEvents(); // Thread.Sleep(20); // if (Environment.TickCount - startTime > timeOut) // { // is_TimeOut = true; // } // } while (!is_C_Ok && !is_TimeOut); // if (is_C_Ok) // { // k = 3; // listBox1.BeginInvoke(new EventHandler(listAdditem), " " + remotHost + i.ToString() + "号指令数据发送成功...."); // } // else // { // listBox1.BeginInvoke(new EventHandler(listAdditem), " " + remotHost + i.ToString() + "号指令数据发送失败.................."); // } //} } else { listBox1.BeginInvoke(new EventHandler(listAdditem), string.Format("{0}号第{1}次连接失败,无法发送数据....................", remotHost + i.ToString(), j + 1)); } } } SetBtnEnable(btnSend, true); SetBtnEnable(btnStop, false); //btnSend.BeginInvoke(new EventHandler(isEnableSendButton), "true"); if (mUdp != null) { mUdp.fUdpClose(); mUdp = null; } }