Configuring and Testing the RS-232/485 Serial Port

Understanding the Serial Buffer System

The camera associates two distinct buffers with the serial port: one for transmitting data and one for receiving data. These two buffers are accessed and controlled via a single set of data access properties.

FLIR provides serial port examples in the Spinnaker SDK for our USB3 Vision and GigE Vision cameras, and in the FlyCapture2 SDK for our older generation USB2, Firewire, and older GigE/USB3 cameras.

Using Spinnaker to control the serial port:

The Spinnaker nodes are documented in the online Technical Reference Manual.  For example, if using the Blackfly S, you can find the Serial Port descriptions on our support site here

Using Flycapture2 to control the serial port:

The Flycapture2 serial port registers are documented in the Technical Reference Manual, which can be found on the support downloads page for your respective camera.  For example, if using the Blackfly PGE camera, you can find the manuals here.

Serial Port Setup:

To physically wire your serial port to the camera, you need to connect your serial device to the RX/TX/GND pins of the cameras GPIO port.  Refer to the technical refence manuals above for the correct pinout for your camera model.

If connecting the cameras serial port to the PC, which is used for our SDK examples and the walkthrough below, you will need the following setup:

  1. Your PC needs a serial port. If one does not already exist, purchase a USB to Serial port cable or adapter.  After installing this, your PC will see a serial port in device manager.  Note the COM port assigned to this serial port.
  2. From your PCs serial port, you need a RS232 to TTL converter.
  3. To wire up from the RS232-TTL converter to the camera, use a FLIR supplied GPIO cable or make your own from the part numbers supplied in our technical reference manual. Wire up the TX/RX/GND pins between the adapter and the camera.

You now have a serial port connected to the PC.  If you open a terminal window on your PC (hyperterminal, teraterm, putty, etc.), use the example below or our SDK examples to test that the camera is properly sending and receiving serial data.

Serial port example:

Both Flycapture2 and Spinnaker SDKs have serial port example code.  Below is a walk through of the steps to test receiving and transmitting serial data with the camera.  The Flycapture2 registers are mentioned below as they are more complicated, but you can follow the same workflow for the Spinnaker nodes using the below and the Technical Reference manual linked above.

To calculate the base address:

  • Query the offset inquiry register (488h).
  • Multiple the value by 4. (The value is a 32-bit offset.)
  • Remove the 0xF prefix from the result.

Offset

Register Name

Description

488h

SIO_CONTROL_CSR_INQ

32-bit offset register for serial communications control

Base + 000h

SERIAL_MODE_REG

Shared transmit and receive CSRs

Base + 004h

SERIAL_CONTROL_REG
SERIAL_STATUS_REG

Base + 008h

RECEIVE_BUFFER_STATUS_CONTROL

Receive buffer status control

Base + 00Ch

TRANSMIT_BUFFER_STATUS_CONTROL

Transmit buffer status control

Base + 100h

SIO_DATA_REGISTER

Shared access to transmit and receive buffers. Data written to this range is directly reflected in the transmit buffer. Reads from this register range only provide access to data from the receive buffer after the data has been exposed via a write to register 2004h as illustrated in the examples below.

Base + 104h-1FFh

SIO_DATA_REGISTER_ALIAS

Offsets vary by camera model. Always query SIO_CONTROL_CSR_INQ register 488h to obtain the correct offset for your camera.

Transmitting and Receiving Examples

To configure and test these examples:

  • Connect the camera’s serial port to your PC’s serial port. Consult your camera’s Technical Reference for GPIO pin layouts (which pins are designated for RS-232/485) and GPIO electrical characteristics.
  • Access the camera’s register space. This can be done by using the FlyCap software included in the FlyCapture SDK. Consult your camera’s Technical Reference for register definitions and individual bit descriptions.
  • Access Microsoft’s HyperTerminal program to display the characters received from the camera.

Start-->All Programs-->Accessories-->Communications

Transmit Characters to a PC

This example describes how to send four characters from the camera to the serial port on a PC.


This example uses 0x2000 as the base address. Always query SIO_CONTROL_CSR_INQ register 488h to obtain the correct offset for your camera.

Step

Action

Register

Result

  • Plug the camera in and start FlyCap.

 

 

 

  • Open the Camera Control Dialog and select the Register tab.

Get Register

0x2000

0x060800FF
0x06 = 19200bps
0x08 = 8-bit, no parity, 1 stop
0xFF = 255 byte buffer*

  • Get the current baudrate, character length setting, parity setting, and stop bit setting

 

 

 

  • Open a HyperTerminal window and create a new connection. Set the COM port settings to match the camera settings from step 3.

 

 

 

  • Enable the serial output (transmit).

Set Register

0x2004

0x40000000

  • Verify transmit buffer is ready.

Get Register

0x2004

0x40800000

  • Send four characters to the output buffer on the camera.

Set Register

0x2100

0x31323334
ASCII = 1234

  • Verify that the transmit buffer is storing 4 bytes worth of characters.

Get Register

0x200C

0xFF040000
0xFF = 251 bytes of buffer remaining*
0x04 = 4 bytes currently stored

  • Send the characters from the output buffer to the PC’s serial port.

Set Register

0x200C

0xFF040000
HyperTerminal should echo the characters “1234”

*The actual transmit buffer size may be larger than that reported in step 3 above. When this is the case, the buffer space remaining that is reported in step 8 will not decrease until the actual buffer space remaining is less than 255 bytes.

To send more than four characters either:

  • Repeat steps 7 through 9 above, and send characters in sets of four;

Or,

  • Do a block write of all the characters using registers 0x2104 – 0x21FF. Consult the FlyCapture API documentation for information on block transfers.

Although both types of writes to the transmit buffer may have to be 32-bit aligned, the number of characters transmitted does not. Subsequent writes to the buffer will overwrite characters that were not transmitted during a previous transmit.

Receive Characters from a PC

This example describes how to send four characters from the PC to the camera’s serial port.

This example uses 0x2000 as the base address. Always query SIO_CONTROL_CSR_INQ register 488h to obtain the correct offset for your camera.

Step

Action

Register

Result

  • Repeat steps 1 to 4 above.

 

 

 

  • Enable the serial input (receive).

Set Register

0x2004

0x80000000

  • Verify no receive data framing errors

Get Register

0x2004

0x80000000
0x80040000 indicates an error possibly a noisy RS-232/485 line or incorrect baudrate/port setting
0x80020000 indicates a receive data parity error

  • Send four characters to the input buffer on the camera. (Type ABCD in the HyperTerminal window.)

 

 

By default, characters are not displayed in the HyperTerminal window. To echo typed characters to the screen, select File-->Properties-->Settings-->ASCII Setup

  • Verify that the receive data buffer is ready to be read.

Get Register

0x2004

0x80200000

  • Verify that the receive buffer is storing 4 bytes worth of characters.

Get Register

0x2008

0x04000000

  • Send four characters from the input buffer to the data access register.

Set Register

0x2008

0x00040000

  • Verify that four characters are ready to be read from the data access register.

Get Register

0x2008

0x00040000

  • Read the four characters from the data access register.

Get Register

0x2100

0x41424344
(Assumes input was ABCD)

To receive more than four characters either:

  • Repeat steps above, and receive characters in sets of four;

Or,

  • Do a block read of all the characters using registers 0x2104 – 0x21FF. Consult the FlyCapture API documentation for information on block transfers.

Although both types of reads from the receive buffer may have to be 32-bit aligned, the number of characters received does not. Extra characters read will be filled with 0s.

The actual receive buffer size may be larger than that reported above.

Transmitting and Receiving Data Simultaneously

Simultaneous transmitting and receiving of data can be achieved in a similar way to the examples above. The primary difference is that register 0x2004 must be set to 0xC0000000 to enable both transmit and receive. Once set, transmit and receive transactions are interleaved as required by the application.