RobotStudio event

RMQ error- invalide message

I'm trying to send messages to the controller through a c# program. Now, it will work several times and then randomly, a message will become invalid message and the error pops up. I really don't know why. I also emptied the queue every time I send a message, so I don't think it's the problem of queue size. The problem kind of happens randomly, sometime message A is invalid, sometime message B is invalid.

Is there anyway I can check inside what's going on? Or does anyone have any ideas about it?

Thanks a lot!

Comments

  • I attached my RAPID code here: What I'm trying to do is to send a message from c# program to the controller. And the controller will move as the message says. For example, I send "left", then the controller will move to the left by a distance. This will work the first couple of time and then the error appears. Is there anything wrong in my code?

    Thanks a lot!


    MODULE COM_L
        VAR bool flag := FALSE;
        VAR bool clearFlag := FALSE;
        VAR string command;
        VAR intnum endnum;
        VAR intnum connectnum;
        CONST robtarget p11 := [ [600, -100, 800], [1, 0, 0, 0], [0, 0, 0,0], [ 9E9, 9E9, 9E9, 9E9, 9E9, 9E9] ];
    PROC main()
        RMQEmptyQueue;
        CONNECT endnum WITH endCommTrap;
        CONNECT connectnum WITH RABMsgs;
        IRMQMessage flag, connectnum;
        IRMQMessage command, endnum;
        WHILE flag = FALSE DO
            !do something, eg. normal processing...
            IF clearFlag = TRUE THEN
                RMQEmptyQueue;
                clearFlag := FALSE;
            ENDIF
            WaitTime 3;
        ENDWHILE
        !PC SDK message received - do something...
        TPWrite "Message from PC SDK, will now...";
        IDelete connectnum;
        IDelete endnum;
        EXIT;
    ENDPROC

    TRAP endCommTrap
        VAR rmqmessage msg;
        VAR rmqheader header;
        VAR rmqslot rabclient;
        VAR num userdef;
        VAR string ack := "get command";
        VAR robtarget p1;
        VAR robtarget pl;
        VAR robtarget pr;
        VAR robtarget pu;
        VAR robtarget pd;
        VAR string in_com;
        RMQGetMessage msg;
        RMQGetMsgHeader msg \Header:=
        header\SenderId:=rabclient\UserDef:=userdef;
        !check data type and assign value to flag variable
        IF header.datatype = "string" THEN
            RMQGetMsgData msg, in_com;
            !return receipt to sender
            ! RMQSendMessage rabclient, ack;
        ELSE
            TPWrite "Unknown data received in RABMsgs...";
        ENDIF
        
        StopMove;
        StorePath;
        p1 := CRobT();
        IF in_com = "endCom" THEN
            flag := TRUE;
        ELSEIF in_com = "left" THEN
            p1 := CRobT();
            pl := p1;
            pl.trans.x := p1.trans.x + 50;
            MoveL pl, v1000, fine, tool0;
        ELSEIF in_com = "right" THEN
            p1 := CRobT();
            pr := p1;
            pr.trans.x := p1.trans.x - 50;
            MoveL pr, v1000, fine, tool0;
        ELSEIF in_com = "up123" THEN
            p1 := CRobT();
            pu := p1;
            pu.trans.z := p1.trans.z + 50;
            MoveL pu, v1000, fine, tool0;
        ELSEIF in_com = "down" THEN
            p1 := CRobT();
            pd := p1;
            pd.trans.x := p1.trans.x - 50;
            MoveL pd, v1000, fine, tool0;
        ENDIF
        RestoPath;
        StartMove;
        clearFlag := TRUE;
    ENDTRAP
    ENDMODULE
  • Does it matter if you are telling it to move "absolute" to the left, or "relative" to the left? Meaning if you tell it to move relative to the left 2 inches, it will move 2 inches every time you tell it. If you tell it to move absolute to the left 2 inches, it will move to the position that is 2 inches from whatever the origin is defined. Does any of that matter for what you're doing?
  • I had a similar problem just a few days ago.

    In your C# Program, you need to make sure that the IpcMessage object is not one you used before for sending a message.
    Because once you set data vid the SetData() Method, it seems like it also sets the length of the data in there.

    If you reuse the same object again, then the length stays at the maximum size it was used with. The message Queue then expects a message with a certain size, the actual message unfortunately, is smaller than this certain size.

    This would result in the following behaviour:

    string sent by C# program: "string;left" -> works fine, overall length is 11
    string sent by C# program: "string:right" -> works fine, overall length is 12
    string sent by C# program: "string;up123" ->works fine, overall length is 12
    string sent by C# program: "string;left" -> does not work because the overall length of your string is less (11) then the last one (12) you set.

    If you keep your C# program running, and only reset the program pointer on your RAPID program, then restart it and try sending "string;up123" again from the C# program that you left running when the error occured, this message should work, because it has the right size.

    What you could try to do is, in your C# program, whenever you are sending a new message, create a new IpcMessage object.
    If this does not work, make sure all the strings are always the same size.

    Would be great if you'd let me know if this was your problem, but I am fairly certain that this is the reason. :smile: