UniPRT SDK v2.0-so (Python)
 
Loading...
Searching...
No Matches
CommSDK.CommSDK Class Reference

Public Member Functions

 __init__ (self)
 
int GetBytesAvailable (self)
 Get the bytes available.
 
bool Connected (self)
 Is connected with the selected interface.
 
 Read (self, buffer, size)
 Read data through the selected interface from printer.
 
 Write (self, data_out, data_size)
 Write data through the selected interface to printer.
 
 WriteAndWaitForResponse (self, data_out, data_size, response_start_time_out, response_end_time_out, completion_token)
 Write byte data to output stream and return data received.
 
 Close (self)
 Disconnect the printer.
 
 Open (self)
 Open the printer through the selected interface.
 
 SendPrintFile (self, ipAddress, fileName)
 Send file through the NET.
 
 SendPrintString (self, ipAddress, data, iDataSize)
 Send the string through the NET.
 
Tuple[List[Tuple_c], int] GetAvailableDevices (self)
 Return the v_id and p_id of valid devices in the format of Tuple_c.
 
 UsbConnection (self, Tuple_c device)
 Connect to the selected USB device.
 
 TcpConnection (self, str ipAddress, int port)
 Connect to the selected NET device.
 
 BtConnection (self, str macAddress)
 Connect to the selected bluetooth device.
 
 ComConnection (self, str comport, int baudrate)
 Connect to the selected COM port device.
 
Union[CObject, None] GetComm (self)
 Get the pointer of communicating interface.
 

Public Attributes

 giComm
 

Protected Attributes

 _socket
 

Constructor & Destructor Documentation

◆ __init__()

CommSDK.CommSDK.__init__ ( self)

Member Function Documentation

◆ BtConnection()

CommSDK.CommSDK.BtConnection ( self,
str macAddress )

Connect to the selected bluetooth device.

Parameters
macAddressMAC address for bluetooth device
Returns
: None
Sample:
BtConnection("34:81:F4:43:3D:A8")
    \~Chinese-Traditional @brief 透過 Bluetooth 連接所選擇的印表機。

◆ Close()

CommSDK.CommSDK.Close ( self)

Disconnect the printer.

Returns
None
Sample
Close()

◆ ComConnection()

CommSDK.CommSDK.ComConnection ( self,
str comport,
int baudrate )

Connect to the selected COM port device.

Parameters
comportCOM port name
baudratebaud rate, range (9600 bps ~ 115200 bps)
Returns
: None
Sample:
Comm_Sdk_Instance.ComConnection("/dev/ttyUSB0", 9600)

◆ Connected()

bool CommSDK.CommSDK.Connected ( self)

Is connected with the selected interface.

Returns
  • True if connected
  • False otherwise
Sample
if Connected():
print("Connected")

◆ GetAvailableDevices()

Tuple[List[Tuple_c], int] CommSDK.CommSDK.GetAvailableDevices ( self)

Return the v_id and p_id of valid devices in the format of Tuple_c.

The "v_id" refers to the Vendor ID, and "p_id" refers to the Vendor ID.

Returns
: devices, count
Sample
devices = None
count = 0
GetAvailableDevices()
\~Chinese-Traditional @brief 傳回有效設備的v_id和p_id,格式為Tuple_c。 「v_id」指供應商ID,「p_id」指供應商ID。                 

◆ GetBytesAvailable()

int CommSDK.CommSDK.GetBytesAvailable ( self)

Get the bytes available.

Returns
  • Greater than 0 : The size of data bytes available
  • Equal to 0 : None
Sample
iBytes = GetBytesAvailable()

◆ GetComm()

Union[CObject, None] CommSDK.CommSDK.GetComm ( self)

Get the pointer of communicating interface.

Returns
None
Sample
commPtr = None
GetComm(commPtr)

◆ Open()

CommSDK.CommSDK.Open ( self)

Open the printer through the selected interface.

Returns
None
Sample
Open()

◆ Read()

CommSDK.CommSDK.Read ( self,
buffer,
size )

Read data through the selected interface from printer.

Parameters
[in]bufferThe buffer to store data
[in]sizeThe size of the buffer
Returns
None
Sample
i_bytes = GetBytesAvailable()
p_buf = bytearray(i_bytes)
Read(p_buf, i_bytes)

◆ SendPrintFile()

CommSDK.CommSDK.SendPrintFile ( self,
ipAddress,
fileName )

Send file through the NET.

Parameters
[in]ipAddressIP address
[in]fileNameFile path
Returns
None
Sample
SendPrintFile("10.0.10.172", "rfid.pgl")

◆ SendPrintString()

CommSDK.CommSDK.SendPrintString ( self,
ipAddress,
data,
iDataSize )

Send the string through the NET.

Parameters
[in]ipAddressIP address
[in]dataThe data to send to the printer
[in]iDataSizeThe size of the data
Returns
None
Sample
SendPrintString("10.0.10.172", "FEED 100", len("FEED 100"))

◆ TcpConnection()

CommSDK.CommSDK.TcpConnection ( self,
str ipAddress,
int port )

Connect to the selected NET device.

Parameters
[in]ipAddressIPv4 or IPv6 address
[in]portPort number (e.g., 9100)
Returns
None
Sample
TcpConnection("10.100.15.214", 9100)
TcpConnection("fe80::208:96ff:fe40:9b04%ens33", 9100) // Link Local IPv6 Address
TcpConnection("2001:b030:2219:c40:208:96ff:fe40:9b04", 9100) // Global Unicast IPv6 Address

◆ UsbConnection()

CommSDK.CommSDK.UsbConnection ( self,
Tuple_c device )

Connect to the selected USB device.

Parameters
deviceTuple_c for v_id & p_id of selected USB device
Returns
: None
Sample:
UsbConnection(usb_tuple)

◆ Write()

CommSDK.CommSDK.Write ( self,
data_out,
data_size )

Write data through the selected interface to printer.

Parameters
[in]data_outThe data to write to printer
[in]data_sizeThe size of the data to write to printer
Returns
None
Sample
content = "FEED 100"
p_str = content.encode('utf-8')
Write(p_str, len(p_str))

◆ WriteAndWaitForResponse()

CommSDK.CommSDK.WriteAndWaitForResponse ( self,
data_out,
data_size,
response_start_time_out,
response_end_time_out,
completion_token )

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]data_outThe data to write to printer
[in]data_sizeThe size of the data to write to printer
[in]response_start_time_outTimeout to wait for first data to be received. Time to first byte
[in]response_end_time_outTimeout of no new data received. Time after last byte
[in]completion_tokenString token denoting the end of the response expected. This can be an empty string if simply want to wait for response after writing data to connection.
Returns
A bytes object received from the connection. Data returned is any data received or up to completion_token if token received
Sample
content = "FEED 100\r\nOUT \"12345678\"\r\n"
print("Send to Printer:")
print(content)
p_response = WriteAndWaitForResponse(content.encode('utf-8'), len(content), 1000, 500, "\r\n")

Member Data Documentation

◆ _socket

CommSDK.CommSDK._socket
protected

◆ giComm

CommSDK.CommSDK.giComm