I am using serial port to control a device called nano controller. I used CreateFile, writeFile and readFile for communication.
this is the syntax for writeFile,
if (!WriteFile(hComm, lpBuf, dwToWrite, &dwWritten, &osWrite)) {
if (GetLastError() != ERROR_IO_PENDING) {
// WriteFile failed, but isn't delayed. Report error and abort.
fRes = FALSE;
}
}
Here data should be included inside lpBuf. It is a buffer.
I want to assign "MINC,moveL" . Here MINC are text. however, moveL is variable which the type should be double. values should be passed to moveL with the time. moveL is varying from 0~10 000.
So how do I fill the buffer?
It sounds like you want sprintf (or one of its cousins):
char buffer[128];
sprintf(buffer, "MINC,%f", moveL);
WriteFile(hComm, buffer, ...);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With