Intercom

Intercom is the heart of automating CC2, but to fully utilize its power, you need to at least learn the basics of macro programming. How intercom works is by sending and receiving data in the form of strings. You have the added data of receiving a number from CC2. You send a number to CC2 as well but CC2 uses this number to determine what macro to run.

When CC2 receives data from your program it takes the number you sent and concatenates the letters RCV in front of your number. This new string, “RCV###” is the name of the macro CC2 will run in response to you sending it data. The string you sent is now inside of a special variable that CC2 has set aside for this purpose, RCVDATA.

The more specialized the macro though, the less we can reuse it in our different projects. So, what we want to do is create a generic macro that we can use in every instance we need it. This is a lot simpler that what you may think because of the way CC2 deals with variables within macros.

CC2 does not type variables so it makes no assumptions on what is inside this variable, including the text for an entire macro! This means that our generic macro need only be one line long yet do everything we want it to. Here it is:


MACRO RCV30000
RCVDATA
ENDM

Note: The ‘ReadMe’ file that comes in the C intercom zip file discusses the naming of intercom macros and suggests that we use no number less than 10,000, so we will use 30,000.

Now that we’ve taken care of the CC2 side of things, lets jump into the VB side. We will be using the VBIntercom DLL. This can be called from any programming language that can call a standard C type DLL. If you are programming in C/C++ I suggest you use the code in the C Intercom zip file.

There are five commands within the DLL:

  1. IcInit – Sets up the communication between CC2 and your program
  2. IcGetMsg – Retrieves the message from CC2
  3. IcSendMsg – Sends a message to CC2
  4. IcBusyStatus – Sets a busy flag to tell CC2 your program is busy
  5. IcEnd – Closes the communication link with CC2 and cleans up for windows.

To access these commands from VB, you first declare them like this:

  • Private Declare Function icInit Lib "intercom.dll" (hwnd As Long) As 
          Long
          
  • Private Declare Function icGetMsg Lib "intercom.dll" (cmd As Long, ByVal pdest As String) As Long
  • Private Declare Function icSendMsg Lib "intercom.dll" (ByVal cmd As Long, ByVal pdest As String) As Long
  • Private Declare Function icBusyStatus Lib "intercom.dll" (status As Boolean) As Long
  • Private Declare Function icEnd Lib "intercom.dll" () As Long

The small Visual Basic program included in the zip file at the bottom of this page is a fully functional intercom application. It sends the text in the edit box to our generic macro and then hides itself. When the macro finished it sends a message back to our application. When our application receives the message, it shows itself again and allows the user to send a different set of commands or close down the application.

To demonstrate the power of the macro code, we can send to CC2, I’ve written a little macro (see below) that will draw a diamond in CC2 after the user selects a point. I do no processing of the string that I send or the data returned to us from CC2. That is left for you to create in your own application.

Diamond macro code:

GP p1 ^DSelect Point for Diamond
GETX px p1
GETY py p1
PATH px,py-15 px+10,py px,py+15 px-10,py px,py-15       
      
SENDM 1 done

(Yes I could have just added this macro code into CC2s .MAC file, but this would not have shown the power of intercom.)


 Read Previous Lesson


Download the Visual Basic program and code for "Diamond.exe".