Sunday, May 1, 2011

A more modern example of Intercom

In the last post, I introduced Intercom with an old example I wrote using VB6.  This post will be a much more modern example using C#.

I’ve also included a “Round Trip” example where the command is initiated via CC3.  By adding this small macro, you now have a command that draws a diamond on the screen.

Code Snippet
  1. MACRO DIAMOND
  2. GP TEMP ^DCenter:
  3. SENDM 2 TEMP
  4. ENDM

What this does is as the user to get a point (GP) and then send it via Intercom to the c# application.

Once it gets to the c# code, it takes the string from CC3 (all data sent from CC3 via Intercom is in strings), splits it on the comma and converts the two substrings into doubles.  Then it creates a command string and passes it back to CC3.

Code Snippet
  1. var strNumbers = System.Text.Encoding.ASCII.GetString(bytMsg).Split(',');
  2. var x = double.Parse(strNumbers[0]);
  3. var y = double.Parse(strNumbers[1]);
  4.  
  5. var strDiamond = "LINE \n" +
  6.                     (x - 100) + "," + y + " \n" +
  7.                     x + "," + (y - 100) + " \n" +
  8.                     (x + 100) + "," + y + " \n" +
  9.                     x + "," + (y + 100) + " \n" +
  10.                     (x - 100) + "," + y + " \n\n" +
  11.                     "ENDM";
  12.  
  13. icSendMsg(20, strDiamond);

Here is a link to the C# portion

No comments:

Post a Comment

Post a Comment