Hello,

We have make a program to log out a rs232 comport,all the data that we read out is in asci. But now on newer version there is also a keep in live string on the rs232 port with that string we keep open the comport to send and receive data( in asci). We also send out a keep in live string for sofar evertyhing works fine. this keep in live string is hex string:
byte[] keepAlive = new byte[] { 0x66, 0x99, 0x06, 0xf9, 0x00, 0x20, 0x00, 0x09, 0x01, 0x02, 0xd4 };

This string we must send out every 2 seconds, and we get back a string like this. this string isn't alway the same. Here come my problem. The text window that show the data show also the string that we get back as answer on the keep inlive string. Not the perfect hex string as above, but convert to asci data but that is normal we program the window to show asci data.

now I like to filter out the hex string (and al this kind of hex data) that i got back from the rs232 so it isn't show in the window so we have a nice text display with data that we can us. so is it posyble to do?????

best regards Erik

Hello,

We have make a program to log out a rs232 comport,all the data that we read out is in asci. But now on newer version there is also a keep in live string on the rs232 port with that string we keep open the comport to send and receive data( in asci). We also send out a keep in live string for sofar evertyhing works fine. this keep in live string is hex string:
byte[] keepAlive = new byte[] { 0x66, 0x99, 0x06, 0xf9, 0x00, 0x20, 0x00, 0x09, 0x01, 0x02, 0xd4 };

This string we must send out every 2 seconds, and we get back a string like this. this string isn't alway the same. Here come my problem. The text window that show the data show also the string that we get back as answer on the keep inlive string. Not the perfect hex string as above, but convert to asci data but that is normal we program the window to show asci data.

now I like to filter out the hex string (and al this kind of hex data) that i got back from the rs232 so it isn't show in the window so we have a nice text display with data that we can us. so is it posyble to do?????

best regards Erik

I think you're looking for this, if I understand your question. I wrote the code here, in the DaniWeb editor, so it might need some tweaking.

Basically all it does is take the string you got from the modem (or whatever) and filters out any control characters (less than ASCII 32), then returns the filtered string.

You may need to add a newline on to the string it returns for formatting.

public string ExtractTextOnly(string myString)
{
    char[] cArray = new char[myString.Length];
    int arrayIdx = 0;

    //iterate through the supplied string and only
    //store the ascii chars >= 32
    for(int x=0; x<myString.Length; x++)
    {
        //pre-set the char element...to avoid garbage
        cArray[x] = (char) 0;

        //add the char if its not a control char
        if( ((int) myString[x]) > 31)
        {
            cArray[arrayIdx] = myString[x];
            arrayIdx++;
        }
    }
   
    //build the string from the array and return it...
    string rtnString = new String(cArray);
    return rtnString;
}

Edited 6 Years Ago by Zinderin: n/a

Hello,

thanks for the answer, with this function we will filter out all the asci below 31 if I understand it right.

I go test it.

The first character in your keep alive string is 0x66. This represents the printable character 'f' and won't be filtered out. Don't know exactly what you are trying to do with your ascii data, but it might be a good idea, not to filter out characters like 0x0d (carriage return).
Good luck.

Hello,

I got a processor that send out 2 type of data 1- in asci format and 2 real hex format.
I measure that with ars232 logger.
We show that data in a window screen and can read normaly the data and can see what kinf of fault code the processor gives.
Now the is a keep inlive strring and get I this in the debug window of my program.
So from my rs232 port to my debugwindowsof my program Imust filter out that data in hex format.

I thought give that option a try of Zinderin and loooks what happend.
below what happend now in the debug window.


f??f???f??f??f???_________________?f???_________________?f???_________________?f???_________________?f???___________

f???
Last Error:
8f???-----------

6f???Res Code Class D?f???ate Time :f??? Startup sec. Deskf???
cription
?f???-----------------Ff???-----------------Ff???-----------------Ff???-----------------Ff???----
?f???19 05 R 1?f???7.02.09 15:08:40 ?f???

Hello,

I got a processor that send out 2 type of data 1- in asci format and 2 real hex format.
I measure that with ars232 logger.
We show that data in a window screen and can read normaly the data and can see what kinf of fault code the processor gives.
Now the is a keep inlive strring and get I this in the debug window of my program.
So from my rs232 port to my debugwindowsof my program Imust filter out that data in hex format.

I thought give that option a try of Zinderin and loooks what happend.
below what happend now in the debug window.


f??f???f??f??f???_________________?f???_________________?f???_________________?f???_________________?f???___________

f???
Last Error:
8f???-----------

6f???Res Code Class D?f???ate Time :f??? Startup sec. Deskf???
cription
?f???-----------------Ff???-----------------Ff???-----------------Ff???-----------------Ff???----
?f???19 05 R 1?f???7.02.09 15:08:40 ?f???

As ddanbe points out, the problem may lie in the fact that my sample code (which was just supposed to get you started) also strips out the carriage returns (ASCII 13).

So you might try changing

...
if( ((int) myString[x]) > 31)
...

to something like

if( (((int) myString[x]) > 31) || (((int) myString[x]) = 13))

You may reach a point with enough conditions on which characters you want to keep/drop that you need to go to SWITCH statements or complex If/If Else clauses.

Its difficult to debug from this side with no live data to test with ... my code was just a suggestion and jumping off point (as all code up here) for you to work with as needed.

Could you post an example of the data sent and data received so we can see what is going back and forth? If we have a clearer idea of the whats being sent and received we may be able to offer a better solution.

Hello,

I'm on the road on this moment and don't have acces to a processors right now.
I come back to it later this week.

best regards Erik

This article has been dead for over six months. Start a new discussion instead.