UniPRT SDK v1.0.0.0
 
Loading...
Searching...
No Matches
JsonMessenger Class Reference

A class for managing JSON-based messaging. More...

#include <JsonMessenger.h>

Inheritance diagram for JsonMessenger:

Instance Methods

(instancetype) - initWithCommToPtr:iCommTyp:maxInputMsgCapacity:usingDataPort:
 Initializes a new instance with the given communication pointer, communication type, maximum input message capacity, and data port usage flag.
 
(NSString *) - sendMsgWithCommand:content:trackNo:
 Send a management command and data/content to printer.
 
(JsonMng *) - sendMsgAndWaitForResponseWithCommand:content:maxWaitTimeSecs:
 Send a management command and data/content to printer and wait for response maxWaitTimeSecs time.
 
(JsonMng *) - readNextMsg
 Read next message that may have been received asynchronously from printer.
 
(void) - sendMsgRawWithDataToSend:
 Sends contents without any message formatting directly to printer.
 
(void) - dispose
 Disposes the object, releasing any resources.
 

Detailed Description

A class for managing JSON-based messaging.

Method Documentation

◆ dispose

- (void) dispose

Disposes the object, releasing any resources.

◆ initWithCommToPtr:iCommTyp:maxInputMsgCapacity:usingDataPort:

- (instancetype) initWithCommToPtr: (AComm *) commToPtr
iCommTyp: (CommType) iCommTyp
maxInputMsgCapacity: (int) maxInputMsgCapacity
usingDataPort: (BOOL) usingDataPort 

Initializes a new instance with the given communication pointer, communication type, maximum input message capacity, and data port usage flag.

The oldest message is dropped if messages not read before more messages received from printer.

Set usingDataPort to true if the communication to printer commToPtr is through the same port that print data is sent through.

This is important in order to properly format management messages so that printer differentiates the messages from print data.

Parameters
commToPtrThe pointer to the communication instance.
iCommTypThe type of communication.
maxInputMsgCapacityThe maximum input message capacity.
usingDataPortA flag indicating whether to use the data port.
Returns
An initialized instance of JsonMessenger, or nil if the object could not be created.

◆ readNextMsg

- (JsonMng *) readNextMsg

Read next message that may have been received asynchronously from printer.

Returns
A JsonMng instance representing the next message.

◆ sendMsgAndWaitForResponseWithCommand:content:maxWaitTimeSecs:

- (JsonMng *) sendMsgAndWaitForResponseWithCommand: (NSString *) command
content: (NSString *) content
maxWaitTimeSecs: (int) maxWaitTimeSecs 

Send a management command and data/content to printer and wait for response maxWaitTimeSecs time.

Null object returned if no response received before timeout expired.

All messages are discarded until the response to the specific message sent is received. The discarded messages may include any unread/old messages waiting to be read prior to the call to this method.

Parameters
commandThe command of the message.
contentThe content of the message.
maxWaitTimeSecsThe maximum wait time in seconds.
Returns
A JsonMng instance representing the response.

◆ sendMsgRawWithDataToSend:

- (void) sendMsgRawWithDataToSend: (NSString *) dataToSend

Sends contents without any message formatting directly to printer.

This is for cases where data needs to be sent without any added management message formatting.

If there is a special management message or data need to be sent in a port that is shared for both data and management, this would be used to send data directly to printer.

Parameters
dataToSendThe data to send.

◆ sendMsgWithCommand:content:trackNo:

- (NSString *) sendMsgWithCommand: (NSString *) command
content: (NSString *) content
trackNo: (NSString *) trackNo 

Send a management command and data/content to printer.

The optional TrackNo is the field used in the JSON command structure sent to printer and can be used by caller to check for response from printer. If no TrackNo is provided, one is generated.

The return string is the TrackNo field used in the JSON message sent to the printer to allow caller to differentiate any response associated with the message sent by comparing the TrackNo field of any response received from printer.

Parameters
commandThe command of the message.
contentThe content of the message.
trackNoThe track number of the message.
Returns
A string representing the result of the send operation.

The documentation for this class was generated from the following file: