MCPcopy Create free account
hub / github.com/brainflow-dev/brainflow / read_from_serial_port

Method read_from_serial_port

src/utils/libftdi_serial.cpp:171–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171int LibFTDISerial::read_from_serial_port (void *bytes_to_read, int size)
172{
173 // the ftdi will send us data after its latency (max 255ms, default
174 // 16ms) times out, even if its buffer is empty, despite the usb
175 // timeout. libftdi does not enforce waiting for the usb timeout if
176 // the chip responds, even if the chip responds with an empty buffer.
177 // so, the read is repeated until the timeout is reached.
178
179 // this latency behavior is documented in
180 // http://www.ftdichip.com/Support/Documents/AppNotes/AN232B-04_DataLatencyFlow.pdf
181
182 auto deadline =
183 std::chrono::steady_clock::now () + std::chrono::milliseconds (ftdi.usb_read_timeout);
184 last_result = 0;
185 while (last_result == 0 && size > 0 && std::chrono::steady_clock::now () < deadline)
186 {
187 last_result = ftdi_read_data (&ftdi, static_cast<unsigned char *> (bytes_to_read), size);
188 // TODO: negative values are libusb error codes, -666 means usb device unavailable
189 if (last_result < 0)
190 {
191 log_error ("read_from_serial_port");
192 }
193 }
194
195 return last_result;
196}
197
198int LibFTDISerial::send_to_serial_port (const void *message, int length)
199{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected