4.6. ISCPParser

added in version 1.7.0

An interface to provide functions to generate commands for the peripheral control.

This interface is only for models which support the peripheral. For the supporting models, refer to Supported Peripherals .

  • Method

    Name

    Contents

    createSendCommands

    Generates a command to receive the response from the peripheral.

4.6.1. StarIoExtParserCompletionResult

added in version 1.7.0

Parse result constants

  • Declaration

    typedef NS_ENUM(NSInteger, StarIoExtParserCompletionResult) {
        StarIoExtParserCompletionResultInvalid = 0,
        StarIoExtParserCompletionResultSuccess,
        StarIoExtParserCompletionResultFailure
    };
    
  • Constants

    Name

    Contents

    StarIoExtParserCompletionResultInvalid

    Parse invalid

    StarIoExtParserCompletionResultSuccess

    Parse success

    StarIoExtParserCompletionResultFailure

    Parse failure

4.6.2. completionHandler

added in version 1.7.0

Analyzes the response of the command (command generated with the createSendCommands ) for the peripheral control.

  • Declaration

    typedef StarIoExtParserCompletionResult (^StarIoExtParserCompletionHandler)(uint8_t *buffer, int *length);
    
    @property (nonatomic, copy) StarIoExtParserCompletionHandler completionHandler;
    
  • Value

    Contents

    Type

    Parse handler

    StarIoExtParserCompletionHandler

4.6.3. createSendCommands

added in version 1.7.0

Generates a command to receive the response from the peripheral.

  • Declaration

    - (NSData *)createSendCommands;
    
  • Parameter

    None

  • Return value

    Contents

    Type

    Generated command.

    NSData *

  • Examples

    + (BOOL)parseDoNotCheckCondition:(ISCPParser *)parser
                                port:(SMPort *)port
                    completionHandler:(SendCompletionHandler)completionHandler {
        CommResult result = CommResultErrorOpenPort;
        NSInteger code = SMStarIOResultCodeFailedError;
    
        NSData *commands = [parser createSendCommands];
    
        while (YES) {
        NSError *error = nil;
    
        ...
    
        StarPrinterStatus_2 printerStatus;
    
        ...
    
        NSDate *startDate = [NSDate date];
    
        uint32_t total = 0;
        while (total < (uint32_t) commands.length) {
            uint32_t written = [port writePort:(unsigned char *) commands.bytes :total :(uint32_t) commands.length - total :&error];
    
            ...
        }
    
        ...
    
        startDate = [NSDate date]; // Restart
    
        NSMutableData *receivedData = [NSMutableData data];
        while (YES) {
            uint8_t buffer[1024 + 8] = {0};
    
            ...
    
            uint32_t readLength = [port readPort:buffer :0 :1024 :&error];
    
            ...
    
            [receivedData appendBytes:buffer length:readLength];
    
            int recvDataLength = (int) receivedData.length;
    
            uint8_t *recvDataBytes = (uint8_t *) receivedData.bytes;
    
            if (parser.completionHandler(recvDataBytes, &recvDataLength) == StarIoExtParserCompletionResultSuccess) {
                result = CommResultSuccess;
                code = SMStarIOResultCodeSuccess;
    
                break;
            }
        }
    
        break;
        }
    
        ...
    }
    

    Refer to Communication.m.