String Manipulation
Hi,
I'm creating a RAPID program that communicates thru RS232 with a PC. The PC is gonna send some information that will end with an Enter (
) and I need to extract the string before the "
".
) and I need to extract the string before the "
".
The information sent by the PC is not always going to be the same lenght.
What command should i use to read to the port if I donA't know the lenght of the data?
Which command should i use to search for this characters "
" and extract the data?
" and extract the data?
So far this is what i have to open and read:
VAR iodev puerto;
VAR string stRead
Close puerto;
Open "com1:", puertoBin;
Close puerto;
Open "com1:", puertoBin;
stRead:=ReadStrBin (puerto, ??);
Thank you for your kind support.
Zasil Medina
0
Comments
-
Hi.
I have just written some code that should do exactly what you are looking for. I have only done some limited testing of the code though, but at least it seems to work for delimiters of length 1.
I'm not sure of the performance of the code as it reads 1 character at the time but RS232 isn't terribly fast to begin with so hopefully that wont be a problem.
[CODE] LOCAL FUNC string ReadStrMab(VAR iodev IODevice,string Delim)
VAR string sBuffer:="";
VAR string sBuf:="";
VAR string sChar:="";
VAR string sDelimiter:="A";
VAR num nDelimLength:=1;
IF (Present(Delim)) THEN
sDelimiter:=Delim;
nDelimLength:=StrLen(sDelimiter);
ENDIF
WHILE (sBuf<>sDelimiter) DO
sChar:=ReadStrBin(IODevice,1);
sBuf:=sBuf+sChar;
IF (StrLen(sBuf)>nDelimLength) THEN
sBuffer:=sBuffer+StrPart(sBuf,1,1);
sBuf:=StrPart(sBuf,2,StrLen(sBuf)-1);
ENDIF
ENDWHILE
RETURN sBuffer;
ENDFUNC[/CODE]
If you dont supply your own delimiter A will be used (hex for newline).
0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 801 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings