Re: Serial Communication in Visual C++
- From: "Ryan Neuhart" <ryan@xxxxxxxxxx>
- Date: Tue, 10 Oct 2006 17:42:50 -0700
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
"Eric Hill" <eric@xxxxxxxxx> wrote in message
news:op.tg73utxhsqk0wa@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Ok, here's the whole function for initializing the comm port....
But that doesn't show where you write to the port at all. Do you write
multiple times? Do you write a command and wait for a response? Are you
writing commands based on a timer event? Mouse click? Button press?
Other?
If the initialization takes a second or two, I don't see a problem with
that. You only initialize once when you start your app up, right?
Eric
.
- Follow-Ups:
- Re: Serial Communication in Visual C++
- From: Ben Voigt
- Re: Serial Communication in Visual C++
- From: Scott McPhillips [MVP]
- Re: Serial Communication in Visual C++
- From: Duane Hebert
- Re: Serial Communication in Visual C++
- 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
- Serial Communication in Visual C++
- Prev by Date: Re: Serial Communication in Visual C++
- Next by Date: Transparent
- Previous by thread: Re: Serial Communication in Visual C++
- Next by thread: Re: Serial Communication in Visual C++
- Index(es):