L
Lasse Madsen
Hi all,
I have an application where i need to receive some data through the C#
seriel port component.
My receive event and uart class which holds the receive buffer etc. looks
like this:
private void seriel_DataReceived( object sender,
System.IO.Ports.SerialDataReceivedEventArgs e )
{
int number_of_bytes = seriel.BytesToRead;
seriel.Read (uart.buffer,uart.rx_wr_index,number_of_bytes);
uart.rx_wr_index += number_of_bytes;
}
class uart
{
static public byte[] buffer = new byte[4096];
static public int rx_wr_index=0;
}
In my application a timer looks at the buffer every 1mS and determines if we
have a "GO / NO GO" situration and asserts a flag correspondantly.
In my application i have a button ... if i press the button i transmit 118
packages of 10 bytes each to another computer over the serial port at 38400
baud ... every time a package is received by the other computer it sends a
"GO / NO GO" response telling me to either try again or proceed with the
next package.
The code could look like this where the go_no_go_flag is updated in the 1mS
timer looking at the buffer...
for ( x = 0 ; x < 118 ; x++ )
{
try_again:
go_no_go_flag = 0;
transmit_pacakge(x); // send the data..
while ( go_no_go_flag == 0 )
{
application.DoEvents();
}
if ( go_no_go_flag == 2 ) // NO GO
goto try_again;
}
My problem is that the data is comming in correctly but the
application.DoEvents(); takes ALOT of time so it slows my application down
In an old DOS program i've written some years ago the entire transmission
took under 1 second but now it takes roughly half a second pr
transmit_package !
What can i do to speed it up?
Best regards
Lasse Madsen
I have an application where i need to receive some data through the C#
seriel port component.
My receive event and uart class which holds the receive buffer etc. looks
like this:
private void seriel_DataReceived( object sender,
System.IO.Ports.SerialDataReceivedEventArgs e )
{
int number_of_bytes = seriel.BytesToRead;
seriel.Read (uart.buffer,uart.rx_wr_index,number_of_bytes);
uart.rx_wr_index += number_of_bytes;
}
class uart
{
static public byte[] buffer = new byte[4096];
static public int rx_wr_index=0;
}
In my application a timer looks at the buffer every 1mS and determines if we
have a "GO / NO GO" situration and asserts a flag correspondantly.
In my application i have a button ... if i press the button i transmit 118
packages of 10 bytes each to another computer over the serial port at 38400
baud ... every time a package is received by the other computer it sends a
"GO / NO GO" response telling me to either try again or proceed with the
next package.
The code could look like this where the go_no_go_flag is updated in the 1mS
timer looking at the buffer...
for ( x = 0 ; x < 118 ; x++ )
{
try_again:
go_no_go_flag = 0;
transmit_pacakge(x); // send the data..
while ( go_no_go_flag == 0 )
{
application.DoEvents();
}
if ( go_no_go_flag == 2 ) // NO GO
goto try_again;
}
My problem is that the data is comming in correctly but the
application.DoEvents(); takes ALOT of time so it slows my application down
In an old DOS program i've written some years ago the entire transmission
took under 1 second but now it takes roughly half a second pr
transmit_package !
What can i do to speed it up?
Best regards
Lasse Madsen