Home AMX User Forum AMX Technical Discussion

Encode to UTF-8 and then decode to TP.

Hello,

My app takes some user data from a TP keyboard.
I need to store that data in UTF-8 format, and then, show the UTF-8 formatted data on the TP again.

What i'm trying so far is:

1.- Encode the data received from the keyboard to UTF-8.
wcAux = wc_decode(acDataText,WC_FORMAT_TP,1)
scStudyCase.Patient.Name = wc_encode(wcAux,WC_FORMAT_UTF8,1)

2.- Take the encoded data and show it on the TP:
wcAux = wc_decode(acAux,WC_FORMAT_UTF8,1)
                acAux = wc_tp_encode(wcAux)                
                send_command dvTp, "'^UNI-',itoa(anAddressItemData[nAux][4]),',0,',acAux"


But, the text at the TP is in blank.

I've also tried other ways to implement similar tests using _WC and wc_to_char or char_to_wc, but none worked for me.

Thanks for your help!!

Comments

  • ericmedleyericmedley Posts: 4,177
    Are you sure the font you're using on the TP has those chars? Not a good suggestion, but worth a try.
  • viningvining Posts: 4,368
    Here's the function I use for sending utf-8 text, maybe you can find something useful in it. Also make sure you have "Enable _WC Preprocessor (Unicode) checkec in NS Preferences > Netlinx Compiler and make sure you have #INCLUDE 'UnicodeLib.axi' in your module and main.
    DEFINE_FUNCTION fnFB_DoSend_VT(INTEGER iUI_Indx,INTEGER iCHAN,CHAR iStrMSG[]) 
         
         {
         STACK_VAR INTEGER n;
         STACK_VAR INTEGER nTPCount; 
         STACK_VAR INTEGER nLoopStart; 
         STACK_VAR CHAR cUNI_STR_2[MAX_4096];
         STACK_VAR WIDECHAR cUNI_STR_1[MAX_4096];
         
         if(iUI_Indx)
          {
          nTPCount = iUI_Indx;
          nLoopStart = iUI_Indx;
          }
         else
          {
          nTPCount = sSBS.sPlayer.nNum_UIs;
          nLoopStart = 1;
          }
         fnDevMod_DEBUG("'SEND_VT: ',iStrMSG,' :DEBUG<',ITOA(__LINE__),'>'",4);
         if(length_string(iStrMSG))
          {
          cUNI_STR_1 = WC_DECODE(fnStrReplace(iStrMSG,'$; ',', '),WC_FORMAT_UTF8,1); 
          cUNI_STR_2 = WC_ENCODE(cUNI_STR_1,WC_FORMAT_TP,1);
          }
         for(n = nLoopStart; n <= nTPCount; n++)
          {
          if(nUI_ActiveArry[n] == sSBS.sPlayer.nInstance)//means it on this SB & ACTIVE on page
               {
               SWITCH(nUI_TypeArry[n])
                {
                CASE UI_TYPE_iPHONE:
                CASE UI_TYPE_iTOUCH:
                CASE UI_TYPE_iPAD:
                CASE UI_TYPE_G4:
                CASE UI_TYPE_R4:
                CASE UI_TYPE_MIO_DMS:
                 {
                 if(length_string(cUNI_STR_2))
                      {
                      STACK_VAR CHAR cUniSend[MAX_4096];
                      STACK_VAR INTEGER nAppend;
                 
                      cUniSend = cUNI_STR_2;
                 
                      WHILE(LENGTH_STRING(cUniSend))
                       {
                       STACK_VAR CHAR cTMP[UNI_STR_SIZE];
                 
                       if(LENGTH_STRING(cUniSend) > UNI_STR_SIZE)
                        {
                        cTMP = GET_BUFFER_STRING(cUniSend,UNI_STR_SIZE);
                        }
                       else
                        {
                        cTMP = GET_BUFFER_STRING(cUniSend,LENGTH_STRING(cUniSend));
                        }
                       if(nAppend)
                        {
                        SEND_COMMAND dvUI_SBSArry[n],"'^BAU-',ITOA(iCHAN),',0,',cTMP";   //Append Unicode to Modero Panels
                        }
                       else
                        {
                        SEND_COMMAND dvUI_SBSArry[n],"'^UNI-',ITOA(iCHAN),',0,',cTMP";   //Unicode to Modero Panels
                        }
                       fnDevMod_DEBUG("'SEND_COMMAND UNI, APPEND-[',itoa(nAppend),'], CHNL-[',itoa(iCHAN),'], STR-[ ',cTMP,' ] :DEBUG<',ITOA(__LINE__),'>'",4);
                       nAppend++;
                       }
                      }
                 else//we need to clear text fields too, duh!
                      {
                      SEND_COMMAND dvUI_SBSArry[n], "'^TXT-',itoa(iCHAN),',0,',cUNI_STR_2"; 
                      }
                 }
                CASE UI_TYPE_G3:
                     {
                 fnDevMod_DEBUG("'^TXT- TP INDX: ',itoa(n),', CHNL: ',itoa(iCHAN),' :DEBUG<',ITOA(__LINE__),'>'",4);
                 SEND_COMMAND dvUI_SBSArry[n], "'^TXT-',itoa(iCHAN),',0,',iStrMSG"; 
                 }
                CASE UI_TYPE_METKP:
                CASE UI_TYPE_UNKNOWN:
                CASE UI_TYPE_VIRTUAL:
                 {
                 //DO NOTHING
                 }
                }
               }
          }
          
         RETURN;
         }
    
  • MorgoZMorgoZ Posts: 116
    Thanks for your responses,

    finally, the solution was that i was receiving data from the TP input fields in ASCII format, so i just had to decode the ASCII data and encode it in UTF-8.

    The code:
                        wcAux = wc_decode(texto,WC_FORMAT_ASCII,1)
                        acAux = wc_encode(wcAux,WC_FORMAT_UTF8,1)
                        scStudyCaseSearch.Patient.FamilyName = acAux
    

    Then, with the data in UTF-8, i can properly store latin characters and use them in a server-PC's database.

    Salutes!
Sign In or Register to comment.