public static byte[] SendBytes(string IP, string port, byte[] command) { TCPConnection t = new TCPConnection(IP, Convert.ToUInt16(port)); byte[] receivedBytes = new byte[t.ReadBufferSize]; return(t.RequestData(command)); }
private void SendViaTCPStandard(byte[] bytesToSend) { //if (CheckNetworkConnection(txtCurrentIP.Text,_pingTimeOut)) //{ try { var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); TCPConnection t = new TCPConnection(txtCurrentIP.Text, Convert.ToUInt16(txtCurrentPort.Text)); t.ConditionalReading = chkConditionalReading.Checked; t.EndByte = Convert.ToByte(txtEndByte.Text); t.Delay = Convert.ToInt16(txtDelayTime.Text == string.Empty ? "0" : txtDelayTime.Text); t.CommunicationTimeOut = Convert.ToInt16(txtTCPClientCommunicationTimeOut.Text); t.ReadBufferSize = Convert.ToInt16(txtReadBufferSize.Text); byte[] receivedBytes = t.RequestData(bytesToSend); stopWatch.Stop(); lblCommandExecutionTime.Text = "Send and Read Time:" + stopWatch.ElapsedMilliseconds.ToString() + " ms"; if (receivedBytes == null) { txtReceivedBytesASCII.Text = "error"; hexReceivedBytes.ResetText(); SaveLog("received bytes null"); } else { ShowBytesInTextBoxes(receivedBytes); } } catch (Exception exc) { SaveLog(exc.ToString()); } //} //else //{ // txtReceivedBytesASCII.Text = "IP problem. Check IP address."; // SaveLog("IP Problem"); //}; }
private void SendSingleCommand2(string command) { TCPConnection tcp = new TCPConnection(txtIP.Text, Convert.ToUInt16(txtPort.Text)); byte[] bytesToSend = new byte[5000]; bytesToSend = GetBytes(command); byte[] receivedBytes = new byte[10000]; receivedBytes = tcp.RequestData(bytesToSend); if (receivedBytes == null) { dgvLogs.Rows.Add(selectedItem.ToString(), DateTime.Now.ToString(), "Gelen byte dizisi null."); return; } txtReceivedBytes.Clear(); for (int i = 0; i < 100; i++) { txtReceivedBytes.Text += receivedBytes[i].ToString() + ","; } txtReceivedBytesASCII.Text = ASCIIEncoding.ASCII.GetString(receivedBytes); }