A very simple, uncluttered version of the below, mainly for linux
| 857 | |
| 858 | // A very simple, uncluttered version of the below, mainly for linux |
| 859 | unsigned int SerialIO::justRead(void* data, unsigned int dataLength) { |
| 860 | if ((data == nullptr) || (dataLength == 0)) return 0; |
| 861 | if (!isPortOpen()) return 0; |
| 862 | |
| 863 | #ifdef FTDI_D2XX_AVAILABLE |
| 864 | if (m_ftdi.isOpen()) { |
| 865 | m_ftdi.FT_SetTimeouts(m_readTimeout + (m_readTimeoutMultiplier * dataLength), m_writeTimeout + (m_writeTimeoutMultiplier * dataLength)); |
| 866 | |
| 867 | DWORD dataRead = 0; |
| 868 | if (m_ftdi.FT_Read((LPVOID)data, dataLength, &dataRead) != FTDI::FT_STATUS::FT_OK) dataRead = 0; |
| 869 | return dataRead; |
| 870 | } |
| 871 | #endif |
| 872 | |
| 873 | #ifdef _WIN32 |
| 874 | DWORD read = 0; |
| 875 | if (!ReadFile(m_portHandle, data, dataLength, &read, NULL)) read = 0; |
| 876 | return read; |
| 877 | #else |
| 878 | int result = ::read(m_portHandle, data, dataLength); |
| 879 | |
| 880 | if (result < 0) return 0; |
| 881 | |
| 882 | return (unsigned int)result; |
| 883 | |
| 884 | |
| 885 | #endif |
| 886 | |
| 887 | return 0; |
| 888 | |
| 889 | } |
| 890 | |
| 891 | // Attempts to read some data from the port. Returns how much it actually read. |
| 892 | // Returns how much it actually read |
no test coverage detected