RAPID Message Queue with PC SDK
I am getting error "A RMQ message was discarded in task T_ROB1. RMQ_T_ROB1 received a RMQ message that couldn't be handled."
What Exactly I am doing wrong here ?
public class Test
What Exactly I am doing wrong here ?
public class Test
{
IpcQueue myQueue;
private IpcQueue tRob1Queue;
private IpcMessage sendMessage;
private IpcMessage recMessage;
public Test()
{
// _Camera.AprilTagCordinatesChanged += DMDecoder_CordinatesChanged;
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[MTAThread]
public void start()
{
NetworkScanner scanner = new NetworkScanner();
scanner.Scan();
System.Threading.Thread.Sleep(2000);
scanner.Scan();
var ControllerInfos = scanner.Controllers;
var ctrl = Controller.Connect(ControllerInfos[0], ConnectionType.Standalone);
ctrl.Logon(UserInfo.DefaultUser);
Console.WriteLine("Controller-System: {0} time is: {1} System ID is: {2}", ctrl.SystemName, ctrl.DateTime, ctrl.SystemId);
Console.WriteLine("Press any key to terminate");
// Get the T_ROB1 queue to send messages to the RAPID task
tRob1Queue = ctrl.Ipc.GetQueue("RMQ_T_ROB1");
// Create my own PC SDK queue to receive messages
if (!ctrl.Ipc.Exists("PC_SDK_Q"))
{
myQueue = ctrl.Ipc.CreateQueue("PC_SDK_Q", 5, Ipc.IPC_MAXMSGSIZE);
}
myQueue = ctrl.Ipc.GetQueue("PC_SDK_Q");
ctrl.EventLog.MessageWritten += EventLogMessageWritten;
recMessage = new IpcMessage();
sendMessage = new IpcMessage();
SendMsgToRapid();
}
static Controller CreateController()
{
try
{
Guid test = new Guid();
NetworkScanner scanner = new NetworkScanner();
Controller controller = new Controller(ControllerFactory.FormatControllerId(new Guid()));
return controller;
}
catch (Exception ex)
{
Console.WriteLine("The specified GUID cannot be found. The robot GUID can be found in the internal directory in the 'system.guid' file. The current sysID is: " );
Console.WriteLine("Press any key to terminate");
Console.ReadKey();
Environment.Exit(1);
}
return null;
}
private void SendMsgToRapid()
{
Thread.Sleep(5000);
try
{
while (true)
{
SendMessage(true);
CheckReturnMsg();
Thread.Sleep(10000); // Send every 10 seconds
}
}
catch (Exception ex)
{
Console.WriteLine($"{ex.Message}");
throw ex; // Rethrow to notify caller
}
}
public 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 void CheckReturnMsg()
{
Thread.Sleep(5000);
IpcReturnType ret = IpcReturnType.Timeout;
string answer = string.Empty;
int timeout = 5000; // 5 seconds timeout
// Check for a message in the PC SDK queue
ret = myQueue.Receive(timeout, recMessage);
if (ret == IpcReturnType.OK)
{
// Convert message data to string
answer = new UTF8Encoding().GetString(recMessage.Data);
Console.WriteLine(answer); // Should show: "Acknowledged"
}
else
{
Console.WriteLine(answer);
}
}
public static void EventLogMessageWritten(object sender, MessageWrittenEventArgs e)
{
if (sender != null && e != null)
{
Console.WriteLine(e.Message.Title);
// Additional code for event logging could be placed here
}
else
{
Console.WriteLine("Null Event Log Message");
}
}
}
}
###Rapid code
MODULE RAB_COMMUNICATION VAR bool flag := FALSE; VAR intnum connectnum; PROC main() CONNECT connectnum WITH RABMsgs; IRMQMessage flag, connectnum; WHILE flag = FALSE DO !do something, eg. normal processing... WaitTime 3; ENDWHILE !PC SDK message received - do something... TPWrite "Message from PC SDK, will now..."; IDelete connectnum; EXIT; ENDPROC TRAP RABMsgs VAR rmqmessage msg; VAR rmqheader header; VAR rmqslot rabclient; VAR num userdef; VAR string ack := "Acknowledged"; RMQGetMessage msg; RMQGetMsgHeader msg \Header:=header \SenderId:=rabclient\UserDef:=userdef; !check data type and assign value to flag variable IF header.datatype = "bool" THEN RMQGetMsgData msg, flag; !return receipt to sender RMQSendMessage rabclient, ack; ELSE TPWrite "Unknown data received in RABMsgs..."; ENDIF ENDTRAP ENDMODULE
0
Categories
- All Categories
- 5.5K RobotStudio
- 397 UpFeed
- 18 Tutorials
- 13 RobotApps
- 299 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 319 IRC5
- 63 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 804 RAPID Programming
- 4 AppStudio
- 3 RobotStudio AR Viewer
- 19 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings