Re: Serial Communication in Visual C++
Hello again,
OutputVoltage is a double. I haven't had any problems with it fitting into
buf. I only need 2 decimal place resolution.
CheckDelay() code is below...
void CheckDelay() {
DWORD tc;
for (tc = GetTickCount();
tc - m_nLastTick < m_nMinCommDelay_ms;
tc = GetTickCount()) {
Sleep(tc - m_nLastTick);
}
m_nLastTick = tc;
}
This function will return zero if the write has failed and ByteCount if
successful. ByteCount will be equal to nBytes if write is successful
(nBytes = strlen(buf) in code).
-Ryan
"Duane Hebert" <spoo@flarn2.com> wrote in message
news:u05rFVM7GHA.4408@TK2MSFTNGP02.phx.gbl...
"Ryan Neuhart" <ryan@bihrle.com> wrote in message
news:5oUWg.33628$iA5.24715@dukeread11...
Right, I only initialize once. Sorry for the confusion on my part. I am
running this through a simulation environment. Initially I had the time
step set to 0.02 sec, but realized that this may be too fast for the
serial connection. However, I get the same result when setting the time
step to as slow as 2.0 secs. Each step I write the following to the
serial port:
I don't see anything obvious, but a couple of questions:
OutputVoltage = DesiredRPM * (1/183.9);
sprintf(buf,":CHAN1:VOLT %g",OutputVoltage);
g_SupTalk.Write(buf, strlen(buf));
What type is OutputVoltage?
If you sprintf() it with %g and no formatting delimiters,
will it fit into buf? At any rate, what type of resolution
are you looking for?
where "buf" has been declared as:
char buf[50];
and g_SupTalk is an instance of the class that is used
and the following is the Write function:
int CCommTalk::Write(const char *pBuf, int nBytes) {
DWORD ByteCount;
CheckDelay();
What does CheckDelay() do?
if (!WriteFile(m_hCommPort, pBuf ,nBytes, &ByteCount, NULL))
return 0;
return ByteCount;
}
Does this function always return a value?
How many bytes?