RobotStudio event

PCSDK Messaging Domain


I am having trouble sending messages from an PC SDK application to an IRC5 queue. In order to ensure that I am doing everything right, I have made a small test application that is more or less identical to the messaging example in the PC SDK manual. The IRC5 virtual controller's task has been setup properly according to the manual as well.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ABB.Robotics.Controllers;
using ABB.Robotics.Controllers.Messaging;

namespace MsgTest
{
    class Program
    {
        private static Controller c;
        private static IpcQueue tRob1Queue;
        private static IpcQueue myQueue;
        private static IpcMessage sendMessage;
        private static IpcMessage recMessage;
        static void Main(string[] args)
        {
            //initiation code, eg in constructor
            c = new Controller(Guid.Parse("611d8508-7286-417c-8112-a474fc93b788"));
            //get T_ROB1 queue to send msgs to RAPID task
            tRob1Queue = c.Ipc.GetQueue("RMQ_T_ROB1");
            //create my own PC SDK queue to receive msgs
            if (c.Ipc.Exists("PC_SDK_Q"))
            {
                myQueue = c.Ipc.GetQueue("PC_SDK_Q");
                c.Ipc.DeleteQueue(myQueue.QueueId);
            }
            myQueue = c.Ipc.CreateQueue("PC_SDK_Q", 5, Ipc.IPC_MAXMSGSIZE);
            myQueue = c.Ipc.GetQueue("PC_SDK_Q");

            //Create IpcMessage objects for sending and receiving
            sendMessage = new IpcMessage();
            recMessage = new IpcMessage();

            //in an event handler, eg. button_Click
            SendMessage(true);
            CheckReturnMsg();
        }
        public static void SendMessage(bool boolMsg)
        {
            Byte[] data = null;
            //Create message data
            if (boolMsg)
            {
                data = new UTF8Encoding().GetBytes("bool;TRUE");
            }
            else
            {
                data = new UTF8Encoding().GetBytes("bool;FALSE");
            }
            //Place data and sender information in message
            sendMessage.SetData(data);
            sendMessage.Sender = myQueue.QueueId;
            //Send message to the RAPID queue
            tRob1Queue.Send(sendMessage);
        }

        private static void CheckReturnMsg()
        {
            IpcReturnType ret = IpcReturnType.Timeout;
            string answer = string.Empty;
            int timeout = 5000;
            //Check for msg in the PC SDK queue
            ret = myQueue.Receive(timeout, recMessage);
            if (ret == IpcReturnType.OK)
            {
                //convert msg data to string
                answer = new UTF8Encoding().GetString(recMessage.Data);
                Console.WriteLine(answer);
                //MessageBox should show: string;"Acknowledged"
            }
            else
            {
                Console.WriteLine("Timeout!");
            }
        }
    }
}


However, when trying to send the message, an null reference exception occur with the following stack trace:

Am I doing something wrong?

   at ABB.Robotics.Controllers.SDKBase.UpdateCallContext(Controller controller)
   at ABB.Robotics.Controllers.SDKBase.UpdateCallContext(IController controller)
   at ABB.Robotics.Controllers.Messaging.IpcQueue.Send(Int32 Sender, Int32 Cmd, Int32 UserDef, Int32 UserData, Byte[] Data)
   at ABB.Robotics.Controllers.Messaging.IpcQueue.Send(IpcMessage Message)
   at MsgTest.Program.SendMessage(Boolean boolMsg) in c:users*****documentsvisual studio 2010ProjectsMsgTestMsgTestProgram.cs:line 56
   at MsgTest.Program.Main(String[] args) in c:users*****documentsvisual studio 2010ProjectsMsgTestMsgTestProgram.cs:line 37
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()



John Wiberg2013-03-01 14:07:57

Comments