EDT PDV SDK Documentation 6.2.0
|
Functions | |
int | pdv_serial_set_baud (PdvDev pdv_p, int baud) |
Sets the baud rate on the serial lines; applies only to cameras with serial control. Valid values are 9600, 19200, 38500, 57500, and 115200. More... | |
int | pdv_serial_get_baud (PdvDev pdv_p) |
Get the baud rate, typically initialized by the serial_baud directive in the config file. More... | |
int | pdv_serial_command (PdvDev pdv_p, const char *cmd) |
Sends an ASCII serial command to the camera, with ASCII camera command formatting. Applies only to cameras that use a serial control method for camera-computer communications. More... | |
int | pdv_serial_binary_command (PdvDev pdv_p, const uint8_t *cmd, int len) |
Sends a binary serial command to the camera. Applies only to cameras that use a serial control method for for camera-computer communications. More... | |
int | pdv_serial_write_available (PdvDev pdv_p) |
Get the number of bytes available in the driver's serial write buffer. More... | |
int | pdv_serial_write (PdvDev pdv_p, const char *buf, int size) |
Performs a serial write over the serial lines. Not recommended for use in new code, consider using pdv_serial_command() or pdv_serial_binary_command() instead. More... | |
int | pdv_serial_read (PdvDev pdv_p, char *buf, int size) |
Performs a serial read over the serial control lines. More... | |
int | pdv_serial_read_blocking (PdvDev pdv_p, char *buf, int size) |
Performs a serial read over the serial control lines, blocks until all requested data is read. More... | |
int | pdv_serial_read_nullterm (PdvDev pdv_p, char *buf, int size, int nullterm) |
Performs a serial read over the serial control lines. The buffer passed in will be NULL-terminated if nullterm is true. More... | |
void | pdv_serial_set_delimiters (PdvDev pdv_p, const char *newprefix, const char *newterm) |
Set the prefix and terminator for serial commands. More... | |
const char * | pdv_serial_prefix (PdvDev pdv_p) |
Get the serial prefix. More... | |
const char * | pdv_serial_term (PdvDev pdv_p) |
Get the serial terminator. More... | |
void | pdv_serial_send_break (PdvDev pdv_p) |
Send a break condition on the serial connection. More... | |
void | pdv_serial_reset (PdvDev pdv_p) |
Resets the serial interface. Clears any outstanding reads and writes and puts the serial interface in a known idle state. More... | |
int | pdv_serial_read_basler (PdvDev pdv_p, uint8_t *cmd, int len) |
Reads a Basler binary frame command. Checks the framing and BCC. More... | |
int | pdv_serial_write_basler (PdvDev pdv_p, uint8_t *cmd, int len) |
Send a Basler formatted serial frame. Adds the framing and BCC. More... | |
int | pdv_serial_read_duncan (PdvDev pdv_p, uint8_t *frame) |
Read a binary serial response from a Duncantech MS and DT series camera – checks for STX and size, then waits for size+1 more bytes. More... | |
int | pdv_serial_write_duncan (PdvDev pdv_p, uint8_t *cmdbuf, int size) |
Send a Duncantech MS / DT series camera frame – adds the framing and checksum, then sends the command. More... | |
int | pdv_serial_wait (PdvDev pdv_p, int msecs, int count) |
Waits for a response from the camera as a result of a pdv_serial_write() or pdv_serial_command(). More... | |
int | pdv_serial_wait_next (PdvDev pdv_p, int msecs, int count) |
Wait for new serial data to come in. Ignore any previously received data. More... | |
int | pdv_serial_set_waitchar (PdvDev pdv_p, int enable, unsigned char wchar) |
Set the serial wait character. More... | |
int | pdv_serial_get_waitchar (PdvDev pdv_p, unsigned char *wchar) |
Get serial wait character. More... | |
int | pdv_serial_get_numbytes (PdvDev pdv_p) |
Returns the number of bytes of unread data in the serial response buffer. More... | |
int | pdv_serial_get_block_size (void) |
Returns the block size for serial writes. More... | |
void | pdv_serial_set_block_size (int newsize) |
Sets the block size for serial writes. More... | |
int | pdv_serial_get_timeout (PdvDev pdv_p) |
Get the value of the serial timeout. More... | |
int | pdv_get_pause_for_serial (PdvDev pdv_p) |
Get the serial pause time, in milliseconds. More... | |
Serial communications and camera control subroutines. Subroutines in this section of the library fall into three general categories: 1) low level serial communications and control, 2) framing commands for cameras that have sophisticated command framing protocols, and 3) high level convenience routines for specific operations on selected cameras.
These subroutines are used to communicate with cameras that have a serial command set. Since there is (to date) no standard command set, programmers who wish to embed camera control commands within applications will need to write code that is specific to the camera(s) in use.
Serial control typically consists a command/response sequence, and looks like the following:
The above is the most general purpose method, but it can be slow since pdv_serial_wait will only return after the timeout period expires, in order to ensure that all of the response characters have come in. If the last character of a response is known and can be assured to always be unique within that response, then the use of a serial wait character can be used. When set, it causes pdv_serial_wait to() return immediately when the character is seen, without waiting for the full timeout period to expire:
int pdv_serial_set_baud | ( | PdvDev | pdv_p, |
int | baud | ||
) |
Sets the baud rate on the serial lines; applies only to cameras with serial control. Valid values are 9600, 19200, 38500, 57500, and 115200.
pdv_p | The open PDV device handle. |
baud | The desired baud rate. |
int pdv_serial_get_baud | ( | PdvDev | pdv_p | ) |
Get the baud rate, typically initialized by the serial_baud directive in the config file.
pdv_p | The open PDV device handle. |
int pdv_serial_command | ( | PdvDev | pdv_p, |
const char * | cmd | ||
) |
Sends an ASCII serial command to the camera, with ASCII camera command formatting. Applies only to cameras that use a serial control method for camera-computer communications.
pdv_p | The open PDV device handle. |
cmd | The command to send to the camera. |
Appends the required serial terminator onto the string before sending. The default serial terminator is the \\r
(carriage return) character, which is the most common serial terminator character for cameras with use ASCII serial command sets. If the serial_term directive is present in the config file in use, it will use the terminator specified by that instead. For example, if the camera requires a CR/LF (carriage return/line feed) to terminate instead of just a single carriage return, make sure the following command is in the config file in use:
Also available but much less common is the serial prefix, which can also be added to any command via the serial_prefix camera configuration directive. By default there is no serial prefix.
For a detailed example of serial communications, see the serial_cmd.c example program.
Consult your camera manufacturer's users guide for information on serial command format reqirements.
Example:
int pdv_serial_binary_command | ( | PdvDev | pdv_p, |
const uint8_t * | cmd, | ||
int | len | ||
) |
Sends a binary serial command to the camera. Applies only to cameras that use a serial control method for for camera-computer communications.
pdv_p | The open PDV device handle. |
cmd | A buffer containing the serial command. |
len | The number of bytes to send. |
Similar to pdv_serial_command(), but for binary instead of ASCII commands, it uses a count instead of a terminating NULL to indicate the end of the data. Also, it doesn't add on any terminating CR or LF characters.
Consult your camera manufacturer user's guide for information on serial command format requirements.
For a detailed example of serial communications, see the serial_cmd.c example program.
int pdv_serial_write_available | ( | PdvDev | pdv_p | ) |
Get the number of bytes available in the driver's serial write buffer.
pdv_p | The open PDV device handle. |
int pdv_serial_write | ( | PdvDev | pdv_p, |
const char * | buf, | ||
int | size | ||
) |
Performs a serial write over the serial lines. Not recommended for use in new code, consider using pdv_serial_command() or pdv_serial_binary_command() instead.
pdv_p | The open PDV device handle. |
buf | The buffer containing the serial command. |
size | The number of bytes to send. |
int pdv_serial_read | ( | PdvDev | pdv_p, |
char * | buf, | ||
int | size | ||
) |
Performs a serial read over the serial control lines.
The serial data read will be stored in a user supplied buffer. That buffer will be NULL-terminated. Use pdv_serial_read_nullterm(pdv_p, FALSE) if you don't want that behavior.
pdv_p | The open PDV device handle. | |
[out] | buf | The buffer to receive the data. It must be at least size + 1 bytes (size bytes of data plus a one byte NULL terminator). |
size | The number of bytes to be read. |
Example:
int pdv_serial_read_blocking | ( | PdvDev | pdv_p, |
char * | buf, | ||
int | size | ||
) |
Performs a serial read over the serial control lines, blocks until all requested data is read.
pdv_p | The open PDV device handle. | |
[out] | buf | The buffer to receive the data. It must be at least size + 1 bytes (size bytes of data plus a one byte NULL terminator). |
size | The number of bytes to be read. |
int pdv_serial_read_nullterm | ( | PdvDev | pdv_p, |
char * | buf, | ||
int | size, | ||
int | nullterm | ||
) |
Performs a serial read over the serial control lines. The buffer passed in will be NULL-terminated if nullterm is true.
pdv_p | The open PDV device handle. | |
[out] | buf | The buffer to receive the data. It must be at least size + 1 bytes (size bytes of data plus a one byte NULL terminator). |
size | The number of bytes to be read. | |
nullterm | True to null terminate the buffer read in, false to disable that. |
void pdv_serial_set_delimiters | ( | PdvDev | pdv_p, |
const char * | newprefix, | ||
const char * | newterm | ||
) |
Set the prefix and terminator for serial commands.
The serial prefix and terminator are typically set through the serial_term and serial_prefix config file directives.
pdv_p | The open PDV device handle. |
newprefix | A string to prefix to serial commands, or NULL. |
newterm | A string to append to serial commands, or NULL. |
const char * pdv_serial_prefix | ( | PdvDev | pdv_p | ) |
Get the serial prefix.
pdv_p | The open PDV device handle. |
const char * pdv_serial_term | ( | PdvDev | pdv_p | ) |
Get the serial terminator.
pdv_p | The open PDV device handle. |
void pdv_serial_send_break | ( | PdvDev | pdv_p | ) |
Send a break condition on the serial connection.
pdv_p | The open PDV device handle. |
void pdv_serial_reset | ( | PdvDev | pdv_p | ) |
Resets the serial interface. Clears any outstanding reads and writes and puts the serial interface in a known idle state.
pdv_p | The open PDV device handle. |
int pdv_serial_read_basler | ( | PdvDev | pdv_p, |
uint8_t * | cmd, | ||
int | len | ||
) |
Reads a Basler binary frame command. Checks the framing and BCC.
pdv_p | The open PDV device handle. | |
[out] | cmd | The buffer to receive the data. |
len | The maximum number of bytes to be read. |
int pdv_serial_write_basler | ( | PdvDev | pdv_p, |
uint8_t * | cmd, | ||
int | len | ||
) |
Send a Basler formatted serial frame. Adds the framing and BCC.
pdv_p | The open PDV device handle. |
cmd | The serial data to send. |
len | The number of bytes to send. |
int pdv_serial_read_duncan | ( | PdvDev | pdv_p, |
uint8_t * | frame | ||
) |
Read a binary serial response from a Duncantech MS and DT series camera – checks for STX and size, then waits for size+1 more bytes.
pdv_p | The open PDV device handle. | |
[out] | frame | The buffer to receive the data. |
int pdv_serial_write_duncan | ( | PdvDev | pdv_p, |
uint8_t * | cmdbuf, | ||
int | size | ||
) |
Send a Duncantech MS / DT series camera frame – adds the framing and checksum, then sends the command.
pdv_p | The open PDV device handle. |
cmdbuf | A buffer containing the command, minus framing information. |
size | The number of bytes in the cmdbuf. |
int pdv_serial_wait | ( | PdvDev | pdv_p, |
int | msecs, | ||
int | count | ||
) |
Waits for a response from the camera as a result of a pdv_serial_write() or pdv_serial_command().
After calling this function, use pdv_serial_read() to get the data. For a detailed example of serial communications, see the serial_cmd.c example program.
If the timeout value is zero, the default from the serial_timeout directive in the config file is used. If no default timeout value was specified, the timeout will be 1000 milliseconds.
If two threads attempt to call pdv_serial_wait() at the same time, one will return immediately with a result of -EBUSY.
pdv_p | The open PDV device handle. |
msecs | Number of milliseconds to wait before timing out. |
count | The maximum number of bytes to wait for before returning. |
int pdv_serial_wait_next | ( | PdvDev | pdv_p, |
int | msecs, | ||
int | count | ||
) |
Wait for new serial data to come in. Ignore any previously received data.
pdv_p | The open PDV device handle. |
msecs | Number of milliseconds to wait before timing out. |
count | The maximum number of bytes to wait for before returning. |
int pdv_serial_set_waitchar | ( | PdvDev | pdv_p, |
int | enable, | ||
unsigned char | wchar | ||
) |
Set the serial wait character.
Normally pdv_serial_wait() will wait until the serial_timeout period expires before returning (unless the max number of characters is seen). This is the most general purpose and robust method since there's no other way of knowing all different camera response formats. However if each response can be expected to be 1 line terminated by the same character(such as a newline) every time, then setting the serial_waitchar to that character can greatly shorten the time it takes for a pdv_serial_wait() call to return.
This character can also be initialized in the camera configuration directive serial_waitchar.
pdv_p | The open PDV device handle. |
enable | Nonzero to enable wait character detection. |
wchar | The end of message character to detect. |
int pdv_serial_get_waitchar | ( | PdvDev | pdv_p, |
unsigned char * | wchar | ||
) |
Get serial wait character.
If wait character detection is enabled, pdv_serial_wait() will return immediately after the wait character is detected.
pdv_p | The open PDV device handle. | |
[out] | wchar | The character wait character detection will wait for. |
int pdv_serial_get_numbytes | ( | PdvDev | pdv_p | ) |
Returns the number of bytes of unread data in the serial response buffer.
Similar to pdv_serial_wait() but doesn't wait for any timeout period, nor does it have any minimum count parameter.
pdv_p | The open PDV device handle. |
int pdv_serial_get_block_size | ( | void | ) |
Returns the block size for serial writes.
void pdv_serial_set_block_size | ( | int | newsize | ) |
Sets the block size for serial writes.
The default size is 1024.
newsize | The new serial block size in bytes. |
int pdv_serial_get_timeout | ( | PdvDev | pdv_p | ) |
Get the value of the serial timeout.
pdv_p | The open PDV device handle. |
int pdv_get_pause_for_serial | ( | PdvDev | pdv_p | ) |
Get the serial pause time, in milliseconds.
Set by the pause_for_serial
directive in a camera configuration file.
pdv_p | The open PDV device handle. |