Re: Serial Communication in Visual C++



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]

.



Relevant Pages

  • [EXPL] TIBCO RendezVous Buffer Overflow (Exploit)
    ... TIB/Rendezvous Routing Communications Daemon (add router buffer ... TIB/Rendezvous Secure Daemon (port 7580) ... char *daemon; ... unsigned int DataOffset; ...
    (Securiteam)
  • [Full-disclosure] Solaris Socket Hijack - solsockjack.c
    ... Hijack Bug ... Solaris has a bug in the use of SO_REUSEADDR in that the Kernel favours any ... a work around could be setting the port numbers that are valuable to ... usage(int argc, char **argv) ...
    (Full-Disclosure)
  • Re: Falcons Device 6 and 7 problem
    ... >>>software and it pays to use HSmodem as well. ... >> to use HS Modem to get higher Baud rate speeds? ... >> accessed a modem port that was not really there. ... The Falcon used the SCC chip and the ST the MFP. ...
    (comp.sys.atari.st)
  • Re: Any BOSS4 Gurus?
    ... > port and not the ... > You also have make sure of the baud rate ... > switches on the ERS board. ... > going in and resetting the dip switches ...
    (alt.machines.cnc)
  • Re: Why is the serial port so slow in Linux?
    ... port, I have connected pins 2 and 3 (the ... to read the serial port. ... integer baud. ... int ascii_loopback; ...
    (comp.os.linux.misc)