public void Send(byte[] dataBytes, IcXdataType ipDataType) { Log.Debug("In send"); try { const byte subType = (byte)0; byte[] numArray; if (ipDataType == IcXdataType.Data) //F2 { try { numArray = new byte[dataBytes.Length + 3]; Array.Copy(dataBytes, 0, numArray, 2, dataBytes.Length); numArray[0] = (byte)ipDataType; numArray[1] = subType; numArray[numArray.Length - 1] = byte.MaxValue; //Log.Debug((object)("IPPort Snd: " + ((object)ipDataType).ToString() + "; " + Encoding.ASCII.GetString(dataBytes))); _resendDataMessage = numArray; } catch (Exception ex) { Log.Error("Send(byte[] dataBytes, ICXclient.ICXdataType ipDataType, bool hideInLog) EXCEPTION: " + ex.Message); numArray = null; } } else { try { numArray = new byte[dataBytes.Length + 3]; numArray[0] = (byte)ipDataType; numArray[1] = 0; for (var index = 0; index < dataBytes.Length; ++index) { numArray[index + 2] = dataBytes[index]; } numArray[numArray.Length - 1] = byte.MaxValue; Log.Debug("numArray clear for send"); //Log.Debug((object)("IPPort Snd: " + ((object)ipDataType).ToString())); } catch (Exception ex) { numArray = null; Log.Error("EX: " + ex.Message); } } try { if (numArray == null || _icxClient == null) { return; } if (_icxClient.Client != null) { _icxClient.Client.Send(numArray); Log.Debug("Sending numArray"); RaiseNewDataSent(new NewDataEventArgs(subType, numArray)); if (_resendDataMessage == null) { return; } _resendDataMessage = null; } else { Disconnect(); RaiseClientError(new ClientErrorEventArgs("Tcp-Client disconnected", false)); } } catch (Exception ex) { Log.Error("EX: " + ex.Message); } } catch (Exception ex) { var icxClient = _icxClient; if (icxClient != null && icxClient.Connected) { if (_icxClient != null) { _icxClient.GetStream().Close(); } } if (_icxClient != null) { _icxClient.Close(); } RaiseClientError(new ClientErrorEventArgs(ex.Message, false)); Log.Error("EX: " + ex.Message); } }
public void Send(string data, IcXdataType ipDataType) { // Log.Debug("In send 3"); Send(new ASCIIEncoding().GetBytes(data), ipDataType); }