RobotStudio event

sending more than 80 characters at a time

Options
Hello,I have to send a message with socketSend to a tcp server in python. I create my string so that I can read it in JSON.All of this is working correctly, but my message is too long for a string.So i want to know if ther is another way to do it or a way to up the number of characteres in the send function. 

Thanks and here a part of my code
string_to_send:=("{"+ByteToStr(34\Char)+"status"+ByteToStr(34\Char)+": "+ByteToStr(34\Char)+"rec_pos"+ByteToStr(34\Char)+ByteToStr(34\Char)+"name"+ByteToStr(34\Char)+" :"+name+ByteToStr(34\Char)+"x"+ByteToStr(34\Char)+" :"+numToStr(tooltempo.tframe.trans.x,3)+ByteToStr(34\Char)+"y"+ByteToStr(34\Char)+" :"+numToStr(tooltempo.tframe.trans.y,3)+ByteToStr(34\Char)+"z"+ByteToStr(34\Char)+" :"+numToStr(tooltempo.tframe.trans.z,3)+"}");

SocketSend my_socket\Str:=string_to_send;

Answers

  • mandolas
    Options
    Hi...

    You could work with \Data instead of \Str this way you would have 1024 'characters' instead of 80.

    Like this ...

    PROC Send()
            CONST num MAX_BYTE_ARRAY:=1024;
            VAR socketdev mySocketL;
            VAR byte sendByteL{MAX_BYTE_ARRAY};
    
            VAR string strSendL;
    
            
            ! CODE ...
    
            ! .... IF string THEN
            ! If it is a string, it must contain only 80 characters ...
            strSendL:="{"+ByteToStr(34\Char)+"status"+ByteToStr(34\Char)+": "+ByteToStr(34\Char)+"rec_pos"+ByteToStr(34\Char)+ByteToStr(34\Char)+"name"+ByteToStr(34\Char)+" :"+name+ByteToStr(34\Char)+"x"+ByteToStr(34\Char)+" :"+numToStr(tooltempo.tframe.trans.x,3)+ByteToStr(34\Char)+"y"+ByteToStr(34\Char)+" :"+numToStr(tooltempo.tframe.trans.y,3)+ByteToStr(34\Char)+"z"+ByteToStr(34\Char)+" :"+numToStr(tooltempo.tframe.trans.z,3)+"}";
    
            FOR id FROM 1 TO MAX_BYTE_ARRAY DO
                sendByteL{id}:=StrToByte(strSendL\Char);
            ENDFOR
            
            
            ! ... IF Byte THEN
            ! If your string is coming in bytes, you can use it like this ...
            SocketReceive mySocketL\Data:=sendByteL;
    
            ! CODE ...
            SocketSend mySocketL\Data:=sendByteL;
        ENDPROC

    ... I haven't tested it, but maybe it will help.