how to modify the string through send command.

Forum Home Forums Understanding the Software how to modify the string through send command.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #16203
    38368423
    Participant

    The data type of the output channel is ASCII string, how to modify the string through send command.

    #16204
    manjey73
    Participant

    You need to process CmdDataStr in the output formula

    #16208
    Mikhail
    Moderator

    Add the following function in the Scripts table:

    public byte[] SetStr()
    {
      string s;
    
      if (CmdData == null)
        s = "null";
      else 
        s = Encoding.UTF8.GetString(CmdData);
    
      SetData(CnlNum, EncodeAscii(s), 1);
      return CmdData;
    }

    Set the output formula of the channel to SetStr()
    It works for a channel of the data length = 1 (or empty)

    #16210
    38368423
    Participant

    length of string is great than 24

    #16212
    Mikhail
    Moderator

    The function below takes a data length into account for Unicode strings.

    public byte[] SetUnicode()
    {
      if (ArrIdx == 0)
      {
        string s = CmdData == null ? "null" : Encoding.UTF8.GetString(CmdData);
        int dataSize = Channel.DataLen ?? 1;
    
        for (int i = 0; i < dataSize; i++)
        {
          string part = Substring(s, i * 4, 4);
          SetData(CnlNum + i, EncodeUnicode(part), 1);
        }
      }
    
      return CmdData;
    }
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.