Re: Serial Communication in Visual C++
- From: "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>
- Date: Tue, 10 Oct 2006 20:00:13 -0400
Ryan Neuhart wrote:
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:
OutputVoltage = DesiredRPM * (1/183.9);
sprintf(buf,":CHAN1:VOLT %g",OutputVoltage);
g_SupTalk.Write(buf, strlen(buf));
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();
if (!WriteFile(m_hCommPort, pBuf ,nBytes, &ByteCount, NULL))
return 0;
return ByteCount;
}
So, operating this way, the power supply eventually outputs the proper desired voltage ( = "OutputVoltage"), but there is a serious delay involved. As of now, I am not waiting for any response and am not explicitly setting any flow control (since the power supply documentation said it didn't use any). Also, I am performing this Write fcn each time step (just to re-emphasize).
Thanks for the help.
-Ryan
I don't see any problem that could cause a significant delay. Visual C++ can certainly keep the port busy at 9600 baud, and even higher. It should take about 50 milliseconds to send your 50 char buffer at 9600 baud.
I suggest you analyze the code and timing with OutputDebugString to send strings to the debugger output window at various points. Use GetTickCount to put time references into this output. This should give you a better idea of where the time is being lost. You just might be confused about the timer you are using, or you might be opening/closing the port for each message.
--
Scott McPhillips [VC++ MVP]
.
- 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
- Serial Communication in Visual C++
- Prev by Date: Re: Serial Communication in Visual C++
- Next by Date: Re: Serial Communication in Visual C++
- Previous by thread: Re: Serial Communication in Visual C++
- Next by thread: Re: Serial Communication in Visual C++
- Index(es):
Relevant Pages
|
|