Monday, July 30, 2012


About Camera Instructions , VB6 and Camera Quirks                                                                         

There is some confusion about the camera instructions and camera output. Typing commands into Hyperterminal leads to nonsensical output. This is because  the camera takes, and outputs, binary data, not ASCII data. What’s more, the camera documentation would lead you to believe that the commands are in hexadecimal form. All data is binary, which for VB6 at least, is of decimal Byte type. Each byte of data is a decimal from 0 to 255 and corresponds to hexadecimals of 00 to FF.  The documentation uses the hexadecimal format, but VB6 easy converts hex to  decimal by preceding the hex number with “&H”. In VB6, &H1A is the same as using the decimal 26.  Decimal numbers can be changed into hex (in String format) by using the Hex command. Print Hex(26) would print “1A”, and Print Hex(15) would print “F”  (to get back the missing “0”, test for a string length of one and then append the leading “0”).

The other key piece of information you need to know, is when using the Microsoft Comm controls, the way you get binary data in and out of the comm buffers is by using Binary Arrays. In VB6, when the comm control is set to binary mode, a comm buffer can send all (or part) of its data and store it in a Byte Array like this:

Dim InputArray() as Byte
InputArray = Mscomm1.Input

Each of the binary bytes is then individually accessible by instructions like:

                                                  ByteNumberZero = InputArray(0)

The lower bound of the byte array is zero and the upper bound is found with:

Ubound(InputArray).

Camera Command Quirks


When the camera’s Reset command is sent or if the camera is turned off and then on, most of the camera’s settings are retained, but the baud rate returns to it’s default value of 38400. (I suspect the compression rate may be reset as well; it's hard to tell.) Any program trying to communicate with the camera should try to anticipate the baud rate change or communication will be lost.

When a camera Image Size command is sent, it must be followed by a Reset command in order for the image size change to take effect. The Reset may change the baud rate and so you must anticipate that as well.

If camera commands are sent too rapidly in succession, the camera gets confused. 

It sometimes takes many seconds for the camera’s data to accumulate into the Mscomm input buffer. Reading the input buffer too soon causes incomplete reads.

When you exit the program, the camera retains the parameters you were using at the time of exit. It is best to return the camera to some default values before terminating the program so that you can know what state the camera is in when the program starts anew.

I address most of these issues in a set of camera functions I wrote in VB6 and placed in a standard module called SerialCameraFunctions.bas. 

No comments:

Post a Comment