30
CITIZEN UWP POS Print SDK - Programming Manual
2.3.3. ConnectAsync method
Syntax
1)
Task<int> ConnectAsync (int connectType, string addr)
2)
Task<int> ConnectAsync (int connectType, string addr, int port)
3)
Task<int> ConnectAsync (int connectType, string addr, int port, int timeout)
Parameter
The meaning and the setting range of the parameters are as follows.
Value
[IN/OUT]
Meaning
Setting range
connectType
[IN]
Connect type
CMP_PORT_WiFi
CMP_PORT_Bluetooth
addr
[IN]
IP address or BD address to
connect.
WiFi:
0.0.0.0
~
255.255.255.255
Bluetooth: 00:00:00:00:00:00~
FF:FF:FF:FF:FF:FF
port
[IN]
Connection port number
timeout
[IN]
Timeout (msec)
Description
This method is used to connect the printer. Please specify the type and address of the printer
connection.
Connection port number is valid only if you specify the connection type CMP_PORT_WiFi. If it is omitted,
you connected with number 9100.
Timeout is giving the maximum number of milliseconds to connect printer. If it is omitted, you
connected with 8000 milliseconds when using Bluetooth and connected with 4000 milliseconds in other
cases.
When connecting to the printer, this SDK also checks the status of the printer and the supporting
models.
When communication with the printer is not necessary, must execute the
disconnect the printer connection. When not disconnect, the next connection will be an error.
An application with this SDK connects to a Bluetooth printer for the first time, Windows shows the
consent dialog to accept to use the Bluetooth device (printer). The "timeout" parameter is invalid while
this dialog is shown. To show this dialog, write ConnectAsync method in the UI thread, or it will not
show and fails to connect.
There are declarations to use "Bluetooth" or "Internet (Client)", "Private Networks (Client & Server)" in
the "Capabilities" tab of the Package.appxmanifest which is created by the Visual Studio in the new
project files. Set them correctly, or Windows prevent to use these interfaces.
Return value
Return CMP_SUCCESS (0) in success. Please check the description of the error codes below in the case
of failure. Please refer to "
" for the error code except it.
Error codes
Description
CMP_E_NOTCONNECT (1003)
Failed connection to the printer.
(1) The printer is under none-connection status.
(2) The printer is not turned ON.
(3) Cannot obtain handle of interface board.
CMP_E_CONNECT_NOTFOUND
(1004)
Failed to check the support model after connecting to the printer.
(1) The model is not supported.
CMP_E_CONNECT_OFFLINE (1005)
Failed to check the printer status after connecting to the printer.
The printer is connected but the following errors occurred.