Re: Serial Communication in Visual C++
- From: Henrik Schmid <HenrikSchmid@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 11 Oct 2006 06:47:02 -0700
"Ryan Neuhart" wrote:
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);
maybe you meant
Sleep(m_nMinCommDelay_ms - (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@xxxxxxxxxx> wrote in message
news:u05rFVM7GHA.4408@xxxxxxxxxxxxxxxxxxxxxxx
"Ryan Neuhart" <ryan@xxxxxxxxxx> wrote in message
news:5oUWg.33628$iA5.24715@xxxxxxxxxxxxx
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?
- References:
- Serial Communication in Visual C++
- From: Ryan Neuhart
- Re: Serial Communication in Visual C++
- From: Carl Daniel [VC++ MVP]
- Re: Serial Communication in Visual C++
- From: Ryan Neuhart
- Re: Serial Communication in Visual C++
- From: Eric Hill
- Re: Serial Communication in Visual C++
- From: Ryan Neuhart
- Re: Serial Communication in Visual C++
- From: Duane Hebert
- Re: Serial Communication in Visual C++
- From: Ryan Neuhart
- Serial Communication in Visual C++
- Prev by Date: Re: Serial Communication in Visual C++
- Next by Date: Re: Position of MS regarding the future C++ Standard
- Previous by thread: Re: Serial Communication in Visual C++
- Next by thread: Re: Serial Communication in Visual C++
- Index(es):