Hello,
Can anyone help me converting a Real number to a string/char array?
Has Kuka any function to do it?
Thank you so much
Regards
Sent from my iPhone using Tapatalk - now Free
Hello,
Can anyone help me converting a Real number to a string/char array?
Has Kuka any function to do it?
Thank you so much
Regards
Sent from my iPhone using Tapatalk - now Free
not sure yet but is there particular range you are interested in? if one is to make own conversion routine, it is much easier if scope of work is limited...
I don't know what do you really need to do, but I think this "discussion" will can help you.
DEF INTtoAscii(Fastener[] : OUT, IOByte: IN)
;FOLD --> Variables
INT IOByte
INT I
CHAR Fastener[]
;ENDFOLD
;FOLD Takes Integer signal and converts to Character
;ENDFOLD
Retry:
switch (IOByte)
case 'H61','H41' ;a or A
I = StrADD(Fastener[],"A");
case 'H62','H42' ;b or B
I = StrADD(Fastener[],"B");
case 'H63','H43' ;c or C
I = StrADD(Fastener[],"C");
case 'H64','H44' ;d or D
I = StrADD(Fastener[],"D");
case 'H65','H45' ;e or E
I = StrADD(Fastener[],"E");
case 'H66','H46' ;f or F
I = StrADD(Fastener[],"F");
case 'H67','H47' ;g or G
I = StrADD(Fastener[],"G");
case 'H68','H48' ;h or H
I = StrADD(Fastener[],"H");
case 'H69','H49' ;i or I
I = StrADD(Fastener[],"I");
case 'H4A','H6A' ;j or J
I = StrADD(Fastener[],"J");
case 'H4B','H6B' ;k or K
I = StrADD(Fastener[],"K");
case 'H4C','H6C' ;l or L
I = StrADD(Fastener[],"L");
case 'H4D','H6D' ;m or M
I = StrADD(Fastener[],"M");
case 'H6E','H4E' ;n or N
I = StrADD(Fastener[],"N");
case 'H6F','H4F' ;o or O
I = StrADD(Fastener[],"O");
case 'H70','H50' ;p or P
I = StrADD(Fastener[],"P");
case 'H71','H51' ;q or Q
I = StrADD(Fastener[],"Q");
case 'H72','H52' ;r or R
I = StrADD(Fastener[],"R");
case 'H73','H53' ;s or S
I = StrADD(Fastener[],"S");
case 'H74','H54' ;t or T
I = StrADD(Fastener[],"T");
case 'H75','H55' ;u or U
I = StrADD(Fastener[],"U");
case 'H76','H56' ;v or V
I = StrADD(Fastener[],"V");
case 'H77','H57' ;w or W
I = StrADD(Fastener[],"W");
case 'H78','H58' ;x or X
I = StrADD(Fastener[],"X");
case 'H79','H59' ;y or Y
I = StrADD(Fastener[],"Y");
case 'H5A','H7A' ;z or Z
I = StrADD(Fastener[],"Z");
Case 'H30'
I = StrADD(Fastener[],"0")
Case 'H31'
I = StrADD(Fastener[],"1")
Case 'H32'
I = StrADD(Fastener[],"2")
Case 'H33'
I = StrADD(Fastener[],"3")
Case 'H34'
I = StrADD(Fastener[],"4")
Case 'H35'
I = StrADD(Fastener[],"5")
Case 'H36'
I = StrADD(Fastener[],"6")
Case 'H37'
I = StrADD(Fastener[],"7")
Case 'H38'
I = StrADD(Fastener[],"8")
Case 'H39'
I = StrADD(Fastener[],"9")
Default
return
ENDSwitch
END
Display More
For converting ascii to int
DEF AsciiToINT(iFastenerDestination[] : OUT)
;Converts 13 Character ASCII Code to binary signal
;FOLD --> Variables
INT iFastenerDestination[]
DECL INT Result
DECL INT i,sLength
;ENDFOLD
sLength = StrLen(CurrentFastener[])
For I = 1 to sLength
iFastenerDestination[i] = GetCharacter(i)
ENDFOR
END
[\code]
[code]
DEFFCT INT GetCharacter(ArrayIndex : IN)
;FOLD --> History
;Program Created by mookie 6/28/08
;7-1-2008 Changed to Return Value in Hex
;ENDFOLD
;FOLD --> Variables
DECL INT ArrayIndex
DECL INT BytePosition
DECL INT Length
;Numeric to ASCII code
;ENDFOLD
;FOLD --> Get Length of String
;ENDFOLD
IF (StrFind(ArrayIndex,CurrentFastener[]," ",#Not_Case_Sens) == 1) then
Return 'H0'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"0",#Not_Case_Sens) == 1) then
Return 'H30'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"1",#Not_Case_Sens) == 1) then
Return 'H31'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"2",#Not_Case_Sens) == 1) then
Return 'H32'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"3",#Not_Case_Sens) == 1) then
Return 'H33'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"4",#Not_Case_Sens) == 1) then
Return 'H34'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"5",#Not_Case_Sens) == 1) then
Return 'H35'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"6",#Not_Case_Sens) == 1) then
Return 'H36'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"7",#Not_Case_Sens) == 1) then
Return 'H37'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"8",#Not_Case_Sens) == 1) then
Return 'H38'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"9",#Not_Case_Sens) == 1) then
Return 'H39'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"A",#Not_Case_Sens) == 1) then
Return 'H41'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"B",#Not_Case_Sens) == 1) then
Return 'H42'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"C",#Not_Case_Sens) == 1) then
Return 'H43'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"D",#Not_Case_Sens) == 1) then
Return 'H44'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"E",#Not_Case_Sens) == 1) then
Return 'H45'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"F",#Not_Case_Sens) == 1) then
Return 'H46'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"G",#Not_Case_Sens) == 1) then
Return 'H47'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"H",#Not_Case_Sens) == 1) then
Return 'H48'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"I",#Not_Case_Sens) == 1) then
Return 'H49'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"J",#Not_Case_Sens) == 1) then
Return 'H4A'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"K",#Not_Case_Sens) == 1) then
Return 'H4B'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"L",#Not_Case_Sens) == 1) then
Return 'H4C'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"M",#Not_Case_Sens) == 1) then
Return 'H4D'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"N",#Not_Case_Sens) == 1) then
Return 'H4E'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"O",#Not_Case_Sens) == 1) then
Return 'H4F'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"P",#Not_Case_Sens) == 1) then
Return 'H50'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"Q",#Not_Case_Sens) == 1) then
Return 'H51'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"R",#Not_Case_Sens) == 1) then
Return 'H52'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"S",#Not_Case_Sens) == 1) then
Return 'H53'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"T",#Not_Case_Sens) == 1) then
Return 'H54'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"U",#Not_Case_Sens) == 1) then
Return 'H55'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"V",#Not_Case_Sens) == 1) then
Return 'H56'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"W",#Not_Case_Sens) == 1) then
Return 'H57'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"X",#Not_Case_Sens) == 1) then
Return 'H58'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"Y",#Not_Case_Sens) == 1) then
Return 'H59'
ENDIF
IF (StrFind(ArrayIndex,CurrentFastener[],"Z",#Not_Case_Sens) == 1) then
Return 'H5A'
ENDIF
ENDFCT
Display More
Wouldn't an SWRITE do the trick? An SWRITE to a blank string with a %f argument should write a Real into a string (char array) in one shot.
Thank you guys, so kind! Tomorrow I'll try
For future reference, the function SWRITE is described in KUKA CREAD/CWRITE documentation. There you can find examples on how to use it as well.
For future reference, the function SWRITE is described in KUKA CREAD/CWRITE documentation. There you can find examples on how to use it as well.
I found that there is a program that contains a KUKA written function that converts from INT to STR with a prefix. Inside of BAS.src, the function isn't declared as a global.
Here's how they did it using SWRITE.
DEFFCT CHAR[128] IntToStrWithPrefix(tVar:IN, bPrefixComma:IN)
DECL INT tVar
DECL CHAR tStr[128]
DECL STATE_T STATE
DECL INT OFFSET
DECL BOOL bPrefixComma
OFFSET = 0
IF bPrefixComma THEN
SWRITE(tStr[],STATE,OFFSET,",%d",tVar)
ELSE
SWRITE(tStr[],STATE,OFFSET,"%d",tVar)
ENDIF
RETURN tStr[]
ENDFCT
Display More
You can make your own func or change BAS.src to define the function as Global
It can be called like this.