views:

97

answers:

1

Hi,

I am using a text file to store the serial port output. And now I want to put the contents of the file to an textArea in java. I have created a dedicated thread for file read operation. I need the thread to sleep when there is no data to read and thread should wake up automatically once data available for read in the file. In the thread I am using a while loop and using readLine() method for reading from file. But when data not available when readLine called in while loop the loop exits and thread terminates. Can anybody suggest how to implement this?

+1  A: 

You can use FIFO pipe (man mkfifo) and write the serial port output data to it instead of the file, or both into the FIFO and into the file (man tee).

The reason why the loop exits is, as far as I understand, that you're hitting the end of file.

ivant
thanks for reply...I am using windows platform so cant use mkfifo. Is there anyway i can create fifo file windows?
Surjya Narayana Padhi
If i can explain the exact problem - its like I send command to remote device by writing on serial buffer and the device responds back with the same command + command output + command prompt. But I need to use the data on my GUI so need to remove the same echoed command and the command prompt from response data. If am putting substring check fror the command prompt text It does not print anything on console also... May be due to processing during data read... Can u suggest a better way?
Surjya Narayana Padhi
Why can't you simply open the device in Java? There's RXTX library which works very well with serial ports.
ivant