views:

278

answers:

1

Hi geeks,

I am explaining my full problem. So I am building one GUI for a device connected to my PC using serial port. I am using javacomm apis and eclipse as my tools. For writing data to serial port I am using thread and for reading I will use a thread or EventListener. So now my question is if I am sending any command to serial port then it should respond with some data and I will print those data on the textArea. But my device responds with data with different patters, like some times in paragraphs and sometimes colon separated and sometimes one line and colon separated. Example below

type 1:
line 1 line 1 line 1 line 1 line 1 line 1 line
parameter 1 : value 1
parameter 2 : value 2 
parameter 3 : value 3

type 2:
line 1 line 1 line 1 parameter 4 and value 4 line 1 line 1 line 1 line 1
line 2 parameter 5 : value 5 line 2 line 2 line 2

type 3:
line 1 line 1 line 1 line 1 :
      parameter 6 = value 6
      parameter 7 = value 7

Now when I write different commands on serial port they send data in different formats. So If am going to put the data simply in one textArea, there is no problem. but if i want to put the data in lables like below

parameter 1(in label 1) : value 1 (label 2)
parameter 2(in label 3) : value 2 (label 4)

So to display data like above from serial port data how can I do it? If I am using string functions for checking for colons(:) and equal signs(=) I have to put so many if else echecks or switch cases when any data arrives from serial port. Everytime any output of any commands reaches to pc from remote device it has to pass through lot of switch cases and if-else cases...

I think it needs a better design.. Do anybody has any idea about any design pattern for designing GUI for serial port? Or any type of suggestion is most welcome.....

I know the problem description might have so much compicated. If anybody find difficulty in understanding my weird explanation please ask me I will try to explain my problem better.......

A: 

Maybe regular expressions could do the parsing.

rodrigoap