Comparing each Character in a String

Vaitheeswaran

Member
Join Date
May 2019
Location
Madurai
Posts
20
Hello,

We are using Schneider SCADAPack 357 and Trimble Acutime 2000GPS.


We are getting the data as a string(ASCII) from gps(Position) , we need to compare each character in the string till we get the position data.


Eg: The string we are receiving from the gps will be : “$10TGȆuC+tgHëÍ@$10$03”, the third character"T" is the packet sent from the gps, but we need the packet as “,,”( ,, is the packet for position). We have to compare the data till we get “,,”.

Could you Please suggest some ideas or programming sample regarding this.

Thanks and Regards,
Vaitheeswaran
email: [email protected]; [email protected]
Contact: 9698944509
 
Last edited:
Not familiar with either device but I believe that Scada pack is capable of using C or C++, and not sure about your data, however below is a C routine to select a group of characters from a string in C. Before anybody criticises the code this is off the top of my head and any variations in the way the C language is used in Scada Pack may be different and although the code could be condensed it is just to show how it might be done and there is no cleaning up of memory shown. your description on how you want to get/compare the data is not clear but this shows how you can extract data from a string, you may want to extract different parts i.e. latitude and longitude or time separately. Also I believe it is capable of using a type of PLC language and this may also have functions to extract or compare strings or characters.

#include <stdio.h>
#include <string.h>

int main()
{
char DataString[] = "$10grgrgrT22,34,564,673$rty";
char SearchString[] = "T";
Char PosData[] =""
char *ptr = strstr(DataString, SearchString);

if (ptr != NULL) /* found "T" */
{
Int Position[] = ptr; /* This gets the pointer of the "T" in the string */
Position = Positition + 1; /* This increments the pointer to first char
/* after "T" */
substr(DataString, PosData, Position, 14); /* so PosData Contains 14 /*Chars "22,34,564,673" */
}
else /* "T" Not found */
{
/* do something if required */
}

return 0;
}
 
Parky, We are getting the data from the GPS by rxstring block in Isagraf. We receive different packets from it but we need only the Position data packet. I have attached the text file where the data from GPS are typed in it (ASCII_Data.txt), and I also attached the rxstring block(Receive String) from which we get the data from GPS through this block(rxstring.jpg). From the image "msg2" should be called in Structured text and we need to split them into single character and we have to compare it with the ",," as i say in the last mail. Once we get the Position packet(,,) we have to take the next 38 byte ASCII code data and convert it into Real time data, then we have to store it in a Modbus Address. This is our task.

Here we dont know how to split the string and compare the each character with ",,". We are stuck in this.. Could you please help me with this?


Thanks and Regards,
Vaitheeswaran Elango.
email: [email protected]
Contact: +91 9698944509
 
Your description seems to be a bit vague, you quote ",," as packet position, however I have looked at the manual and there are a few types of protocols and they state that the start of the message is $ etc... and the fields are delimited with commas, looking at NMEA 0183 it appears to be as below:
$ Signifies the start of a message.
ID The talker identification is a two letter mnemonic which describes the source of the navigation information. The GP identification signifies a GPS source while GL will signify a GLONASS source. In the event that the information in the sentence is agnostic the ID will be GP.
MSG The message identification is a three letter mnemonic which describes the message content and the number and order of the data fields.
, Commas serve as delimiters for the data fields.
Dn Each message contains multiple data fields (Dn) which are delimited by commas.
* The asterisk serves as a checksum delimiter.
CS The checksum field contains two ASCII characters which indicate the hexadecimal value of the checksum.
[CR][LF] The carriage return [CR] and line feed [LF] combination terminate the message.
These are documented as ASCII
However there are some message formats where the data fields are integer or doubles etc. (the manual is a little confusing maybe translation to English)
Looking at your txt this does not tie up fully with any of your descriptions.
(note: could not open picture file). as there are multiple $ (start of message) and no commas (,) as delimiters I'm still confused. If the message is in ASCII then you only need to look for the start of data and next comma to extract the field and by looping through the string until the end character. How you do it in structured text on that platform I have not used it so could not comment. However once you have split the strings if you need to convert the data from ASCII to real numbers that would be more complex.
To be honest with little knowledge of both these units and without having a play I don't think I can help you anymore best of luck
 

Similar Topics

I’m running a micro 820 to measure a tank level, then turning on equipment at certain levels. I have an analog input (4-20) that I’m storing and...
Replies
10
Views
288
How do you go about implementing, on the M580 PLC, how many days, hours, minutes before a predefine event in the future? The RRTC_DT yields the...
Replies
3
Views
1,819
This is a Citect SCADA question I have Six variables of type REAL (Float) to compare and determine (identify) which variable has the highest...
Replies
4
Views
1,426
I have currently made a logic to read Serial input from a barcode scanner. The situation is that I need to read the barcode from the machine and...
Replies
5
Views
2,043
Hello, Im here to ask all you well learned professionals a few questions which im struggling with. Im a noob and trying to learn all i can. I...
Replies
10
Views
1,830
Back
Top Bottom