Application Note PCI DV C-Link Support for the Basler A202k Engineering Design Team, Inc May 2002 Support for the Basler A202k Camera Link camera was added to the PCI DV Software/Driver package in May of 2002. The first version that included this support was v3.2.6.4. This application note describes the specifics of that support. CONFIGURATION FILES There are six configuration files for the A202k camera: basler202k_10f.cfg (10-bit, freerun) basler202k_10l.cfg (10-bit, exsync timing) basler202k_10p.cfg (10-bit, exsync programmable timing) basler202k_8f.cfg (8-bit, freerun) basler202k_8l.cfg (8-bit, exsync timing) basler202k_8p.cfg (8-bit, exsync programmable timing) Choices corresponding to the above configuration files will show up in the camera configuration tool, included with the PCI DV software package. You can choose them from there (when running the pdvshow GUI program for example), directly using initcam. For example: initcam -f basler202k_8f.cfg ================================================================= | IMPORTANT: in 10-bit mode, the data throughput from the A202k | | camera is higher than can be accomodated with a standard 33 | | MHz PCI bus. Choose only 8-bit modes unless the EDT PCI DV | | C-Link interface board is installed in a 66Mhz slot. | ================================================================= The BASLER_202K configuration file constant was added and is meant to be used as an argument to the method_camera_shutter_timing config file directive. The library uses this directive to determine how to set the exposure time when running in freerun and exsync timing modes. If set, the libpdv library subroutine pdv_set_exposure will transmit the necessary serial commands to the camera to set the Timer1 and Timer2 values as appropritate for the given exposure value. The configuration file directive serial_init_baslerf was also added. Its argument should be a double-quoted string containing colon-separated ASCII representations of serial binary commands WITHOUT the framing information. Initcam will add the framing (STX, BCC and ETX) to each command and send the resulting commnand to the camera. For example, to put the Basler A202k camera into freerun mode, the following serial_init directive would be used: serial_init: "c00103" After adding the STX, BCC and ETX, initcam will send the properly framed command bytes to the camera, via pdv_serial_binary_command: 03 c0 01 03 c2 02 Alternately you could just use serial_init and include the STX, BCC and ETX characters; serial_init_baslerf just makes things simpler. Initcam and configuration file directives are discussed in detail in the Camera Configuration guide camconfig.pdf, available on the distribution CD ROM and on our web site at www.edt.com -> Technical -> Documentation. Also see the contents of the specific config file for more examples. CONTROLLING THE CAMERA On Windows NT/2000/XP, the Basler camera configuration tool CameraConfigTool, provided by Basler, can be used to control and configure the camera. Simply copy the clseredt.dll file from the EDT\Pdv directory to your windows System32 directory, then run the CameraConfigTool. On Solaris or Linux, there is no corresponding config/control tool. The EDT camera capture/display applications DV30 (Solaris) and Pdvj (Linux) as well as pdvshow (Windows) do provide some limited control of camera functions (namely exposure), and the configuration files send the necessary commands to the camera to set it into the desired timing mode. But for other operations, such control can only be achieved through low level serial commands (either using the serial_cmd command-line application, or through pdvlib subroutine calls from within an application). SERIAL COMMUNICATIONS FROM THE COMMAND-LINE The EDT utility program serial_cmd can be used to send and receive serial information to and from the Basler A202k camera. The program is described in the PCI DV user's guide, and its usage can be output by invoking it with the -h (help) option. The -x option can be used to send raw binary commands to the A202k camera. However, if you do this you will need to include the STX, BCC and ETX bytes. Because of this, we added a -B option, which handles these framing details, and makes it a little easier to send serial commands to the camera from the command line. With the -B option, serial_cmd will first send out an STX (0x03), then the command bytes, then calculate and send the BCC byte, then send the ETX (0x02). This is analogous to what serial_init_baslerf does in the config file. For example, say you wanted to query the camera's microcontroller version. The Basler command for this is 0x40. The R/W bit (leftmost bit of the 2nd byte) should be 1, and the length (rightmost 7 bits of the 2nd byte) is 3. Therefore you would send it as: serial_cmd -B -i > 40 83 which should come back with something like: resp <06 02 40 03 30 02 03 72 03> BASLER A202K-SPECIFIC PCI DV LIBRARY ROUTINES The convenience routine pdv_set_exposure has been updated to include Basler A202k-specific binary commands to set Timer 1 and Timer 2, so applications can use it in lieu of direct serial commands to control Basler A202k exposure. These subroutines are called by the EDT "take" example program, and GUI applications pdvshow, dv30 and pdvj, allowing the user to control exposure via the sliders in these GUIs. However, since the convenience routines pdv_set_gain and pdv_set_blacklevel are both single channel, they will not work with the A202k which has two-channel gain and blacklevel. However, two specialized subroutines that can be called from user applications were created to handle both of these functions: pdv_set_gain_basler202k, and pdv_set_offset_basler202k. The source code for these is provided in libpdv.c and can be used as examples for for programmers wishing to create subroutines for other Basler A202k-specific functions. ======================================================================= pdv_set_gain_basler202k DESCRIPTION Set the gain on channel A and B of the Basler A202k camera. Sends the binary serial command, properly formatted, to the camera, and reads the response. SYNTAX int pdv_set_gain_basler202k(PdvDev *pdv_p, int gaina, int gainb) ARGUMENTS pdv_p pointer device struct returned from pdv_open gaina gain value for channel A gainb gain value for channel B RETURNS 0 on success, -1 on failure EXAMPLE /* set both channel A and channel B gain to 100 */ pdv_set_gain_basler202k(pdv_p, 100, 100); ======================================================================= pdv_set_offset_basler202k DESCRIPTION Set the gain on channel A and B of the Basler A202k camera. Sends the binary serial command, properly formatted, to the camera, and reads the response. SYNTAX int pdv_set_offset_basler202k(PdvDev *pdv_p, int offseta, int offsetb) ARGUMENTS pdv_p pointer device struct returned from pdv_open offseta offset value for channel A offsetb offset value for channel B RETURNS 0 on success, -1 on failure EXAMPLE /* set both channel A and channel B offset to 100 */ pdv_set_offset_basler202k(pdv_p, 100, 100); ======================================================================= Two more specialized subroutines were created to help make it easier to program for this camera -- pdv_send_basler_command, and pdv_send_basler_frame. Both are used, either directly or indrectly by the above routines. ======================================================================= pdv_send_basler_command DESCRIPTION send a basler binary command -- do the framing and BCC. Ref. BASLER A202k Camera Manual Doc. ID number DA044003. SYNTAX int pdv_send_basler_command(PdvDev * pdv_p, int cmd, int rwflag, int len, int data) ARGUMENTS pdv_p pointer device struct returned from pdv_open cmd basler command to send rwflag read/write flag -- 1 if read, 0 if write len data length data the data (if any) RETURNS 0 on success, -1 on failure EXAMPLE /* set channel A gain to 10 -- see A202k user's guide for command set */ pdv_send_basler_command(pdv_p, 0x81, 0, 2, 10); ======================================================================= pdv_send_basler_frame DESCRIPTION Given a command buffer minus the framing, add the framing information and send the frame. Ref. BASLER A202k Camera Manual Doc. ID number DA044003. SYNTAX int pdv_send_basler_frame(PdvDev * pdv_p, u_char *cmdbuf, int len) ARGUMENTS pdv_p pointer device struct returned from pdv_open cmdbuf basler command buffer len length in bytes of command buffer RETURNS 0 on success, -1 on failure EXAMPLE unsigned char cmdbuf[2]; buf[0] = 0x81; /* basler channel A gain command */ buf[1] = 0x02; /* r/w flag 0 (write), data length 2 bytes */ buf[2] = 10; /*LS byte of data (in this case, gain value of 10 */ buf[3] = 10; /* MS byte of data */ pdv_send_basler_frame(pdv_p, cmdbuf, 4); /* send_basler_frame adds the */ /* STX, BCC and ETX, and sends */ /* the frame */ =======================================================================