I am a newbie at Codesys and trying to concatenate some time variables into text, so that I can pass this information to a server via an Ethernet socket.
I am trying to convert this vairable "CurDate" which is an LWORD to a STRING (variable named "Text"). I am then trying to decode each digit into it's ASCII character into an array;
VAR
  CurDate: LWORD;
  Text : STRING;
  Index : INT;
  Var1AT%MB100 : STRING;
  Var2AT%MB100 : BYTE;
  ascii : ARRAY[0..64] OFBYTE;END_VARCurDate:=(DTNow.Year*10000000000)+(DT_Month)+(DT_Day)+(DT_Hour)+(DT_Minute)+(DT_Second); (* this value equals 20130103185505, at the moment *)Text :=STRING(CurDate);FORIndex :=1TOLEN(Text)BY1DO
  Var1 :=MID(Text ,1,Index);
  ascii[Index-1] :=Var2;END_FOR;
I get an Error 4268: Expression expected on the line "Text := STRING(CurDate);", I can't seem to find an "LWORD_TO_STRING()" function??
Any assistance would be greatly appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2013-01-04
Originally created by: 99bobster99
After digging through some manuals, I came up with this solution. It is not pretty but it works (please let me know if there is a more elegant way of doing this);
CurDate:=DT_Year+DT_Month+DT_Day;Â Â Â Â Â Â Â (* CurDate := 20130104 *)CurTime:=DT_Hour+DT_Minute+DT_Second;Â Â Â Â (* CurTime := 92530 *)(*ConverttheLWORDinto2STRINGvariables*)Text1 :=LREAL_TO_STRING(CurDate);Â Â Â Â Â Â Â Â Â Â (* Text1 := "20130104" *)Text2 :=LREAL_TO_STRING(CurTime);Â Â Â Â Â Â Â Â Â Â (* Text2 := "92540" *)IFLEN(Text2)=5THENText2 :=INSERT(Text2,'0',0);Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (* Text2 := "092540" *)END_IF(*FillDataArraywithASCIIcharactersrepresentingtheSTRINGcharacters*)Text3 :=CONCAT(Text1,Text2);Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (* Text3 := "20130104092540" *)FORIndex :=1TOLEN(Text3)BY1DO
  Var1 :=MID(Text3,1,Index);
  Array_DT[Index-1] :=Var2;END_FOR;
Everything works perfectly, I get the ASCII equivalent data in my "Array_DT" array, for each character in "Text3". Any ideas on how to make this code more compact?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Originally created by: 99bobster99
I am a newbie at Codesys and trying to concatenate some time variables into text, so that I can pass this information to a server via an Ethernet socket.
I am trying to convert this vairable "CurDate" which is an LWORD to a STRING (variable named "Text"). I am then trying to decode each digit into it's ASCII character into an array;
I get an Error 4268: Expression expected on the line "Text := STRING(CurDate);", I can't seem to find an "LWORD_TO_STRING()" function??
Any assistance would be greatly appreciated.
Originally created by: 99bobster99
After digging through some manuals, I came up with this solution. It is not pretty but it works (please let me know if there is a more elegant way of doing this);
Everything works perfectly, I get the ASCII equivalent data in my "Array_DT" array, for each character in "Text3". Any ideas on how to make this code more compact?
you can have a look at http://www.oscat.de nice lib