Join us today!

Notifications
Clear all

twincat string

2 Posts
2 Users
0 Likes
364 Views
Posts: 3
Topic starter
(@sarunas-z)
Active Member
Joined: 11 months ago

Hello, I have variable code:

FOR n:=1 TO 255 DO
CONCAT2(pSrcString1:=ADR(GlobalPersistent.ReadAllEvents[n].sDate),pSrcString2:=ADR(GlobalPersistent.ReadAllEvents[n].STime),pDstString:=ADR(GVariable.WriteToFileString[n]),nDstSize:=255);
formatStrg:='%s,%s,%s,%s';
FBFormatString(sFormat:=FormatStrg, arg1:=F_STRING(GlobalPersistent.ReadAllEvents[n].sDate),
arg2:=F_STRING(GlobalPersistent.ReadAllEvents[n].STime),
arg3:=F_STRING(GlobalPersistent.ReadAllEvents[n].sSource),
arg4:=F_STRING(GlobalPersistent.ReadAllEvents[n].sMessageText),
sOut=>GVariable.WriteToFileString[n]);
END_FOR

I string write to array, when this Array I write to txt file

fbFileWrite( bExecute := FALSE );
fbFileWrite( sNetId:=sDestNetId, hFile:=hDestFile,
pWriteBuff:= ADR(GVariable.WriteToFileString), cbWriteLen:= SIZEOF(GVariable.WriteToFileString),
bExecute:=TRUE, tTimeout:=tTimeOut );

I open create file and see this

logtext.jpg

how solve problem don't show a lot of NULL

Reply
1 Reply
kolyur
Posts: 12
(@kolyur)
Active Member
Joined: 2 years ago

I would guess the problem is how you are executing fbFileWrite. If this is cyclical ST code, you shouldn't execute the function block twice in the same scan. Your code is continually toggling the bExecute bit which could explain the result you're seeing. A common practice is to monitor the bBusy bit after executing fbFileWrite with bExecute:=true. It isn't necessary to turn off bExecute until the busy bit goes false.

Reply
Share: