Richard, programming the CM11A is no easy task. I couldn't find any really definitive help on the web. But I was able to piece together enough to finally get the CM11A working like a charm. The following hints should give you a big head start.
There is no such thing as a timing issue.
Please, do not try any tricks to make it work. Some have tried some tricks; e.g. for x = 0 1000000; next -- to get it to respond and produce feedback. Go ahead if you feel like it, but you have been warned. You can get it to halfway work. But you will drive yourself crazy.
Just set up your software correctly using the MsComm Component.
Here are some general guidelines to follow using VB6:
(1) Set your Send Threshhold to 1.
(2) Set your Receive Threshhold to 1.
(3) Set the input mode to Binary instead of Text
(4) Set your settings according to specs: 4800, N, 8, 1
You can set it up with Text Mode. But this bombs on one of the house codes. Just one. But it does bomb.
Initialize the HouseAddress (HouseCode and Device Code) first on the CiM11A using hex code 4 as per the CM11A_protocol.txt.
.ouput = Chr$(&H4) & Chr$("&H" & strHouseCode & strDeviceCode) Both of these variables need to be strings and already converted to Hex$ values.
Read the documentation!
0x04 in binary is 100, this is the value you want to use for initialization. Don't get this confused with sending a Housecode
Initialize the function command first with the following. You'll only want to do this after verifying that the checksums match.
PseudoCode:
Extract CM11a Checksum
Check the sum of the initialization string to see that it matches.
If it matches, initialiize the function wtih the following.
Send a function using Hex$ 6 (binary 110):
.output = chr$(&H6) & chr$(&H0)
Again, don't confuse the 0x06 value with a house code. And you do need the 0x00 in there following the 0x06!
Again, after sending this initialization string, you'll receive another input in the OnCom even: the CM11a responding to the initialiation string. See if you can't stop your program using the debug mode to query the value. After you see a few returns you should see a pattern. Based on your observations, you should be able to write code to deal with the buffer return from the CM11a after the function initialization string.
Preceding the Function call with this output forces the CM11 to respond with a checksum, which you can detect in the OnComm Event and program accordingly before sending your function command:
For example, after you pickup the right checksum from the OnComm Event, then send the command:
.output = Chr$(&h6) & chr$("&H" & strHouseCode & strHouseCommand)
Both variables need to be in Hex$: e. g. the housecode and the HouseCommand ( "2", "3", etc.......)
Check your checkum values. The documentation tells you what to look for.
All checksum values should be detected in the OnComm event. Once you receive a correct checksum in response to the above. Program your code to repsond appropriately.
But how do I get the checksum?
Declare at least 2 variables in the OnComm event to pick up the responses from the CM11:
Dim strBuffer as string, bytereceived() as byte
The second variable is a byte array. You will pick up different bounds on the array depending on what the CM11A sends:
Basically your array will have a boundary with 1 value or more. Use the values produced from the input with 2 values to extract your checksums.
If the boundary of the array has 2 values, extract the first value from the Buffer to obtain the checksum:
For example:
bytereceived() = .input
In essence an OnCom event receives the binary output from the CM11A. This data is transmitted as a binary array. If you want to verify this, you can declare a variant variable and have the input assigned to the variant. And then just use the varType function to find out exactly what type of data your storing.
Dim varReceived as variant
varReceived = .input
debug.print vartype(varReceived)
You should see an output of a number in the 8 or 9000 range. Consult your MSDN documention on the varType function to see exactly what the number means.
bytereceive(0) should be the check sum. You'll have to convert it into a Hex$. It's a binary value that you'll convert to a Hex$ value that you can understand and that corresponds with the documentation of the CM11A protocol.txt
But that's a start. I'm not gong to do all the work for you. I wouldn't want to take away all the fun. But it doesn't seem that many people have gotten past the initial stage of figuring out how to send the basic commands. But this should give you a good head start.
You can do further checks on the byte array boundary count to respond to different situations. But I'll leave that programming to you. But the general principle is to initiate an output, get the feedback from the CM11 in the OnCommEvent and put your code in the OnComm Event to deal with the various input strings you extract from using the mscomm.input value inside the OnComm Event.
And another good hint would be to use the ComEvSend and the ComEvReceive constants that come built in with the MSComm control within the OnComm event. But the ComEvReceive should take care of about 99% of what you want done.
Also, there are a few situations that will pop up when you unplug your CM11A, a radio frequency device has sent a signal to the CM11a (e.g. RR501), etc. Two of the byte values that you'll have to write special code for are "5A" and "A5." Just read the CM11A_protocol.txt. Search for these values, and the documentation should tell you how to respond. All these responses should be dealt with within the OnCom subroutine.
Hank