I have a string of data that ends in a line feed (0x0A), I need to send it out on a serial port without adding the extra carriage return and line feed attached.
I can put together and send the string to the serial port but when I do it automatically adds (or converts the line feed to a carriage return and line feed).
How can I send the string as it is without it being converted?
I have some sample code if it helps but I am assuming that it is a command option.
What's a "command option"? The preferred answer depends heavily on whether your "string" is a C-String, std::string, std::wstring or a BSTR (Windows Automation only*).
- In the first case you want the function "strok()" that is exposed in the 'cstdlib' header file. The second parameter here is where you designate the delimiter, in this case you would enter '\n'.
- In the second and third scenarios you'll want to use either "std::string.substr()" or "std::string.copy()" along with "std::string.find()" to split the array. All three of the function mentioned are available for both data types and which one of the first two you use is basically dealers choice.
- The final case, BSTR for Windows, is something that I really only put in here so that I look smarter then I really am. If you are running into this problem with this data type then I have to ask what the heck you are doing because, regardless of what it is, you're doing it wrong.