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 RCV30000RCVDATAENDM
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:
To access these commands from VB, you first declare them like this: |
|
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 DiamondGETX px p1GETY py p1PATH px,py-15 px+10,py px,py+15 px-10,py px,py-15SENDM 1 done |