private bool VerifyRead(System.Text.Encoding encoding, ReadDataFromEnum readDataFrom, int bufferSize) { SerialPort com1 = TCSupport.InitFirstSerialPort(); SerialPort com2 = TCSupport.InitSecondSerialPort(com1); char[] charXmitBuffer = TCSupport.GetRandomChars(bufferSize, false); byte[] byteXmitBuffer; byteXmitBuffer = encoding.GetBytes(charXmitBuffer); com1.ReadTimeout = 500; com1.Encoding = encoding; com1.Open(); if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback { com2.Open(); } switch (readDataFrom) { case ReadDataFromEnum.NonBuffered: return(VerifyReadNonBuffered(com1, com2, byteXmitBuffer)); case ReadDataFromEnum.Buffered: return(VerifyReadBuffered(com1, com2, byteXmitBuffer)); case ReadDataFromEnum.BufferedAndNonBuffered: return(VerifyReadBufferedAndNonBuffered(com1, com2, byteXmitBuffer)); } return(false); }
private void VerifyRead(Encoding encoding, int numberOfBytesToRead, ReadDataFromEnum readDataFrom) { using (SerialPort com1 = TCSupport.InitFirstSerialPort()) using (SerialPort com2 = TCSupport.InitSecondSerialPort(com1)) { Random rndGen = new Random(-55); char[] charsToWrite = new char[numberOfBytesToRead]; byte[] bytesToWrite = new byte[numberOfBytesToRead]; //Genrate random chars to send for (int i = 0; i < bytesToWrite.Length; i++) { char randChar = (char)rndGen.Next(0, ushort.MaxValue); charsToWrite[i] = randChar; } Debug.WriteLine("Verifying read method endocing={0} with {1} random chars", encoding.EncodingName, bytesToWrite.Length); com1.ReadTimeout = 500; com1.Encoding = encoding; TCSupport.SetHighSpeed(com1, com2); com1.Open(); if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback { com2.Open(); } bytesToWrite = com1.Encoding.GetBytes(charsToWrite, 0, charsToWrite.Length); switch (readDataFrom) { case ReadDataFromEnum.NonBuffered: VerifyReadNonBuffered(com1, com2, bytesToWrite); break; case ReadDataFromEnum.Buffered: VerifyReadBuffered(com1, com2, bytesToWrite); break; case ReadDataFromEnum.BufferedAndNonBuffered: VerifyReadBufferedAndNonBuffered(com1, com2, bytesToWrite); break; default: throw new ArgumentOutOfRangeException(nameof(readDataFrom), readDataFrom, null); } } }
private void VerifyRead(Encoding encoding, ReadDataFromEnum readDataFrom) { using (SerialPort com1 = TCSupport.InitFirstSerialPort()) using (SerialPort com2 = TCSupport.InitSecondSerialPort(com1)) { Random rndGen = new Random(-55); int bufferSize = numRndByte; byte[] byteXmitBuffer = new byte[bufferSize]; //Genrate random bytes for (int i = 0; i < byteXmitBuffer.Length; i++) { byteXmitBuffer[i] = (byte)rndGen.Next(0, 256); } com1.ReadTimeout = 500; com1.Encoding = encoding; TCSupport.SetHighSpeed(com1, com2); com1.Open(); if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback { com2.Open(); } switch (readDataFrom) { case ReadDataFromEnum.NonBuffered: VerifyReadNonBuffered(com1, com2, byteXmitBuffer); break; case ReadDataFromEnum.Buffered: VerifyReadBuffered(com1, com2, byteXmitBuffer); break; case ReadDataFromEnum.BufferedAndNonBuffered: VerifyReadBufferedAndNonBuffered(com1, com2, byteXmitBuffer); break; default: throw new ArgumentOutOfRangeException(nameof(readDataFrom)); } } }
public bool VerifyRead(System.Text.Encoding encoding, int numberOfBytesToRead, ReadDataFromEnum readDataFrom) { SerialPort com1 = TCSupport.InitFirstSerialPort(); SerialPort com2 = TCSupport.InitSecondSerialPort(com1); Random rndGen = new Random(-55); char[] charsToWrite = new char[numberOfBytesToRead]; byte[] bytesToWrite = new byte[numberOfBytesToRead]; //Genrate random chars to send for (int i = 0; i < bytesToWrite.Length; i++) { char randChar = (char)rndGen.Next(0, System.UInt16.MaxValue); charsToWrite[i] = randChar; } Console.WriteLine("Verifying read method endocing={0} with {1} random chars", encoding.EncodingName, bytesToWrite.Length); com1.ReadTimeout = 500; com1.Encoding = encoding; com1.Open(); if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback { com2.Open(); } bytesToWrite = com1.Encoding.GetBytes(charsToWrite, 0, charsToWrite.Length); switch (readDataFrom) { case ReadDataFromEnum.NonBuffered: return(VerifyReadNonBuffered(com1, com2, bytesToWrite)); case ReadDataFromEnum.Buffered: return(VerifyReadBuffered(com1, com2, bytesToWrite)); case ReadDataFromEnum.BufferedAndNonBuffered: return(VerifyReadBufferedAndNonBuffered(com1, com2, bytesToWrite)); } return(false); }
private void VerifyRead(Encoding encoding, ReadDataFromEnum readDataFrom, int bufferSize) { using (SerialPort com1 = TCSupport.InitFirstSerialPort()) using (SerialPort com2 = TCSupport.InitSecondSerialPort(com1)) { char[] charXmitBuffer = TCSupport.GetRandomChars(bufferSize, false); byte[] byteXmitBuffer = encoding.GetBytes(charXmitBuffer); com1.ReadTimeout = 500; com1.Encoding = encoding; TCSupport.SetHighSpeed(com1, com2); com1.Open(); if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback { com2.Open(); } switch (readDataFrom) { case ReadDataFromEnum.NonBuffered: VerifyReadNonBuffered(com1, com2, byteXmitBuffer); break; case ReadDataFromEnum.Buffered: VerifyReadBuffered(com1, com2, byteXmitBuffer); break; case ReadDataFromEnum.BufferedAndNonBuffered: VerifyReadBufferedAndNonBuffered(com1, com2, byteXmitBuffer); break; default: throw new ArgumentOutOfRangeException(nameof(readDataFrom), readDataFrom, null); } } }
private bool VerifyRead(System.Text.Encoding encoding, ReadDataFromEnum readDataFrom) { SerialPort com1 = TCSupport.InitFirstSerialPort(); SerialPort com2 = TCSupport.InitSecondSerialPort(com1); Random rndGen = new Random(-55); int bufferSize = numRndByte; byte[] byteXmitBuffer = new byte[bufferSize]; //Genrate random bytes for (int i = 0; i < byteXmitBuffer.Length; i++) { byteXmitBuffer[i] = (byte)rndGen.Next(0, 256); } com1.ReadTimeout = 500; com1.Encoding = encoding; com1.Open(); if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback { com2.Open(); } switch (readDataFrom) { case ReadDataFromEnum.NonBuffered: return(VerifyReadNonBuffered(com1, com2, byteXmitBuffer)); case ReadDataFromEnum.Buffered: return(VerifyReadBuffered(com1, com2, byteXmitBuffer)); case ReadDataFromEnum.BufferedAndNonBuffered: return(VerifyReadBufferedAndNonBuffered(com1, com2, byteXmitBuffer)); } return(false); }
private void VerifyRead(Encoding encoding, string newLine, int numBytesRead, int numNewLines, ReadDataFromEnum readDataFrom) { using (SerialPort com1 = TCSupport.InitFirstSerialPort()) using (SerialPort com2 = TCSupport.InitSecondSerialPort(com1)) { Random rndGen = new Random(-55); StringBuilder strBldrToWrite; int numNewLineChars = newLine.ToCharArray().Length; int minLength = (1 + numNewLineChars) * numNewLines; if (minLength < numBytesRead) { strBldrToWrite = TCSupport.GetRandomStringBuilder(numBytesRead, TCSupport.CharacterOptions.None); } else { strBldrToWrite = TCSupport.GetRandomStringBuilder(rndGen.Next(minLength, minLength * 2), TCSupport.CharacterOptions.None); } //We need place the newLine so that they do not write over eachother int divisionLength = strBldrToWrite.Length / numNewLines; int range = divisionLength - numNewLineChars; for (int i = 0; i < numNewLines; i++) { int newLineIndex = rndGen.Next(0, range + 1); strBldrToWrite.Insert(newLineIndex + (i * divisionLength) + (i * numNewLineChars), newLine); } Debug.WriteLine("Verifying ReadTo encoding={0}, newLine={1}, numBytesRead={2}, numNewLines={3}", encoding, newLine, numBytesRead, numNewLines); com1.ReadTimeout = 500; com1.Encoding = encoding; TCSupport.SetHighSpeed(com1, com2); com1.Open(); if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback { com2.Open(); } switch (readDataFrom) { case ReadDataFromEnum.NonBuffered: VerifyReadNonBuffered(com1, com2, strBldrToWrite.ToString(), newLine); break; case ReadDataFromEnum.Buffered: VerifyReadBuffered(com1, com2, strBldrToWrite.ToString(), newLine); break; case ReadDataFromEnum.BufferedAndNonBuffered: VerifyReadBufferedAndNonBuffered(com1, com2, strBldrToWrite.ToString(), newLine); break; default: throw new ArgumentOutOfRangeException(nameof(readDataFrom), readDataFrom, null); } } }
private void VerifyRead(char[] buffer, int offset, int count, Encoding encoding, int numberOfBytesToRead, ReadDataFromEnum readDataFrom) { using (SerialPort com1 = TCSupport.InitFirstSerialPort()) using (SerialPort com2 = TCSupport.InitSecondSerialPort(com1)) { Random rndGen = new Random(-55); char[] charsToWrite; char[] expectedChars = new char[numberOfBytesToRead]; byte[] bytesToWrite = new byte[numberOfBytesToRead]; if (1 < count) { charsToWrite = TCSupport.GetRandomChars(numberOfBytesToRead, TCSupport.CharacterOptions.Surrogates); } else { charsToWrite = TCSupport.GetRandomChars(numberOfBytesToRead, TCSupport.CharacterOptions.None); } //Genrate some random chars in the buffer for (int i = 0; i < buffer.Length; i++) { char randChar = (char)rndGen.Next(0, ushort.MaxValue); buffer[i] = randChar; } TCSupport.SetHighSpeed(com1, com2); Debug.WriteLine( "Verifying read method buffer.Length={0}, offset={1}, count={2}, endocing={3} with {4} random chars", buffer.Length, offset, count, encoding.EncodingName, bytesToWrite.Length); com1.ReadTimeout = 500; com1.Encoding = encoding; com1.Open(); if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback { com2.Open(); } bytesToWrite = com1.Encoding.GetBytes(charsToWrite, 0, charsToWrite.Length); expectedChars = com1.Encoding.GetChars(bytesToWrite, 0, bytesToWrite.Length); switch (readDataFrom) { case ReadDataFromEnum.NonBuffered: VerifyReadNonBuffered(com1, com2, bytesToWrite, buffer, offset, count); break; case ReadDataFromEnum.Buffered: VerifyReadBuffered(com1, com2, bytesToWrite, buffer, offset, count); break; case ReadDataFromEnum.BufferedAndNonBuffered: VerifyReadBufferedAndNonBuffered(com1, com2, bytesToWrite, buffer, offset, count); break; default: throw new ArgumentOutOfRangeException(nameof(readDataFrom), readDataFrom, null); } } }
private void VerifyRead(char[] buffer, int offset, int count, int numberOfBytesToRead, ReadDataFromEnum readDataFrom) { VerifyRead(buffer, offset, count, new ASCIIEncoding(), numberOfBytesToRead, readDataFrom); }
private void VerifyRead(System.Text.Encoding encoding, ReadDataFromEnum readDataFrom) { VerifyRead(encoding, readDataFrom, numRndChar); }
private void VerifyRead(byte[] buffer, int offset, int count, int numberOfBytesToRead, ReadDataFromEnum readDataFrom) { using (SerialPort com1 = TCSupport.InitFirstSerialPort()) using (SerialPort com2 = TCSupport.InitSecondSerialPort(com1)) { Random rndGen = new Random(); byte[] bytesToWrite = new byte[numberOfBytesToRead]; //Genrate random bytes for (int i = 0; i < bytesToWrite.Length; i++) { byte randByte = (byte)rndGen.Next(0, 256); bytesToWrite[i] = randByte; } //Genrate some random bytes in the buffer for (int i = 0; i < buffer.Length; i++) { byte randByte = (byte)rndGen.Next(0, 256); buffer[i] = randByte; } Debug.WriteLine("Verifying read method buffer.Length={0}, offset={1}, count={2} with {3} random chars", buffer.Length, offset, count, bytesToWrite.Length); com1.ReadTimeout = 500; com1.Open(); if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback { com2.Open(); } switch (readDataFrom) { case ReadDataFromEnum.NonBuffered: VerifyReadNonBuffered(com1, com2, bytesToWrite, buffer, offset, count); break; case ReadDataFromEnum.Buffered: VerifyReadBuffered(com1, com2, bytesToWrite, buffer, offset, count); break; case ReadDataFromEnum.BufferedAndNonBuffered: VerifyReadBufferedAndNonBuffered(com1, com2, bytesToWrite, buffer, offset, count); break; default: throw new ArgumentOutOfRangeException(nameof(readDataFrom), readDataFrom, null); } } }
private bool VerifyRead(System.Text.Encoding encoding, ReadDataFromEnum readDataFrom) { return(VerifyRead(encoding, readDataFrom, numRndChar)); }
public bool VerifyRead(byte[] buffer, int offset, int count, int numberOfBytesToRead, ReadDataFromEnum readDataFrom) { SerialPort com1 = TCSupport.InitFirstSerialPort(); SerialPort com2 = TCSupport.InitSecondSerialPort(com1); Random rndGen = new Random(); byte[] bytesToWrite = new byte[numberOfBytesToRead]; //Genrate random bytes for (int i = 0; i < bytesToWrite.Length; i++) { byte randByte = (byte)rndGen.Next(0, 256); bytesToWrite[i] = randByte; } //Genrate some random bytes in the buffer for (int i = 0; i < buffer.Length; i++) { byte randByte = (byte)rndGen.Next(0, 256); buffer[i] = randByte; } Console.WriteLine("Verifying read method buffer.Lenght={0}, offset={1}, count={2} with {3} random chars", buffer.Length, offset, count, bytesToWrite.Length); com1.ReadTimeout = 500; com1.Open(); if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback { com2.Open(); } switch (readDataFrom) { case ReadDataFromEnum.NonBuffered: return(VerifyReadNonBuffered(com1, com2, bytesToWrite, buffer, offset, count)); case ReadDataFromEnum.Buffered: return(VerifyReadBuffered(com1, com2, bytesToWrite, buffer, offset, count)); case ReadDataFromEnum.BufferedAndNonBuffered: return(VerifyReadBufferedAndNonBuffered(com1, com2, bytesToWrite, buffer, offset, count)); } return(false); }
public bool VerifyRead(System.Text.Encoding encoding, string newLine, int numBytesRead, int numNewLines, ReadDataFromEnum readDataFrom) { SerialPort com1 = TCSupport.InitFirstSerialPort(); SerialPort com2 = TCSupport.InitSecondSerialPort(com1); Random rndGen = new Random(-55); System.Text.StringBuilder strBldrToWrite; int numNewLineChars = newLine.ToCharArray().Length; int minLength = (1 + numNewLineChars) * numNewLines; if (minLength < numBytesRead) { strBldrToWrite = TCSupport.GetRandomStringBuilder(numBytesRead, TCSupport.CharacterOptions.None); } else { strBldrToWrite = TCSupport.GetRandomStringBuilder(rndGen.Next(minLength, minLength * 2), TCSupport.CharacterOptions.None); } //We need place the newLine so that they do not write over eachother int divisionLength = strBldrToWrite.Length / numNewLines; int range = divisionLength - numNewLineChars; for (int i = 0; i < numNewLines; i++) { int newLineIndex = rndGen.Next(0, range + 1); strBldrToWrite.Insert(newLineIndex + (i * divisionLength) + (i * numNewLineChars), newLine); } Console.WriteLine("Verifying ReadTo encoding={0}, newLine={1}, numBytesRead={2}, numNewLines={3}", encoding, newLine, numBytesRead, numNewLines); com1.ReadTimeout = 500; com1.Encoding = encoding; com1.Open(); if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback { com2.Open(); } switch (readDataFrom) { case ReadDataFromEnum.NonBuffered: return(VerifyReadNonBuffered(com1, com2, strBldrToWrite.ToString(), newLine)); case ReadDataFromEnum.Buffered: return(VerifyReadBuffered(com1, com2, strBldrToWrite.ToString(), newLine)); case ReadDataFromEnum.BufferedAndNonBuffered: return(VerifyReadBufferedAndNonBuffered(com1, com2, strBldrToWrite.ToString(), newLine)); } return(false); }