D
Daniel
hi!
I have written an application that reads data from the serial-port
with javax.comm. My problem is that it acts a bit strange.
I can issue several commands to the controller card at the other end
of the serial-kable. One command gives me the event-log. This eventlog
is approx. 4500 bytes long. I have the following code to do the
reading
out.write(key.getBytes("US-ASCII"));
out.write(13); // make the card execute the request.
out.flush();
Thread.currentThread().sleep(initalWaitTime); // let the
//card "catch up"
int a=in.available();
do{
a=in.available();
Thread.currentThread().sleep(50);
}while(a!=in.available());
byte[] retval = new byte[in.available()];
in.read(retval,0,retval.length); // get the data
return retval;
key is the command I send. it is given to me as a string. and I write
the bytes to the card. This seems to be working without problems.
initalWaitTime is the time specified by the caller of this method (it
is private so it's only me, and I have full control over this) for
some commands I get very short responses and the need to wait is very
small. Others (like the eventlog) give long responses and with a
longer wait at first, I got better performance.
in is a BufferedInputSteam
The serial port is set to 38400bps so getting the event log should
take approx 1-2 seconds. depending on length.
With the code given here it takes 8.5 seconds!
While this could be explained with things like "the card doesn't send
data at max-speed" I can live with that time. But of course I am
interested to know if there is anything *I* can do to improve this
time.
Second, this code doesn't get all the data. Which confuses me greatly.
The current eventlog is 240 "items" long. I get items 240-10.
If I download the table with settings 117 "items" long. it works
perfectly.
My questions now are
1. is there anything I can do to improve performance even more?
2. Do I do something really stupid?
3. Any ideas why it reads to little data given the code here? (I can
via hyperterminal verify that the data is infact there and is sent to
me)
A really odd thing is that the eventlog seems to be getting fewer and
fewer "items" (or rows) each time I run the application. Each start
gives me one row less! (start of application).
This code has worked before, but I have made a few changes to it now.
(and no I can not go back, the requested changes were really needed)
In short I'm totally lost as to wy this is not working..
I have written an application that reads data from the serial-port
with javax.comm. My problem is that it acts a bit strange.
I can issue several commands to the controller card at the other end
of the serial-kable. One command gives me the event-log. This eventlog
is approx. 4500 bytes long. I have the following code to do the
reading
out.write(key.getBytes("US-ASCII"));
out.write(13); // make the card execute the request.
out.flush();
Thread.currentThread().sleep(initalWaitTime); // let the
//card "catch up"
int a=in.available();
do{
a=in.available();
Thread.currentThread().sleep(50);
}while(a!=in.available());
byte[] retval = new byte[in.available()];
in.read(retval,0,retval.length); // get the data
return retval;
key is the command I send. it is given to me as a string. and I write
the bytes to the card. This seems to be working without problems.
initalWaitTime is the time specified by the caller of this method (it
is private so it's only me, and I have full control over this) for
some commands I get very short responses and the need to wait is very
small. Others (like the eventlog) give long responses and with a
longer wait at first, I got better performance.
in is a BufferedInputSteam
The serial port is set to 38400bps so getting the event log should
take approx 1-2 seconds. depending on length.
With the code given here it takes 8.5 seconds!
While this could be explained with things like "the card doesn't send
data at max-speed" I can live with that time. But of course I am
interested to know if there is anything *I* can do to improve this
time.
Second, this code doesn't get all the data. Which confuses me greatly.
The current eventlog is 240 "items" long. I get items 240-10.
If I download the table with settings 117 "items" long. it works
perfectly.
My questions now are
1. is there anything I can do to improve performance even more?
2. Do I do something really stupid?
3. Any ideas why it reads to little data given the code here? (I can
via hyperterminal verify that the data is infact there and is sent to
me)
A really odd thing is that the eventlog seems to be getting fewer and
fewer "items" (or rows) each time I run the application. Each start
gives me one row less! (start of application).
This code has worked before, but I have made a few changes to it now.
(and no I can not go back, the requested changes were really needed)
In short I'm totally lost as to wy this is not working..