public byte[] toByteArray() { short datalen = 0; byte[] data = null; byte[] bytes = null; byte[] byteNew = null; try { if (dos != null) { dos.Flush(); data = ms.ToArray(); datalen = (short)data.Length; dos.Close(); } MemoryStream bos1 = new MemoryStream(datalen + 3); DataOutputStream dos1 = new DataOutputStream(new BinaryWriterIns(bos1)); dos1.WriteByteNew(command); dos1.WriteShort(datalen); if (datalen > 0) { dos1.Write(data); } bytes = bos1.ToArray(); byteNew = new byte[bytes.Length - 3]; int n = byteNew.Length; Array.Copy(bytes, 3, byteNew, 0, n); byteNew[0] = (byte)command; dos1.Close(); } catch (IOException e) { Debug.Log(e.ToString()); } return byteNew; }
public byte[] toByteArray() { short datalen = 0; byte[] data = null; byte[] bytes = null; byte[] byteNew = null; try { if (dos != null) { dos.Flush(); data = ms.ToArray(); datalen = (short)data.Length; dos.Close(); } MemoryStream bos1 = new MemoryStream(datalen + 3); DataOutputStream dos1 = new DataOutputStream(new BinaryWriterIns(bos1)); dos1.WriteByteNew(command); dos1.WriteShort(datalen); if (datalen > 0) { dos1.Write(data); } bytes = bos1.ToArray(); byteNew = new byte[bytes.Length - 3]; int n = byteNew.Length; Array.Copy(bytes, 3, byteNew, 0, n); byteNew[0] = (byte)command; dos1.Close(); } catch (IOException e) { Debug.Log(e.ToString()); } return(byteNew); }