Reputation: 31
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?
Upvotes: 3
Views: 4233
Reputation: 48290
Can you use sprintf(lpBuf, "MINC,%lf", moveL);
to create the string?
Be sure to allocate sufficient memory for lpBuf
before you fill it with data.
Upvotes: 1
Reputation: 490108
It sounds like you want sprintf
(or one of its cousins):
char buffer[128];
sprintf(buffer, "MINC,%f", moveL);
WriteFile(hComm, buffer, ...);
Upvotes: 1