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

Method serialPort1ThreadLoop

test/MultiThreadUnitTests.cpp:133–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131}
132
133void
134MultiThreadUnitTests::serialPort1ThreadLoop()
135{
136 const size_t threadLoopStartTimeMilliseconds = getTimeInMilliSeconds() ;
137 size_t timeElapsedMilliSeconds = 0;
138
139 while (timeElapsedMilliSeconds < timeOutMilliseconds)
140 {
141 //
142 // Write data to the serial port. It should be received by the other
143 // thread.
144 //
145 serialPort1.Write(writeString1 + '\n') ;
146 serialPort1.DrainWriteBuffer() ;
147
148 //
149 // Wait for data to arrive from the other thread
150 //
151 if (serialPort1.IsDataAvailable())
152 {
153 try
154 {
155 readString2.clear() ;
156 serialPort1.ReadLine(readString2, '\n', timeOutMilliseconds) ;
157 }
158 catch (const std::exception& err)
159 {
160 std::cerr << err.what() << std::endl ;
161 }
162
163 if(readString2 != writeString2 + '\n')
164 {
165 const std::lock_guard<std::mutex> lock {mutex} ;
166 failureRate++;
167 }
168 }
169
170 const std::lock_guard<std::mutex> lock {mutex} ;
171 loopCount++;
172
173 timeElapsedMilliSeconds = getTimeInMilliSeconds() - threadLoopStartTimeMilliseconds;
174 }
175}
176
177void
178MultiThreadUnitTests::serialPort2ThreadLoop()

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