hci_pd_open_device [contns[config]]

This establishes the connection between the driver and the operating system. It also prepares the device for use, where the config argument shadows the declarations made by the driver’s define device statement.

The keys are the same as the keywords in the define device construct, except that lower-case letters are upper-case.

Example 1

The device definition is:

define device;
type: async;
baud: 1200;
end device;

With this definition, you can open the device with a different line speed by calling:

hci_pd_open_device {} {{BAUD 9600}}

The keys that are given in configuration override the specifications made by define device on a per-key basis.

In the case of a TCP server or an async device with require-cd enabled, this function waits for the client to connect before calling the ok continuation.

As for hci_pd_receive, specify a time-out. If the connection fails to establish within the specified time, then the time-out continuation is called.

These continuations, similar to others in this interface, are called with a single keylist argument. The keylist contains a status key with a value of the type of continuation invoked (for example, ok, timeout, temp-error, or perm-error).

These are error continuations apart from the time-out continuation:

  • temp-error is called when the system detects a transient error, such as when the host is unreachable for a TCP client.
  • perm-error is called when an error condition arises that does not go away. For example, an error in the configuration string, or an unknown host name.

An error key is shorthand for specifying both temp-error and perm-error.

Example 2

This example shows the use of hci_pd_open_device with continuations and overrides.

In this example, the driver’s exact configuration is not fully known at compile time. The path to an async device file is taken from some driver-specific configuration information stored in a Tcl global variable.

proc hci_pd_open {info} { 
global some_config_info
hci_pd_open_device {{ok open_ok} \
{error open_failed}} [list [list PATH \
[keylget some_config_info my_path]]] 
}
proc open_ok {info} { 
hci_pd_send welcome_phrase...
}
proc open_failed {info} {
hci_pd_set_result_code 2
}