MCPcopy Create free account
hub / github.com/crayzeewulf/libserial / serialPort2ThreadLoop

Method serialPort2ThreadLoop

test/MultiThreadUnitTests.cpp:177–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175}
176
177void
178MultiThreadUnitTests::serialPort2ThreadLoop()
179{
180 const size_t threadLoopStartTimeMilliseconds = getTimeInMilliSeconds() ;
181 size_t timeElapsedMilliSeconds = 0;
182
183 while (timeElapsedMilliSeconds < timeOutMilliseconds)
184 {
185 //
186 // Write data to the serial port. It should be received by the other
187 // thread.
188 //
189 serialPort2.Write(writeString2 + '\n') ;
190 serialPort2.DrainWriteBuffer() ;
191
192 //
193 // Wait for data to arrive from the other thread
194 //
195 if (serialPort2.IsDataAvailable())
196 {
197 try
198 {
199 readString1.clear() ;
200 serialPort2.ReadLine(readString1, '\n', timeOutMilliseconds) ;
201 }
202 catch (const std::exception& err)
203 {
204 std::cerr << err.what() << std::endl ;
205 }
206
207 if(readString1 != writeString1 + '\n')
208 {
209 const std::lock_guard<std::mutex> lock {mutex} ;
210 failureRate++;
211 }
212 }
213
214 const std::lock_guard<std::mutex> lock {mutex} ;
215 loopCount++;
216
217 timeElapsedMilliSeconds = getTimeInMilliSeconds() - threadLoopStartTimeMilliseconds;
218 }
219}
220
221void
222MultiThreadUnitTests::testMultiThreadSerialStreamReadWrite()

Callers

nothing calls this directly

Calls 4

WriteMethod · 0.80
ReadLineMethod · 0.80
DrainWriteBufferMethod · 0.45
IsDataAvailableMethod · 0.45

Tested by

no test coverage detected