/// <summary> /// TCP数据消息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnTcpRecv(object sender, CTcpRecvArgs e) { try { _TCPLock.AcquireWriterLock(-1); string er = string.Empty; int wr = 0; int devType = 0; int cmdNo = 0; string recvVal = string.Empty; string strReponse = string.Empty; if (!ReposeCommand(e.recvData, out wr, out devType, out cmdNo, out recvVal, out strReponse)) { OnLogArgs.OnEvented(new CLogArgs(1, name, e.recvData, (int)EResult.Action)); OnLogArgs.OnEvented(new CLogArgs(1, name, strReponse, (int)EResult.NG)); return; } if (wr == 2) { OnLogArgs.OnEvented(new CLogArgs(1, name, e.recvData, (int)EResult.Action)); OnCmdArgs.OnEvented(new CCmdArgs(wr, devType, cmdNo, recvVal, e.remoteEndPoint, e.recvData)); return; } string rData = string.Empty; if (serTcp.send(e.remoteEndPoint, strReponse, 0, out rData, out er)) { OnLogArgs.OnEvented(new CLogArgs(1, name, e.recvData, (int)EResult.Action)); OnLogArgs.OnEvented(new CLogArgs(1, name, strReponse, (int)EResult.OK)); OnCmdArgs.OnEvented(new CCmdArgs(wr, devType, cmdNo, recvVal, e.remoteEndPoint, e.recvData)); } else { OnLogArgs.OnEvented(new CLogArgs(1, name, e.recvData, (int)EResult.Action)); OnLogArgs.OnEvented(new CLogArgs(1, name, strReponse, (int)EResult.NG)); OnCmdArgs.OnEvented(new CCmdArgs(wr, devType, cmdNo, recvVal, e.remoteEndPoint, e.recvData)); } } catch (Exception) { throw; } finally { _TCPLock.ReleaseWriterLock(); } }
private void btnSend1_Click(object sender, EventArgs e) { try { btnSend1.Enabled = false; if (btnListen.Text == "监听") { labSerStatus.Text = "未启动服务端监听"; labSerStatus.ForeColor = Color.Red; return; } if (!remoteClient.Contains(cmbClientList.Text)) { labSerStatus.Text = "客户端已不存在"; labSerStatus.ForeColor = Color.Red; return; } string er = string.Empty; string rData = string.Empty; string wData = txtSerMessage.Text; if (chkRtn1.Checked) { wData += "\r\n"; } _devSerTCP.send(cmbClientList.Text, wData, 0, out rData, out er); } catch (Exception) { throw; } finally { btnSend1.Enabled = true; } }