UniPRT SDK v2.0-DLL (C++)
 
Loading...
Searching...
No Matches
CommSDK.cpp File Reference
#include "pch.h"
#include "framework.h"
#include "CommSDK.h"
#include "UsbComm.h"
#include "TcpComm.h"
#include "BtComm.h"
#include "ComComm.h"
Include dependency graph for CommSDK.cpp:

Enumerations

enum  COMM_IDX { USB_COMM = 0 , TCP_COMM , BT_COMM , COM_COMM }
 

Functions

DLLEXINT BytesAvailable ()
 Get the bytes available.
 
DLLEXBOOL Connected ()
 Is connected with the selected interface.
 
DLLEXVOID Read (byte *buffer, int size)
 Read data through the selected interface from printer.
 
DLLEXVOID Write (byte *dataOut, int iDataSize)
 Write data through the selected interface to printer.
 
DLLEXPBYTE WriteAndWaitForResponse (byte *dataOut, int iDataSize, int responseStartTimeOut, int responseEndTimeOut, char *completetionToken)
 Write byte data to output stream and return data received. Data returned is any data received or up to completion token if received. Wait for response timeout before returning.
 
DLLEXVOID Close ()
 Disconnect the printer.
 
DLLEXVOID Open ()
 Open the printer through the selected interface.
 
DLLEXVOID SendPrintFile (char *ipAddress, char *fileName)
 Send file through the NET.
 
DLLEXVOID SendPrintString (char *ipAddress, char *data, int iDataSize)
 Send the string through the NET.
 
DLLEXINT GetAvailableDevices (Tuple_c **devices, int *count)
 Return the v_id and p_id of valid devices in the format of Tuple_c {short v_id; short p_id;}. The "v_id" refers to the Vendor ID, and "p_id" refers to the Vendor ID.
 
DLLEXVOID UsbConnect (Tuple_c device)
 Connect to the selected USB device.
 
DLLEXVOID TcpConnect (char *ipAddress, int port)
 Connect to the selected NET device.
 
DLLEXVOID BtConnect (u_int64 macAddress)
 Connect to the selected bluetooth device.
 
DLLEXVOID ComConnect (std::string ComPort, int BaudRate)
 Connect to the selected COM port device.
 
DLLEXVOID GetComm (CObject *&ptrComm)
 Get the pointer of communicating interface.
 

Variables

CCommSDKApp theApp
 
UsbComm gUsbComm
 
UsbConnection gUsbConnection
 
TcpComm gTcpComm
 
TcpConnection gTcpConnection
 
BtComm gBtComm
 
BtConnection gBtConnection
 
ComComm gComComm
 
ComConnection gComConnection
 
int giComm = USB_COMM
 

Enumeration Type Documentation

◆ COMM_IDX

enum COMM_IDX
Enumerator
USB_COMM 
TCP_COMM 
BT_COMM 
COM_COMM 

Function Documentation

◆ BtConnect()

DLLEXVOID BtConnect ( u_int64 macAddress)

Connect to the selected bluetooth device.

Parameters
[in]macAddress: MAC address for bluetooth device
Returns
void
Sample
BtConnect(0x3481F4433DA8);
DLLEXVOID BtConnect(u_int64 macAddress)
Connect to the selected bluetooth device.
Definition CommSDK.cpp:923

◆ BytesAvailable()

DLLEXINT BytesAvailable ( )

Get the bytes available.

Returns
Greater than 0 : The size of data bytes available
Equal to 0 : None
Sample
int iBytes = BytesAvailable();
pBuf = new byte[iBytes];
Read(pBuf, iBytes);
DLLEXINT BytesAvailable()
Get the bytes available.
Definition CommSDK.cpp:158
DLLEXVOID Read(byte *buffer, int size)
Read data through the selected interface from printer.
Definition CommSDK.cpp:302

◆ Close()

DLLEXVOID Close ( )

Disconnect the printer.

Returns
void
Sample
DLLEXVOID Close()
Disconnect the printer.
Definition CommSDK.cpp:552

◆ ComConnect()

DLLEXVOID ComConnect ( std::string ComPort,
int BaudRate )

Connect to the selected COM port device.

Parameters
[in]ComPort: COM port name
[in]BaudRate: baud rate, range (9600 bps ~ 115200 bps)
Returns
void
Sample
ComConnect("COM5", 9600);
DLLEXVOID ComConnect(std::string ComPort, int BaudRate)
Connect to the selected COM port device.
Definition CommSDK.cpp:967

◆ Connected()

DLLEXBOOL Connected ( )

Is connected with the selected interface.

Returns
true or false
Sample
if (true == Connected())
DLLEXBOOL Connected()
Is connected with the selected interface.
Definition CommSDK.cpp:213

◆ GetAvailableDevices()

DLLEXINT GetAvailableDevices ( Tuple_c ** devices,
int * count )

Return the v_id and p_id of valid devices in the format of Tuple_c {short v_id; short p_id;}. The "v_id" refers to the Vendor ID, and "p_id" refers to the Vendor ID.

Parameters
[out]devices: Tuple_c to storage v_id & p_id
[out]count: the count of USB device(s)
Returns
int
Sample
Tuple_c* devices = nullptr;
int count = 0;
DLLEXINT GetAvailableDevices(Tuple_c **devices, int *count)
Return the v_id and p_id of valid devices in the format of Tuple_c {short v_id; short p_id;}....
Definition CommSDK.cpp:760
Tuple_c * devices
Definition LabelMakerSDK.cpp:2622

◆ GetComm()

DLLEXVOID GetComm ( CObject *& ptrComm)

Get the pointer of communicating interface.

Parameters
[in]ptrComm: a pointer to storage communicating interface
Returns
void
Sample
CObject* commPtr = NULL;
GetComm(commPtr);
DLLEXVOID GetComm(CObject *&ptrComm)
Get the pointer of communicating interface.
Definition CommSDK.cpp:1013

◆ Open()

DLLEXVOID Open ( )

Open the printer through the selected interface.

Returns
void
Sample
Open();
DLLEXVOID Open()
Open the printer through the selected interface.
Definition CommSDK.cpp:598

◆ Read()

DLLEXVOID Read ( byte * buffer,
int size )

Read data through the selected interface from printer.

Parameters
[in]buffer: the buffer for to storage data
[in]size: buffer size
Returns
void
Sample
int iBytes = BytesAvailable();
pBuf = new byte[iBytes];
Read(pBuf, iBytes);

◆ SendPrintFile()

DLLEXVOID SendPrintFile ( char * ipAddress,
char * fileName )

Send file through the NET.

Parameters
[in]ipAddress: IP address
[in]fileName: file path
Returns
void
Sample
SendPrintFile((char*)"10.0.10.172", (char*)"rfid.pgl");
DLLEXVOID SendPrintFile(char *ipAddress, char *fileName)
Send file through the NET.
Definition CommSDK.cpp:662

◆ SendPrintString()

DLLEXVOID SendPrintString ( char * ipAddress,
char * data,
int iDataSize )

Send the string through the NET.

Parameters
[in]ipAddress: IP address
[in]data: the data to the printer
[in]iDataSize: the size of data
Returns
void
Sample
SendPrintString((char*)"10.0.10.172", (char*)"FEED 100", strlen("FEED 100"));
DLLEXVOID SendPrintString(char *ipAddress, char *data, int iDataSize)
Send the string through the NET.
Definition CommSDK.cpp:709

◆ TcpConnect()

DLLEXVOID TcpConnect ( char * ipAddress,
int port )

Connect to the selected NET device.

Parameters
[in]ipAddress: IPv4 or IPv6 address
[in]port: port number:9100
Returns
void
Sample
TcpConnect("10.100.15.214", 9100); // IPv4
TcpConnect((char*)"fe80::208:96ff:fe40:9b04%35", 9100); // Link Local IPv6 Address
TcpConnect((char*)"2001:b030:2219:c40:208:96ff:fe40:9b04", 9100); // Global Unicast IPv6 Address
DLLEXVOID TcpConnect(char *ipAddress, int port)
Connect to the selected NET device.
Definition CommSDK.cpp:877

◆ UsbConnect()

DLLEXVOID UsbConnect ( Tuple_c device)

Connect to the selected USB device.

Parameters
[in]devices: Tuple_c for v_id & p_id of selected USB device
Returns
void
Sample
DLLEXVOID UsbConnect(Tuple_c device)
Connect to the selected USB device.
Definition CommSDK.cpp:823

◆ Write()

DLLEXVOID Write ( byte * dataOut,
int iDataSize )

Write data through the selected interface to printer.

Parameters
[in]dataOut: the data write to printer
[in]iDataSize: the size of data to write to printer
Returns
void
Sample
std::string content;
content += "FEED 100";
const char* pStr = content.c_str();
Write((byte*)pStr, strlen(pStr));
DLLEXVOID Write(byte *dataOut, int iDataSize)
Write data through the selected interface to printer.
Definition CommSDK.cpp:393

◆ WriteAndWaitForResponse()

DLLEXPBYTE WriteAndWaitForResponse ( byte * dataOut,
int iDataSize,
int responseStartTimeOut,
int responseEndTimeOut,
char * completetionToken )

Write byte data to output stream and return data received. Data returned is any data received or up to completion token if received. Wait for response timeout before returning.

Parameters
[in]dataOut: the data write to printer
[in]iDataSize: the size of data to write to printer
[in]responseStartTimeOut: Timeout to wait for first data to be received. Time to first byte
[in]responseEndTimeOut: Timeout of no new data received. Time after last byte
[in]completetionTokenString token denoting the end of the response expected. This can be empty string if simply want to wait for response after writing data to connection.
Returns
byte* string received from connection. Data returned is any data received or up to completetionToken if token received
Sample
std::string content;
content += "FEED 100\r\n";
content += "OUT \"12345678\"\r\n";
std::cout << std::endl;
std::cout << "Send to Printer:" << std::endl;
std::cout << content;
const char* pStr = content.c_str();
byte* pResponse = WriteAndWaitForResponse((byte*)pStr, content.size(), 1000, 500, "\r\n");
DLLEXPBYTE WriteAndWaitForResponse(byte *dataOut, int iDataSize, int responseStartTimeOut, int responseEndTimeOut, char *completetionToken)
Write byte data to output stream and return data received. Data returned is any data received or up t...
Definition CommSDK.cpp:492

Variable Documentation

◆ gBtComm

BtComm gBtComm

◆ gBtConnection

BtConnection gBtConnection

◆ gComComm

ComComm gComComm

◆ gComConnection

ComConnection gComConnection

◆ giComm

int giComm = USB_COMM

◆ gTcpComm

TcpComm gTcpComm

◆ gTcpConnection

TcpConnection gTcpConnection

◆ gUsbComm

UsbComm gUsbComm

◆ gUsbConnection

UsbConnection gUsbConnection

◆ theApp

CCommSDKApp theApp