|
RR Unstable During Tab Calls JHao from United States [10 posts] |
7 year
|
Hi,
I created a RR script (including one Main and four Tabs) to process several images. Then I call RR API from my C# code. If I debug my code (set one break point in each image processing), everything works fine. However if I remove the debug and run my code, my program hangs. Then I set sleep point in my code and it seems getting better (the frequency of hanging reduced significantly), but not completely fix the problem. I am using Ver. 2.83.23. Here is a sample of my code.
*****************************************************************
...
_roboRealmServer.SetVariable("TabType", "Fiducial");
Thread.Sleep(100);
_roboRealmServer.LoadImage("", imageFile);
_roboRealmServer.WaitImageFor(3000);
Thread.Sleep(200);
string fiducialPointCountStr = _roboRealmServer.GetVariable("CIRCLES_COUNT");
...
*****************************************************************
|
|
|
Steven Gentner from United States [1446 posts] |
7 year
|
JHao,
Can you share the robofile with us too? There doesn't appear to be any issues with the code you posted in that it should not create a lockup so perhaps the issue is the interaction between the CSharp code and the robofile.
Note, you may want to download the lastest version just in case the recent API fixes were not in the version you have.
Finally, watch which thread you are using the CSharp to run this code. We have found that creating and COM object is a different thread than the one you run this code in can cause issues. Its not apparent in the CSharp example that we have since that uses a very simple framework environment. So if you notice the code getting stuck try doing the
RR_COM_APILib.API_Wrapper _roboRealmServer = new API_Wrapper();
just before the
_roboRealmServer.SetVariable("TabType", "Fiducial");
and see if that helps.
It can be easier to debug these issues if you open up RR and go to the Options Api tab and watch the messages come into the app as you run your code. That can help you understand which line it is that is causing the lockup.
STeven.
|
|
|
JHao from United States [10 posts] |
7 year
|
Hi STeven,
Attached is a screen shot of my script file. When I set TabType, I checked "Set Once" box. I can e-mail you my entire script file.
There are two possible reasons why my code is stuck
1. The variable "CIRCCLES_COUNT" is not available when I call it. I suspect this is why it helps when I put a sleep before I make the following call.
string fiducialPointCountStr = _roboRealmServer.GetVariable("CIRCLES_COUNT");
2. I have two Tabs to process circles. I don't know how to clear the variables. The leftover of first "CIRCLES" may interfere variables of the second "CIRCLES". This might be the reason why sometimes I see the contents of CIRCLES is not a multiple of 13.
For me, when unexpected things happen, I would like to deal it with Exception in my code. The last thing I want to see is the code is stuck. Do you throw an exception in dll when the code is stuck? If that is the case, I can switch to "dll".
By the way, sometimes I see the pop-up Message Box from RR. See attachment.
Thanks,
|
|
|
Steven Gentner from United States [1446 posts] |
7 year
|
JHao,
Unfortunately neither of those reasons will cause a lockup. If a variable does not exist and a query is made for its value a zero or empty string will simply be returned. Likewise, when a second instance of a module accesses the same variable, it is simply overwritten with the new values. The second instance will NOT read the current variable and append values to it .. it will just overwrite it. Which is why using the Set_Variable module to rename a variable inbetween two similar modules is a common trick to preserve the value.
The real reason is indicated in your second image or the one indicating that the pipeline is taking too long. This can either be caused by a faulty or slow hardware device (are you interfacing with anything) or can be a situation caused by the API making a query that has actually locked up the pipeline and the GUI is responding to that error.
Unfortunately, since many languages use the COM object we can't use exceptions since that's not handled very well in many languages. The full XML protocol is available for you to use yourself ... but as that has grown quite large that can be an ordeal to program directly in CSharp.
If you could post your robofile here and confirm that you CSharp code is the same as you have it at the top of this post we can investigate further. Also are you still using version 2.83.23 or have you tried upgrading to a later version?
STeven.
|
|
|
JHao from United States [10 posts] |
7 year
|
Hi STeven,
I am not allowed to post our RR file for commercial application in the public domain but can send it to you by e-mail. Could you send me your e-mail address?
In order to simplify the problem and understand the stability of RR. I just wrote a RR script (see attachment) with one RR module of "Set_Variable" and then call RR script from C# code (see attachment, VS2015). In my C# program, I just create 300 loops and call RR in each loop. My image size is about 5 MB. My output file show the response time of each call with RR (see attachment). Most of the time, RR works well but once a while it does take a lot of time. See excerpted output below. Also if I include "API_Wrapper rrServer = new API_Wrapper();" inside the for loop, the program just hangs.
Please be noted that this periodically slow down issue happens not in my computer, it also happens in our development machine where I installed my RR script. The possibility of hardware issue is very slim. I am still use ver. 2.83.23.
Your help is highly appreciated.
****************************************************
i = 54;Hello World
Time elasped to GetVariable Hello: 0.9984 milliseconds
C:\Users\jhao\Documents\CSharpTest\RRStableTest\Image__2017-04-24__14-06-00 EH 22514 us.bmp
Time elasped to GetVariable imagePath: 0.6232 milliseconds
Time elasped to complete Run Stop command: 0.5043 milliseconds
Time elasped to complete Run Start command: 0.9032 milliseconds
Time elasped to complete LoadProgram command: 6805.9252 milliseconds
Time elasped to complete LoadImage command: 99.6884 milliseconds
Time elasped to complete pipeline: 56.9333 milliseconds
i = 69;Hello World
Time elasped to GetVariable Hello: 0.0729 milliseconds
C:\Users\jhao\Documents\CSharpTest\RRStableTest\ImageAD back__2017-05-11__11-02-29 20k us.bmp
Time elasped to GetVariable imagePath: 0.0685 milliseconds
Time elasped to complete Run Stop command: 0.0601 milliseconds
Time elasped to complete Run Start command: 8.2638 milliseconds
Time elasped to complete LoadProgram command: 10015.9093 milliseconds
Time elasped to complete LoadImage command: 99.928 milliseconds
Time elasped to complete pipeline: 79.4028 milliseconds
i = 128;Hello World
Time elasped to GetVariable Hello: 0.3446 milliseconds
C:\Users\jhao\Documents\CSharpTest\RRStableTest\Image__2017-04-24__14-06-00 EH 22514 us.bmp
Time elasped to GetVariable imagePath: 0.3453 milliseconds
Time elasped to complete Run Stop command: 0.3354 milliseconds
Time elasped to complete Run Start command: 1.2157 milliseconds
Time elasped to complete LoadProgram command: 6907.1726 milliseconds
Time elasped to complete LoadImage command: 100.0797 milliseconds
Time elasped to complete pipeline: 87.9117 milliseconds
i = 282;Hello World
Time elasped to GetVariable Hello: 0.4124 milliseconds
C:\Users\jhao\Documents\CSharpTest\RRStableTest\Image__2017-04-24__14-06-00 EH 22514 us.bmp
Time elasped to GetVariable imagePath: 0.3675 milliseconds
Time elasped to complete Run Stop command: 0.3245 milliseconds
Time elasped to complete Run Start command: 1.3175 milliseconds
Time elasped to complete LoadProgram command: 6901.1163 milliseconds
Time elasped to complete LoadImage command: 99.7537 milliseconds
Time elasped to complete pipeline: 102.4769 milliseconds
*************************************************
|
|
|
JHao from United States [10 posts] |
7 year
|
Unable to attach the code. Here is a copy of my C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RR_COM_APILib;
using System.Diagnostics;
using System.Threading;
namespace RRStableTest
{
class Program
{
private const int VARIANT_TRUE = -1;
private const int VARIANT_FALSE = 0;
static void Main(string[] args)
{
TestRRExample();
}
static void OneLineCommunicationTest()
{
int testNumber = 300;
int sleepTime = 200;
string rrStartCommand = "on";
string rrStopCommand = "off";
Stopwatch stopWatch = new Stopwatch();
API_Wrapper rrServer = new API_Wrapper();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < testNumber; i++)
{
stopWatch.Restart();
//API_Wrapper rrServer = new API_Wrapper();
if (rrServer.Startup() == VARIANT_TRUE)
{
rrServer.Run(rrStartCommand);
string rrMessage =$"Time elasped to complete Run Start command: {stopWatch.Elapsed.TotalMilliseconds} milliseconds";
Console.WriteLine(rrMessage);
sb.Append(rrMessage + "\r\n");
stopWatch.Restart();
rrServer.LoadProgram(@"C:\Users\jhao\Documents\CSharpTest\RRStableTest\BasicRR.robo");
rrMessage = $"Time elasped to complete LoadProgram command: {stopWatch.Elapsed.TotalMilliseconds} milliseconds";
Console.WriteLine(rrMessage);
sb.Append(rrMessage + "\r\n");
stopWatch.Restart();
if (i % 2 == 0)
{
rrServer.LoadImage("",
@"C:\Users\jhao\Documents\CSharpTest\RRStableTest\Image__2017-04-24__14-06-00 EH 22514 us.bmp");
}
else
{
rrServer.LoadImage("",
@"C:\Users\jhao\Documents\CSharpTest\RRStableTest\ImageAD back__2017-05-11__11-02-29 20k us.bmp");
}
rrMessage = $"Time elasped to complete LoadImage command: {stopWatch.Elapsed.TotalMilliseconds} milliseconds";
Console.WriteLine(rrMessage);
sb.Append(rrMessage + "\r\n");
stopWatch.Restart();
rrServer.WaitImageFor(3000);
rrMessage = $"Time elasped to complete pipeline: {stopWatch.Elapsed.TotalMilliseconds} milliseconds";
Console.WriteLine(rrMessage);
sb.Append(rrMessage + "\r\n");
stopWatch.Restart();
string result = rrServer.GetVariable("Hello");
rrMessage = $"Time elasped to GetVariable Hello: {stopWatch.Elapsed.TotalMilliseconds} milliseconds";
result = "i = " + i + ";" + result;
Console.WriteLine(result);
Console.WriteLine(rrMessage);
sb.Append(result + "\r\n");
sb.Append(rrMessage + "\r\n");
stopWatch.Restart();
string imagePath = rrServer.GetVariable("IMAGE_PATH");
rrMessage = $"Time elasped to GetVariable imagePath: {stopWatch.Elapsed.TotalMilliseconds} milliseconds";
Console.WriteLine("ImagePath = " + imagePath);
Console.WriteLine(rrMessage);
sb.Append(imagePath + "\r\n");
sb.Append(rrMessage + "\r\n");
stopWatch.Restart();
rrServer.Run(rrStopCommand);
rrMessage = $"Time elasped to complete Run Stop command: {stopWatch.Elapsed.TotalMilliseconds} milliseconds";
Console.WriteLine(rrMessage);
sb.Append(rrMessage + "\r\n");
}
else
{
string message = "i = " + i + "; Can not start RR";
Console.WriteLine(message);
sb.Append(message + "\r\n");
}
/*
stopWatch.Stop();
string elapsedTime = "Time Elasped: " + stopWatch.Elapsed.TotalMilliseconds;
Console.WriteLine(elapsedTime);
sb.Append(elapsedTime + "\r\n");
*/
Thread.Sleep(sleepTime);
Console.WriteLine("Sleep for " + sleepTime);
}
string fileName = @"C:\Users\jhao\Documents\CSharpTest\RRStableTest" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") +".txt";
using (System.IO.StreamWriter myStream = new System.IO.StreamWriter(fileName))
myStream.Write(sb);
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
static void TestRRExample()
{
int testNumber = 300;
int sleepTime = 200;
string rrStartCommand = "on";
string rrStopCommand = "off";
Stopwatch stopWatch = new Stopwatch();
API_Wrapper rrServer = new API_Wrapper();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < testNumber; i++)
{
stopWatch.Restart();
//API_Wrapper rrServer = new API_Wrapper();
if (rrServer.Startup() == VARIANT_TRUE)
{
rrServer.Run(rrStartCommand);
string rrMessage = $"Time elasped to complete Run Start command: {stopWatch.Elapsed.TotalMilliseconds} milliseconds";
Console.WriteLine(rrMessage);
sb.Append(rrMessage + "\r\n");
stopWatch.Restart();
if (i % 2 == 0)
{
rrServer.LoadProgram(@"C:\Users\jhao\Documents\CSharpTest\RRStableTest\Count_Colors.robo");
}
else
{
rrServer.LoadProgram(@"C:\Users\jhao\Documents\CSharpTest\RRStableTest\Count_Circles.robo");
}
rrMessage = $"Time elasped to complete LoadProgram command: {stopWatch.Elapsed.TotalMilliseconds} milliseconds";
Console.WriteLine(rrMessage);
sb.Append(rrMessage + "\r\n");
stopWatch.Restart();
rrServer.LoadImage("",@"C:\Users\jhao\Documents\CSharpTest\RRStableTest\Counting_Objects.jpg");
rrMessage = $"Time elasped to complete LoadImage command: {stopWatch.Elapsed.TotalMilliseconds} milliseconds";
Console.WriteLine(rrMessage);
sb.Append(rrMessage + "\r\n");
stopWatch.Restart();
rrServer.WaitImageFor(3000);
rrMessage = $"Time elasped to complete pipeline: {stopWatch.Elapsed.TotalMilliseconds} milliseconds";
Console.WriteLine(rrMessage);
sb.Append(rrMessage + "\r\n");
stopWatch.Restart();
string result = rrServer.GetVariable("Yellow");
rrMessage = $"Time elasped to GetVariable Yellow: {stopWatch.Elapsed.TotalMilliseconds} milliseconds";
result = "i = " + i + ";" + result;
Console.WriteLine(result);
Console.WriteLine(rrMessage);
sb.Append(result + "\r\n");
sb.Append(rrMessage + "\r\n");
stopWatch.Restart();
string imagePath = rrServer.GetVariable("IMAGE_PATH");
rrMessage = $"Time elasped to GetVariable imagePath: {stopWatch.Elapsed.TotalMilliseconds} milliseconds";
Console.WriteLine("ImagePath = " + imagePath);
Console.WriteLine(rrMessage);
sb.Append(imagePath + "\r\n");
sb.Append(rrMessage + "\r\n");
stopWatch.Restart();
rrServer.Run(rrStopCommand);
rrMessage = $"Time elasped to complete Run Stop command: {stopWatch.Elapsed.TotalMilliseconds} milliseconds";
Console.WriteLine(rrMessage);
sb.Append(rrMessage + "\r\n");
}
else
{
string message = "i = " + i + "; Can not start RR";
Console.WriteLine(message);
sb.Append(message + "\r\n");
}
/*
stopWatch.Stop();
string elapsedTime = "Time Elasped: " + stopWatch.Elapsed.TotalMilliseconds;
Console.WriteLine(elapsedTime);
sb.Append(elapsedTime + "\r\n");
*/
Thread.Sleep(sleepTime);
Console.WriteLine("Sleep for " + sleepTime);
}
string fileName = @"C:\Users\jhao\Documents\CSharpTest\RRStableTest\RRExample" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".txt";
using (System.IO.StreamWriter myStream = new System.IO.StreamWriter(fileName))
myStream.Write(sb);
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
}
|
|
|
Steven Gentner from United States [1446 posts] |
7 year
|
JHao,
Thanks for your CSharp code. That was helpful to test the system in a specific way. There was an issue with blank variables. As it turns out, my earlier statement was WRONG and the missing of a variable was causing the COM object to wait. The COM object was incorrectly upgraded in the last release not to handle an absent variable correctly. This has now been fixed in RR to avoid that case. If you download the latest version that should function better.
Also, you should move the RR.Startup() out of the inner loop since you only want to do this once. Same with the Wrapper object, only create that once and then use accordingly. Things will loop a little faster with that out of the loop.
After this update your test loop runs fine for 300 iterations. Let me know if you still run into any inconsistencies.
Thanks,
STeven.
|
|
|
JHao from United States [10 posts] |
7 year
|
Hi STeven,
I did as you suggested: download new RR (ver. 2.86.3) and move RR.Startup() outside the for loop. However, the periodical slow down problem still exists. It is consistent with what I experienced before: most of time RR works well but from time to time it does slow down. The following is the excerpted output. See attached file for details.
Thanks
**********************************************************************
...
i = 201;Hello World
Time elasped to GetVariable Hello: 0.1958 milliseconds
C:\Users\jhao\Documents\CSharpTest\RRStableTest\ImageAD back__2017-05-11__11-02-29 20k us.bmp
Time elasped to GetVariable imagePath: 0.1436 milliseconds
Time elasped to complete Run Stop command: 0.6939 milliseconds
Time elasped to complete Run Start command: 0.8124 milliseconds
Time elasped to complete LoadProgram command: 99.4108 milliseconds
Time elasped to complete LoadImage command: 9998.193 milliseconds
Time elasped to complete pipeline: 20.9961 milliseconds
...
i = 284;Hello World
Time elasped to GetVariable Hello: 0.2928 milliseconds
C:\Users\jhao\Documents\CSharpTest\RRStableTest\Image__2017-04-24__14-06-00 EH 22514 us.bmp
Time elasped to GetVariable imagePath: 0.2931 milliseconds
Time elasped to complete Run Stop command: 0.1393 milliseconds
Time elasped to complete Run Start command: 0.2775 milliseconds
Time elasped to complete LoadProgram command: 10016.5786 milliseconds
Time elasped to complete LoadImage command: 102.4503 milliseconds
Time elasped to complete pipeline: 87.2227 milliseconds
********************************************************
|
|