 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ram Guest
|
Posted: Mon Jan 09, 2006 10:39 am Post subject: Very Slow communication Init on Windows-98, why? |
|
|
Hi, below is the function that i'm using to init my communication
for COM1, when i run it on my PC (Windows-2000) it's runs very
fast, but when i run the same application on another PC with
Windows-98 it's takes MUCH more time, for the test i wrote a loop
that runs this function 5,000 times over and over again, on my PC
the loop took about 10 seconds, this was the time that it took
it to run ONLY 50 loops on the Windows-98 computer.... (100 times
slower than my PC)
Why does it happen? and how can i fix in my function to make it
run faster on the Win-98 computer? it's important becouse in the
communication protocol that i'm using i should init the com for
each message (i send some bytes with parity and the rest of the
message without parity, so for each message i have to call the
init function 2 times) and it's takes lot of time in the Win-98
computer.
Thanks, here is the function:
int InitCommunication( void )
{
COMMTIMEOUTS read_timeout; // timeout structure
char ComName[30];
HANDLE ComHndl = NULL;
DCB PortDCB; // device control block structure
if ( SystemInfo.ErrorInfo.Status != NO_ERRORS ) // If Error -> Exit
return 0;
if ( SystemInfo.ComInfo.ComHandle ) // If Port already open
{
CloseHandle( SystemInfo.ComInfo.ComHandle ); // Close Port
SystemInfo.ComInfo.ComHandle = NULL; // Reset Port Handle
}
strcpy( ComName, SystemInfo.ComInfo.ComPort ); // Set ComName
ComHndl = CreateFile( ComName, GENERIC_WRITE + GENERIC_READ, 0, NULL, // Open the asked Com Port
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
if ( ComHndl == INVALID_HANDLE_VALUE ) // Check COM Handle
return FAIL;
PortDCB.DCBlength= sizeof( PortDCB ); // Sizeof( DCB )
GetCommState( ComHndl, &PortDCB );
PortDCB.BaudRate = SystemInfo.ComInfo.BaudRate; // Current baud rate
PortDCB.fBinary = true; // Binary mode, no EOF check
PortDCB.fParity = 0; // 0 = Disable Parity Checking
PortDCB.fOutxCtsFlow = 0; // CTS output flow control
PortDCB.fOutxDsrFlow = 0; // DSR output flow control
PortDCB.fDtrControl = DTR_CONTROL_ENABLE; // DTR flow control type
PortDCB.fDsrSensitivity = 0; // DSR sensitivity
PortDCB.fTXContinueOnXoff = 1; // 0; // XOFF continues Tx
PortDCB.fOutX = 0; // XON/XOFF out flow control
PortDCB.fInX = 0; // XON/XOFF in flow control
PortDCB.fErrorChar = 0; // Enable error replacement
PortDCB.fNull = false; // Enable null stripping
PortDCB.fRtsControl = RTS_CONTROL_ENABLE; // RTS flow control
PortDCB.fAbortOnError = 0; // Abort reads/writes on error
PortDCB.ByteSize = 8; // Number of bits/byte, 4-8
PortDCB.Parity = (char)SystemInfo.ComInfo.Parity; // 0-4 = No, Odd, Even, Mark, Space
PortDCB.StopBits = ONESTOPBIT; // 0, 1, 2 = 1, 1.5, 2
PortDCB.XonLim = 50; // Transmit XON threshold
PortDCB.XoffLim = 50; // Transmit XOFF threshold
PortDCB.XonChar = 0; // Tx and Rx XON character
PortDCB.XoffChar = 0; // Tx and Rx XOFF character
PortDCB.ErrorChar = 0; // Error replacement character
PortDCB.EofChar = 0; // End of input character
PortDCB.EvtChar = 0; // Received event character
read_timeout.ReadIntervalTimeout = 0; // Read Interval Timeout
read_timeout.ReadTotalTimeoutMultiplier = 0; // Read Total Timeout Multiplier
read_timeout.ReadTotalTimeoutConstant = SystemInfo.ComInfo.RxTimeout; // Read Total Timeout Constant
read_timeout.WriteTotalTimeoutMultiplier = 0; // Write Total Timeout Multiplier
read_timeout.WriteTotalTimeoutConstant = SystemInfo.ComInfo.TxTimeout; // Write Total Timeout Constant
if ( !SetCommState( ComHndl, &PortDCB ) ) // Configures Com Port
return FAIL; // Return If Fail
if ( !SetCommTimeouts( ComHndl, &read_timeout ) ) // Set Tx & Rx Timeouts
return FAIL;
SystemInfo.ComInfo.ComHandle = ComHndl; // Set Communication Handle
hndl = SystemInfo.ComInfo.ComHandle;
return PASS; // COM Init was successful
}
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Jan 11, 2006 10:37 am Post subject: Re: Very Slow communication Init on Windows-98, why? |
|
|
"Ram" <Ram (AT) NoSpam (DOT) com> wrote
| Quote: | Why does it happen? and how can i fix in my function
to make it run faster on the Win-98 computer?
|
Did you try stepping through the code in the debugger, or run it through a
profiler, to find out where the bottleneck actually is?
Gambit
|
|
| Back to top |
|
 |
Ram Guest
|
Posted: Wed Jan 11, 2006 3:18 pm Post subject: Re: Very Slow communication Init on Windows-98, why? |
|
|
I can't, becouse there is not Builder C++ Compiler installed on
that Win-98 computer, i can only run the Exe file on it....
Ram.
| Quote: | Did you try stepping through the code in the debugger, or run it through a
profiler, to find out where the bottleneck actually is?
Gambit
|
|
|
| Back to top |
|
 |
Ram Guest
|
Posted: Wed Jan 11, 2006 3:21 pm Post subject: Re: Very Slow communication Init on Windows-98, why? |
|
|
On a second thought, mybe I can measure time for each part in
that function, and show the result on the form itself.
"Ram" <Ram (AT) NoSpam (DOT) com> wrote:
| Quote: |
I can't, becouse there is not Builder C++ Compiler installed on
that Win-98 computer, i can only run the Exe file on it....
Ram.
Did you try stepping through the code in the debugger, or run it through a
profiler, to find out where the bottleneck actually is?
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Jan 11, 2006 7:21 pm Post subject: Re: Very Slow communication Init on Windows-98, why? |
|
|
"Ram" <Ram (AT) NoSpam (DOT) com> wrote
| Quote: | I can't, becouse there is not Builder C++ Compiler installed
on that Win-98 computer, i can only run the Exe file on it....
|
Then you will have to put debugging statements directly into your code that
record how long it takes to perform your operations. Use the GetTickCount()
function, ie:
inline DWORD GetElapsed(DWORD Start, DWORD End)
{
return (dwEnd >= dwStart) ? (dwEnd - dwStart) : ((0xFFFFFFFF -
dwStart) + dwEnd);
}
{
DWORD dwStart = ::GetTickCount();.
// do something ...
DWORD dwElapsed = GetElapsed(dwStart, ::GetTickCount());.
// report what the operation was and the elapsed time to perform it
//...
dwStart = ::GetTickCount();.
// do something else ...
dwElapsed = GetElapsed(dwStart, ::GetTickCount());.
// report what the operation was and the elapsed time to perform it
// and so on ...
}
Once you have the elapsed time for your operations, you can report them
somewhere, such as to a text file that the user can then email back to you.
Alternatively, if you use OutputDebugString(), then the user can use
third-party trace tools, such as DebugView from http://www.sysinternals.com,
to view the code's activity in real-time, and then save the detailed log and
send it to you.
Gambit
|
|
| Back to top |
|
 |
Stefan Kvist Guest
|
Posted: Wed Jan 11, 2006 10:01 pm Post subject: Re: Very Slow communication Init on Windows-98, why? |
|
|
"Ram" <Ram (AT) NoSpam (DOT) com> skrev i meddelandet
news:43c24b5a$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
It's important becouse in the
communication protocol that i'm using i should init the com for
each message (i send some bytes with parity and the rest of the
message without parity, so for each message i have to call the
init function 2 times) and it's takes lot of time in the Win-98
computer.
|
A different way to solve the problem is to only initialize the port
once with parity set to 'none'. Then add the parity bit to those
bytes that require it in the software. If you use a lookup table for
the parity it will only cost you a few clock cycles.
Stefan Kvist
|
|
| Back to top |
|
 |
Ram Guest
|
Posted: Thu Jan 12, 2006 7:49 am Post subject: Re: Very Slow communication Init on Windows-98, why? |
|
|
Thanks, based on the function that i showed in my first message,
can you please show me how should i write that?
For transmiting the bytes to the port i'm using something like:
TxBuff[0] = 0xAA;
TxBuff[2] = 0xBB;
TxBuff[3] = 0xCC;
Result = WriteFile( hndl, TxBuff, 3, &written, NULL )
What should i write if i want to transmite the 0xAA with
Parity, and the 0xBB amd the 0xCC without parity?
Thanks.
| Quote: | Then add the parity bit to those
bytes that require it in the software.
Stefan Kvist
|
|
|
| Back to top |
|
 |
Ram Guest
|
Posted: Thu Jan 12, 2006 7:54 am Post subject: Re: Very Slow communication Init on Windows-98, why? |
|
|
Thanks, as I said in my message above this is exactly what I
wanted to try, and as I said I'll just show the timming results
on the Form itself. But first I want to try the sollution that
I got from dot, i'll be happy to see your comments for that
idea also.
Thanks,
Ram.
| Quote: | Once you have the elapsed time for your operations, you can report them
somewhere, such as to a text file that the user can then email back to you.
Alternatively, if you use OutputDebugString(), then the user can use
third-party trace tools, such as DebugView from http://www.sysinternals.com,
to view the code's activity in real-time, and then save the detailed log and
send it to you.
Gambit
|
|
|
| Back to top |
|
 |
Ram Guest
|
Posted: Thu Jan 12, 2006 7:56 am Post subject: Re: Very Slow communication Init on Windows-98, why? |
|
|
Sorry it should be:
TxBuff[0] = 0xAA;
TxBuff[1] = 0xBB;
TxBuff[2] = 0xCC;
Result = WriteFile( hndl, TxBuff, 3, &written, NULL )
|
|
| Back to top |
|
 |
Stefan Kvist Guest
|
Posted: Thu Jan 12, 2006 10:07 pm Post subject: Re: Very Slow communication Init on Windows-98, why? |
|
|
"Ram" <Ram (AT) NoSpam (DOT) com> skrev i meddelandet
news:43c619d9$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
Sorry it should be:
TxBuff[0] = 0xAA;
TxBuff[1] = 0xBB;
TxBuff[2] = 0xCC;
Result = WriteFile( hndl, TxBuff, 3, &written, NULL )
.
.
|
After rereading the original question I realize that I might have been
to quick to suggest this solution.
When you are sending with parity, is that 8 bits plus parity?
If so, then my solution won't work as that would require the
character size to be set to 9 bits.
The solution I suggested only works with 7 bits or less plus parity.
Stefan Kvist
|
|
| Back to top |
|
 |
Ram Guest
|
Posted: Sun Jan 15, 2006 6:18 am Post subject: Re: Very Slow communication Init on Windows-98, why? |
|
|
Hmmmm.... I'm using 8 Bits of data.
So do you say that I must init the port for each message?
(I still have to do the time measuring.....)
Ram.
| Quote: | After rereading the original question I realize that I might have been
to quick to suggest this solution.
When you are sending with parity, is that 8 bits plus parity?
If so, then my solution won't work as that would require the
character size to be set to 9 bits.
The solution I suggested only works with 7 bits or less plus parity.
Stefan Kvist
|
|
|
| Back to top |
|
 |
Stefan Kvist Guest
|
Posted: Mon Jan 16, 2006 5:30 pm Post subject: Re: Very Slow communication Init on Windows-98, why? |
|
|
"Ram" <Ram (AT) NoSpam (DOT) com> skrev i meddelandet
news:43c9f760$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
Hmmmm.... I'm using 8 Bits of data.
So do you say that I must init the port for each message?
|
Yes, unless you can find a way to change the parity setting without
reinitializing the port.
|
|
| Back to top |
|
 |
Ram Guest
|
Posted: Thu Jan 19, 2006 12:23 pm Post subject: Re: Very Slow communication Init on Windows-98, why? |
|
|
Thanks, i'll try to see if i can run only part of the Port Init
function for changing the 'Parity', if i'll have luck it will be
the quick part of the function and not the slow one which i
want to rid of it.
| Quote: | Yes, unless you can find a way to change the parity setting without
reinitializing the port.
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|