與 Monitor 相關的類和方法。
更多...
與 Monitor 相關的類和方法。
對於 Objective-C 範例:
打印機監視器範例
Rfid 監視器範例
Odv 監視器範例
對於 Swift 範例:
打印機監視器範例
Rfid 監視器範例
Odv 監視器範例
Example
Objective-C:
Printer Monitor:
#import "ViewController.h"
@import UniPRT;
@interface ViewController ()
@property (strong)
TcpComm *tcpComm;
@property (nonatomic, strong) UITextField *ipTextField;
@property (nonatomic, strong) UITextView *resultTextView;
@property (nonatomic, strong) UITextView *callbackTextView;
@property (nonatomic, strong) UIButton *openButton;
@property (nonatomic, strong) UIButton *writeButton;
@property (nonatomic, strong) UIButton *readButton;
@property (nonatomic, strong) UIButton *connectCloseButton;
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UISegmentedControl *connectionSegmentedControl;
@property (nonatomic, strong) UIButton *connectshowPrinterInfoTestButton;
@property (nonatomic, strong) UIButton *connectPrinterMonitorTestButton;
@property (nonatomic, strong) UIButton *connectPrintTestButton;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, 1500);
scrollView.userInteractionEnabled = YES;
scrollView.scrollEnabled = YES;
[self.view addSubview:scrollView];
self.ipTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 50, 200, 30)];
self.ipTextField.placeholder = @"Enter IP Address";
self.ipTextField.borderStyle = UITextBorderStyleRoundedRect;
[scrollView addSubview:self.ipTextField];
self.ipTextField.text = @"10.0.10.180";
self.resultTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, 150, 300, 200)];
self.resultTextView.editable = NO;
self.resultTextView.scrollEnabled = YES;
self.resultTextView.layer.borderWidth = 1.0;
self.resultTextView.layer.borderColor = [[UIColor blackColor] CGColor];
[scrollView addSubview:self.resultTextView];
self.callbackTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, 550, 300, 1000)];
self.callbackTextView.editable = NO;
self.callbackTextView.scrollEnabled = YES;
self.callbackTextView.layer.borderWidth = 1.0;
self.callbackTextView.layer.borderColor = [[UIColor blackColor] CGColor];
[scrollView addSubview:self.callbackTextView];
self.connectCloseButton = [self createButtonWithTitle:@"Connect" frame:CGRectMake(20, 370, 300, 30)];
self.connectCloseButton.backgroundColor = [UIColor redColor];
[self.connectCloseButton addTarget:self action:@selector(connectCloseButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.connectCloseButton];
self.openButton = [self createButtonWithTitle:@"Open" frame:CGRectMake(20, 420, 300, 30)];
self.openButton.backgroundColor = [UIColor redColor];
[self.openButton addTarget:self action:@selector(openButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.openButton];
self.connectshowPrinterInfoTestButton = [self createButtonWithTitle:@"showPrinterInfoTest" frame:CGRectMake(20, 460, 300, 30)];
self.connectshowPrinterInfoTestButton.backgroundColor = [UIColor redColor];
[self.connectshowPrinterInfoTestButton addTarget:self action:@selector(showPrinterInfoTestButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.connectshowPrinterInfoTestButton];
self.connectPrinterMonitorTestButton = [self createButtonWithTitle:@"PrinterMonitorTest" frame:CGRectMake(20, 500, 300, 30)];
self.connectPrinterMonitorTestButton.backgroundColor = [UIColor redColor];
[self.connectPrinterMonitorTestButton addTarget:self action:@selector(connectPrinterMonitorTestButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.connectPrinterMonitorTestButton];
self.connectPrintTestButton = [self createButtonWithTitle:@"PrinterTest" frame:CGRectMake(20, 535, 300, 30)];
self.connectPrintTestButton.backgroundColor = [UIColor redColor];
[self.connectPrintTestButton addTarget:self action:@selector(connectPrintTestButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.connectPrintTestButton];
}
- (UIButton *)createButtonWithTitle:(NSString *)title frame:(CGRect)frame {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = frame;
[button setTitle:title forState:UIControlStateNormal];
return button;
}
- (void)openButtonPressed {
[self.tcpComm open];
}
- (void)connectCloseButtonPressed {
NSString *currentTitle = [self.connectCloseButton titleForState:UIControlStateNormal];
if ([currentTitle isEqualToString:@"Connect"]) {
NSString *ipAddress = self.ipTextField.text;
self.tcpComm = [[
TcpComm alloc] initWithIPAddress:ipAddress port:DEFAULT_MGMT_PORT];
[self.connectCloseButton setTitle:@"Close" forState:UIControlStateNormal];
} else if ([currentTitle isEqualToString:@"Close"]) {
[self.tcpComm close];
[self.connectCloseButton setTitle:@"Connect" forState:UIControlStateNormal];
}
}
- (void)showPrinterInfoTestButtonPressed {
NSMutableString *receivedString = [[NSMutableString alloc] init];
[receivedString appendString:@"======= RFID Printer Info: \n"];
[receivedString appendFormat:@"Printer Model: %@\n", printerInfo.model];
[receivedString appendFormat:@"Printer SN: %@\n", printerInfo.serialNumber];
[receivedString appendFormat:@"Printer FW PN: %@\n", printerInfo.firmwarePartNumber];
[receivedString appendFormat:@"Printer FW Ver: %@\n", printerInfo.firmwareVersion];
[receivedString appendFormat:@"Printhead Resolution (Dots/Inch): %@\n", printerInfo.printheadResolution];
[receivedString appendFormat:@"Has odv: %@\n", printerInfo.hasOdvOption ? @"Yes" : @"No"];
NSLog(@"%@", receivedString);
self.resultTextView.text = receivedString;
}
- (void)connectPrinterMonitorTestButtonPressed {
NSMutableString *receivedString = [[NSMutableString alloc] init];
NSLog(@"Engine status update: %@", status);
[receivedString appendFormat:@"Engine status update: %@\n", status];
dispatch_async(dispatch_get_main_queue(), ^{
self.callbackTextView.text = receivedString;
});
};
NSLog(@"Display status update: %@", [status componentsJoinedByString:@", "]);
[receivedString appendFormat:@"Display status update: %@\n", [status componentsJoinedByString:@", "]];
dispatch_async(dispatch_get_main_queue(), ^{
self.callbackTextView.text = receivedString;
});
};
NSLog(@"Alert status update: %@", [status componentsJoinedByString:@", "]);
[receivedString appendFormat:@"Alert status update: %@\n", [status componentsJoinedByString:@", "]];
dispatch_async(dispatch_get_main_queue(), ^{
self.callbackTextView.text = receivedString;
});
};
}
- (void)connectPrintTestButtonPressed {
NSString *ipAddress = self.ipTextField.text;
TcpComm *tcpComm2 = [[
TcpComm alloc] initWithIPAddress:ipAddress port:DEFAULT_DATA_PORT];
[tcpComm2
sendPrintFile:ipAddress
fileName:@"/Users/realbuber/Documents/Objective-C IOS SDK example/Objective-C/TestPrinterMonitor/Hello_1.pgl"];
NSLog(@"Sending print job...");
}
@end
打印機信息類,用於顯示打印機屬性和其他有用信息。
Definition PrinterInfo.h:33
模塊用於方便監聽/檢索打印機的非請求消息或檢索打印機狀態/信息。
Definition PrinterMonitor.h:45
void SetEngineStatusListening:(BOOL value)
設置是否啟用引擎狀態監聽。
EngineStatusCallback engineStatusCallback
當從打印機接收到引擎狀態時調用的函數。函數必須符合 EngineStatusNotice 的簽名。
Definition PrinterMonitor.h:474
AlertStatusCallback alertStatusCallback
當從打印機接收到故障/警報消息時調用的函數。函數必須符合 AlertStatusNotice 的簽名。
Definition PrinterMonitor.h:498
PrinterInfo * getPrinterInfo()
獲取打印機信息。
void SetAlertStatusListening:(BOOL value)
設置是否啟用警報狀態監聽。
void SetDisplayStatusListening:(BOOL value)
設置是否啟用顯示狀態監聽。
DisplayStatusCallback displayStatusCallback
當從打印機接收到顯示文本消息時調用的函數。函數必須符合 DisplayStatusNotice 的簽名。
Definition PrinterMonitor.h:486
一個用於 TCP 通信的類,繼承自 AComm 並符合 NSStreamDelegate 協議。
Definition TcpComm.h:101
void sendPrintFile:fileName:(NSString *ipAddress,[fileName] NSString *fileName)
將打印文件發送到指定的 IP 地址。
Rfid Monitor:
#import "ViewController.h"
@import UniPRT;
@interface ViewController ()
@property (strong)
TcpComm *tcpComm;
@property (nonatomic, strong) UITextField *ipTextField;
@property (nonatomic, strong) UITextField *macAddressTextField;
@property (nonatomic, strong) UITextView *resultTextView;
@property (nonatomic, strong) UITextView *callbackTextView;
@property (nonatomic, strong) UIButton *openButton;
@property (nonatomic, strong) UIButton *writeButton;
@property (nonatomic, strong) UIButton *readButton;
@property (nonatomic, strong) UIButton *connectCloseButton;
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UISegmentedControl *connectionSegmentedControl;
@property (nonatomic, strong) UIButton *connectshowPrinterInfoTestButton;
@property (nonatomic, strong) UIButton *connectRfidMonitorTestButton;
@property (nonatomic, strong) UIButton *connectPrintTestButton;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, 1500);
scrollView.userInteractionEnabled = YES;
scrollView.scrollEnabled = YES;
[self.view addSubview:scrollView];
self.ipTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 50, 200, 30)];
self.ipTextField.placeholder = @"Enter IP Address";
self.ipTextField.borderStyle = UITextBorderStyleRoundedRect;
[scrollView addSubview:self.ipTextField];
self.ipTextField.text = @"10.0.10.178";
self.resultTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, 150, 300, 200)];
self.resultTextView.editable = NO;
self.resultTextView.scrollEnabled = YES;
self.resultTextView.layer.borderWidth = 1.0;
self.resultTextView.layer.borderColor = [[UIColor blackColor] CGColor];
[scrollView addSubview:self.resultTextView];
self.callbackTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, 550, 300, 1000)];
self.callbackTextView.editable = NO;
self.callbackTextView.scrollEnabled = YES;
self.callbackTextView.layer.borderWidth = 1.0;
self.callbackTextView.layer.borderColor = [[UIColor blackColor] CGColor];
[scrollView addSubview:self.callbackTextView];
self.connectCloseButton = [self createButtonWithTitle:@"Connect" frame:CGRectMake(20, 370, 300, 30)];
self.connectCloseButton.backgroundColor = [UIColor redColor];
[self.connectCloseButton addTarget:self action:@selector(connectCloseButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.connectCloseButton];
self.openButton = [self createButtonWithTitle:@"Open" frame:CGRectMake(20, 420, 300, 30)];
self.openButton.backgroundColor = [UIColor redColor];
[self.openButton addTarget:self action:@selector(openButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.openButton];
self.connectshowPrinterInfoTestButton = [self createButtonWithTitle:@"showPrinterInfoTest" frame:CGRectMake(20, 460, 300, 30)];
self.connectshowPrinterInfoTestButton.backgroundColor = [UIColor redColor];
[self.connectshowPrinterInfoTestButton addTarget:self action:@selector(showPrinterInfoTestButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.connectshowPrinterInfoTestButton];
self.connectRfidMonitorTestButton = [self createButtonWithTitle:@"RfidMonitorTest" frame:CGRectMake(20, 500, 300, 30)];
self.connectRfidMonitorTestButton.backgroundColor = [UIColor redColor];
[self.connectRfidMonitorTestButton addTarget:self action:@selector(connectRfidMonitorTestButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.connectRfidMonitorTestButton];
self.connectPrintTestButton = [self createButtonWithTitle:@"PrinterTest" frame:CGRectMake(20, 535, 300, 30)];
self.connectPrintTestButton.backgroundColor = [UIColor redColor];
[self.connectPrintTestButton addTarget:self action:@selector(connectPrintTestButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.connectPrintTestButton];
}
- (UIButton *)createButtonWithTitle:(NSString *)title frame:(CGRect)frame {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = frame;
[button setTitle:title forState:UIControlStateNormal];
return button;
}
- (void)openButtonPressed {
[self.tcpComm open];
}
- (void)connectCloseButtonPressed {
NSString *currentTitle = [self.connectCloseButton titleForState:UIControlStateNormal];
if ([currentTitle isEqualToString:@"Connect"]) {
NSString *ipAddress = self.ipTextField.text;
self.tcpComm = [[
TcpComm alloc] initWithIPAddress:ipAddress port:DEFAULT_MGMT_PORT];
[self.connectCloseButton setTitle:@"Close" forState:UIControlStateNormal];
} else if ([currentTitle isEqualToString:@"Close"]) {
[self.tcpComm close];
[self.connectCloseButton setTitle:@"Connect" forState:UIControlStateNormal];
}
}
- (void)showPrinterInfoTestButtonPressed {
NSMutableString *receivedString = [[NSMutableString alloc] init];
[receivedString appendString:@"======= RFID Printer Info: \n"];
[receivedString appendFormat:@"Printer Model: %@\n", printerInfo.model];
[receivedString appendFormat:@"Printer SN: %@\n", printerInfo.serialNumber];
[receivedString appendFormat:@"Printer FW PN: %@\n", printerInfo.firmwarePartNumber];
[receivedString appendFormat:@"Printer FW Ver: %@\n", printerInfo.firmwareVersion];
[receivedString appendFormat:@"Printhead Resolution (Dots/Inch): %@\n", printerInfo.printheadResolution];
[receivedString appendFormat:@"Has RFID: %@\n", printerInfo.hasRfidOption ? @"Yes" : @"No"];
NSLog(@"%@", receivedString);
self.resultTextView.text = receivedString;
}
- (void)connectRfidMonitorTestButtonPressed {
NSMutableString *receivedString = [[NSMutableString alloc] init];
if (report.failed) {
[receivedString appendFormat:@"\nRFID Failed."];
} else {
[receivedString appendFormat:@"\nRFID Passed."];
[receivedString appendFormat:@"Write Action: %@", report.isWriteOperation ? @"Yes" : @"No"];
[receivedString appendFormat:@"Data: \n%@", report.data];
dispatch_async(dispatch_get_main_queue(), ^{
self.callbackTextView.text = receivedString;
});
}
};
}
- (void)connectPrintTestButtonPressed {
NSString *ipAddress = self.ipTextField.text;
TcpComm *tcpComm2 = [[
TcpComm alloc] initWithIPAddress:ipAddress port:DEFAULT_DATA_PORT];
NSLog(@"Sending RFID print job...");
}
@end
提供與 RFID 相關的服務支持。模塊用於監聽/檢索與 RFID 相關的打印機非請求消息。
Definition RfidMonitor.h:53
RfidReportCallback rfidReportCallback
用於接收 RFID 報告時調用的函數。函數必須符合 RfidReportNotice 的簽名。
Definition RfidMonitor.h:302
void SetRfidReportListening:(BOOL value)
設置是否啟用 RFID 報告監聽。
基於從打印機接收到的 RFID 標籤消息的 RFID 報告。
Definition RfidReport.h:110
Odv Monitor:
#import "ViewController.h"
@import UniPRT;
@interface ViewController ()
@property (strong)
TcpComm *tcpComm;
@property (nonatomic, strong) UITextField *ipTextField;
@property (nonatomic, strong) UITextView *resultTextView;
@property (nonatomic, strong) UITextView *callbackTextView;
@property (nonatomic, strong) UIButton *openButton;
@property (nonatomic, strong) UIButton *readButton;
@property (nonatomic, strong) UIButton *connectCloseButton;
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UISegmentedControl *connectionSegmentedControl;
@property (nonatomic, strong) UIButton *connectshowPrinterInfoTestButton;
@property (nonatomic, strong) UIButton *connectOdvMonitorTestButton;
@property (nonatomic, strong) UIButton *connectPrintTestButton;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, 1500);
scrollView.userInteractionEnabled = YES;
scrollView.scrollEnabled = YES;
[self.view addSubview:scrollView];
self.ipTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 50, 200, 30)];
self.ipTextField.placeholder = @"Enter IP Address";
self.ipTextField.borderStyle = UITextBorderStyleRoundedRect;
[scrollView addSubview:self.ipTextField];
self.ipTextField.text = @"10.0.10.178";
self.resultTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, 150, 300, 200)];
self.resultTextView.editable = NO;
self.resultTextView.scrollEnabled = YES;
self.resultTextView.layer.borderWidth = 1.0;
self.resultTextView.layer.borderColor = [[UIColor blackColor] CGColor];
[scrollView addSubview:self.resultTextView];
self.callbackTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, 550, 300, 1000)];
self.callbackTextView.editable = NO;
self.callbackTextView.scrollEnabled = YES;
self.callbackTextView.layer.borderWidth = 1.0;
self.callbackTextView.layer.borderColor = [[UIColor blackColor] CGColor];
[scrollView addSubview:self.callbackTextView];
self.connectCloseButton = [self createButtonWithTitle:@"Connect" frame:CGRectMake(20, 370, 300, 30)];
self.connectCloseButton.backgroundColor = [UIColor redColor];
[self.connectCloseButton addTarget:self action:@selector(connectCloseButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.connectCloseButton];
self.openButton = [self createButtonWithTitle:@"Open" frame:CGRectMake(20, 420, 300, 30)];
self.openButton.backgroundColor = [UIColor redColor];
[self.openButton addTarget:self action:@selector(openButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.openButton];
self.connectshowPrinterInfoTestButton = [self createButtonWithTitle:@"showPrinterInfoTest" frame:CGRectMake(20, 460, 300, 30)];
self.connectshowPrinterInfoTestButton.backgroundColor = [UIColor redColor];
[self.connectshowPrinterInfoTestButton addTarget:self action:@selector(showPrinterInfoTestButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.connectshowPrinterInfoTestButton];
self.connectOdvMonitorTestButton = [self createButtonWithTitle:@"OdvMonitorTest" frame:CGRectMake(20, 500, 300, 30)];
self.connectOdvMonitorTestButton.backgroundColor = [UIColor redColor];
[self.connectOdvMonitorTestButton addTarget:self action:@selector(odvMonitorTestButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.connectOdvMonitorTestButton];
self.connectPrintTestButton = [self createButtonWithTitle:@"PrinterTest" frame:CGRectMake(20, 535, 300, 30)];
self.connectPrintTestButton.backgroundColor = [UIColor redColor];
[self.connectPrintTestButton addTarget:self action:@selector(connectPrintTestButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:self.connectPrintTestButton];
}
- (UIButton *)createButtonWithTitle:(NSString *)title frame:(CGRect)frame {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = frame;
[button setTitle:title forState:UIControlStateNormal];
return button;
}
- (void)openButtonPressed {
[self.tcpComm open];
}
- (void)connectCloseButtonPressed {
NSString *currentTitle = [self.connectCloseButton titleForState:UIControlStateNormal];
if ([currentTitle isEqualToString:@"Connect"]) {
NSString *ipAddress = self.ipTextField.text;
self.tcpComm = [[
TcpComm alloc] initWithIPAddress:ipAddress port:3007];
[self.connectCloseButton setTitle:@"Close" forState:UIControlStateNormal];
} else if ([currentTitle isEqualToString:@"Close"]) {
[self.tcpComm close];
[self.connectCloseButton setTitle:@"Connect" forState:UIControlStateNormal];
}
}
- (void)showPrinterInfoTestButtonPressed {
NSMutableString *receivedString = [[NSMutableString alloc] init];
[receivedString appendString:@"======= ODV Printer Info: \n"];
[receivedString appendFormat:@"Printer Model: %@\n", printerInfo.model];
[receivedString appendFormat:@"Printer SN: %@\n", printerInfo.serialNumber];
[receivedString appendFormat:@"Printer FW PN: %@\n", printerInfo.firmwarePartNumber];
[receivedString appendFormat:@"Printer FW Ver: %@\n", printerInfo.firmwareVersion];
[receivedString appendFormat:@"Printhead Resolution (Dots/Inch): %@\n", printerInfo.printheadResolution];
[receivedString appendFormat:@"Has ODV: %@\n", printerInfo.hasOdvOption ? @"Yes" : @"No"];
NSLog(@"%@", receivedString);
self.resultTextView.text = receivedString;
}
- (void)odvMonitorTestButtonPressed {
NSMutableString *receivedString = [[NSMutableString alloc] init];
if ([report failed]) {
[receivedString appendFormat:@"\nBarcode Failed."];
} else {
[receivedString appendFormat:@"\nBarcode Passed."];
[receivedString appendFormat:@"Grade: %f", [report overallGradeAsFloat]];
if ([report overallGradeAsFloat] > 3.5) {
[receivedString appendFormat:@"Print Quality passed. \n Overall Grade= %.2f", [report overallGradeAsFloat]];
} else {
[receivedString appendFormat:@"Print Quality Failed. \n Overall Grade= %.2f", [report overallGradeAsFloat]];
}
[receivedString appendFormat:@"Barcode Symbology: %@", [report symbology]];
[receivedString appendFormat:@"Barcode Data: %@", [report data]];
dispatch_async(dispatch_get_main_queue(), ^{
self.callbackTextView.text = receivedString;
});
}
};
}
- (void)connectPrintTestButtonPressed {
NSString *ipAddress = self.ipTextField.text;
TcpComm *tcpComm2 = [[
TcpComm alloc] initWithIPAddress:ipAddress port:DEFAULT_DATA_PORT];
[tcpComm2
sendPrintFile:ipAddress
fileName:@"/Users/realbuber/Documents/doc/TestOdvMonitor/DM_PRINTRONIX_1.pgl"];
NSLog(@"Sending ODV print job...");
}
@end
提供與 ODV 相關的服務支持。模塊用於監聽/檢索與 ODV 相關的打印機非請求消息。
Definition OdvMonitor.h:54
OdvReportCallback odvReportCallback
用於接收 ODV 報告時調用的函數。函數必須符合 OdvReportNotice 的簽名。
Definition OdvMonitor.h:267
void SetOdvReportListening:(BOOL value)
設置是否啟用 ODV 報告監聽。
ODV 報告類,用於顯示從打印機接收的 ODV/ODV2D 數據。
Definition OdvReport.h:33
Swift:
Printer Monitor:
import SwiftUI
import UniPRT
struct ContentView: View {
@State private var ipText = "10.0.10.170"
@State private var inputText = ""
@StateObject private var viewModel = CommunicationViewModel()
var body: some View {
NavigationView {
Form {
Section(header: Text("IP Address")) {
TextField("Enter IP Address", text: $ipText)
.keyboardType(.decimalPad)
}
Section(header: Text("Output")) {
ScrollView {
Text(viewModel.resultText)
.frame(maxWidth: .infinity, alignment: .leading)
.fixedSize(horizontal: false, vertical: true)
.font(.system(size: 8))
}
.frame(height: 300)
.border(Color.secondary, width: 1)
}
Button("Connect/Close") {
viewModel.connectCloseAction(ip: ipText)
}
Button("Open") {
viewModel.openAction()
}
Button("Get Printer Info") {
viewModel.fetchPrinterInfo()
}
Button("Test Printer Monitor") {
viewModel.printerListening()
}
Button("Send Print File") {
viewModel.printTest()
}
}
.navigationBarTitle("Communication")
}
}
}
@objcMembers class CommunicationViewModel: ObservableObject {
@Published var resultText = ""
var tcpComm: TcpComm?
func openAction() {
if tcpComm != nil {
tcpComm?.open()
DispatchQueue.main.async {
self.resultText = "TCP Connection opened"
}
} else {
DispatchQueue.main.async {
self.resultText = "No TCP Connection to open"
}
}
}
func fetchPrinterInfo() {
guard let tcpComm = tcpComm else {
DispatchQueue.main.async {
self.resultText = "No TCP Connection"
}
return
}
let printerMonitor = PrinterMonitor(tcpComm: tcpComm)
let printerInfo = printerMonitor?.getPrinterInfo()
DispatchQueue.main.async {
self.resultText = "======= RFID Printer Info: \n"
self.resultText += "Printer Model: \(String(describing: printerInfo?.model))\n"
self.resultText += "Printer SN: \(String(describing: printerInfo?.serialNumber))\n"
self.resultText += "Printer FW PN: \(String(describing: printerInfo?.firmwarePartNumber))\n"
self.resultText += "Printer FW Ver: \(String(describing: printerInfo?.firmwareVersion))\n"
self.resultText += "Printhead Resolution (Dots/Inch): \(String(describing: printerInfo?.printheadResolution))\n"
self.resultText += "Has RFID: \((printerInfo?.hasRfidOption != nil) ? "Yes" : "No")\n"
}
}
func connectCloseAction(ip: String) {
if tcpComm != nil {
tcpComm?.close()
tcpComm = nil
DispatchQueue.main.async {
self.resultText = "TCP Connection closed"
}
} else {
tcpComm = TcpComm(ipAddress: ip, port: 3007)
DispatchQueue.main.async {
self.resultText = "TCP Connected to \(ip)"
}
}
}
func printerListening() {
guard let tcpComm = tcpComm else {
DispatchQueue.main.async {
self.resultText = "No TCP Connection"
}
return
}
let printerMonitor = PrinterMonitor(tcpComm: tcpComm)
// Engine Status Update Callback
printerMonitor?.engineStatusCallback = { status in
DispatchQueue.main.async {
self.resultText += "Engine status update: \(String(describing: status))\n"
}
}
printerMonitor?.setEngineStatusListening(true)
// Display Status Update Callback
printerMonitor?.displayStatusCallback = { status in
DispatchQueue.main.async {
let statusString = (status ?? ["Unknown"]).compactMap { $0 }.joined(separator: ", ")
self.resultText += "Display status update: \(statusString)\n"
}
}
printerMonitor?.setDisplayStatusListening(true)
// Alert Status Update Callback
printerMonitor?.alertStatusCallback = { status in
DispatchQueue.main.async {
let statusString = (status ?? ["Unknown"]).compactMap { $0 }.joined(separator: ", ")
self.resultText += "Alert status update: \(statusString)\n"
}
}
printerMonitor?.setAlertStatusListening(true)
}
func printTest() {
let tcpComm2 = TcpComm(ipAddress: "10.0.10.170", port: 9100)
tcpComm2?.sendPrintFile("10.0.10.170", fileName: "/Users/realbuber/Documents/Objective-C IOS SDK example/Swift/TestPrinterMonitor/Hello_1.pgl")
}
}
#Preview {
ContentView()
}
Rfid Monitor:
import SwiftUI
import UniPRT
struct ContentView: View {
@State private var ipText = "10.0.10.178"
@StateObject private var viewModel = CommunicationViewModel()
var body: some View {
NavigationView {
Form {
Section(header: Text("IP Address")) {
TextField("Enter IP Address", text: $ipText)
.keyboardType(.decimalPad)
}
Section(header: Text("Output")) {
ScrollView {
Text(viewModel.resultText)
.frame(maxWidth: .infinity, alignment: .leading)
.fixedSize(horizontal: false, vertical: true)
.font(.system(size: 8))
}
.frame(height: 300)
.border(Color.secondary, width: 1)
}
Button("Connect/Close") {
viewModel.connectCloseAction(ip: ipText)
}
Button("Open") {
viewModel.openAction()
}
Button("Get Printer Info") {
viewModel.fetchPrinterInfo()
}
Button("Test RFID Monitor") {
viewModel.rfidListening()
}
Button("Send Print File") {
viewModel.printTest()
}
}
.navigationBarTitle("Communication")
}
}
}
@objcMembers class CommunicationViewModel: ObservableObject {
@Published var resultText = ""
var tcpComm: TcpComm?
func openAction() {
if tcpComm != nil {
tcpComm?.open()
DispatchQueue.main.async {
self.resultText = "TCP Connection opened"
}
} else {
DispatchQueue.main.async {
self.resultText = "No TCP Connection to open"
}
}
}
func fetchPrinterInfo() {
guard let tcpComm = tcpComm else {
DispatchQueue.main.async {
self.resultText = "No TCP Connection"
}
return
}
let printerMonitor = PrinterMonitor(tcpComm: tcpComm)
let printerInfo = printerMonitor?.getPrinterInfo()
DispatchQueue.main.async {
self.resultText = "======= RFID Printer Info: \n"
self.resultText += "Printer Model: \(String(describing: printerInfo?.model))\n"
self.resultText += "Printer SN: \(String(describing: printerInfo?.serialNumber))\n"
self.resultText += "Printer FW PN: \(String(describing: printerInfo?.firmwarePartNumber))\n"
self.resultText += "Printer FW Ver: \(String(describing: printerInfo?.firmwareVersion))\n"
self.resultText += "Printhead Resolution (Dots/Inch): \(String(describing: printerInfo?.printheadResolution))\n"
self.resultText += "Has RFID: \((printerInfo?.hasRfidOption != nil) ? "Yes" : "No")\n"
}
}
func connectCloseAction(ip: String) {
if tcpComm != nil {
tcpComm?.close()
tcpComm = nil
DispatchQueue.main.async {
self.resultText = "TCP Connection closed"
}
} else {
tcpComm = TcpComm(ipAddress: ip, port: 3007)
DispatchQueue.main.async {
self.resultText = "TCP Connected to \(ip)"
}
}
}
func rfidListening() {
guard let tcpComm = tcpComm else {
DispatchQueue.main.async {
self.resultText = "No TCP Connection"
}
return
}
let rfidMonitor = RfidMonitor(tcpComm: tcpComm)
rfidMonitor?.rfidReportCallback = { report in
DispatchQueue.main.async {
if report?.failed() == true {
self.resultText = "RFID Failed."
} else {
self.resultText += "RFID Passed. Write Action: \((report?.isWriteOperation() == true) ? "Yes" : "No"), Data: \n\(String(describing: report?.data()))"
}
}
}
rfidMonitor?.setRfidReportListening(true)
}
func printTest() {
let tcpComm2 = TcpComm(ipAddress: "10.0.10.170", port: 9100)
tcpComm2?.sendPrintFile("10.0.10.170", fileName: "/Users/realbuber/Documents/Objective-C IOS SDK example/Swift/TestRfidMonitor/rfid.pgl")
}
}
#Preview {
ContentView()
}
Odv Monitor:
import SwiftUI
import UniPRT
struct ContentView: View {
@State private var ipText = "10.0.10.170"
@State private var communicationType = 0 // 0 for TCP
@StateObject private var viewModel = CommunicationViewModel()
var body: some View {
NavigationView {
Form {
Section(header: Text("Connection Type")) {
Picker("Select Type", selection: $communicationType) {
Text("TCP").tag(0)
}
.pickerStyle(SegmentedPickerStyle())
}
Section(header: Text("IP Address")) {
TextField("Enter IP Address", text: $ipText)
.keyboardType(.decimalPad)
}
Section(header: Text("Output")) {
ScrollView {
Text(viewModel.resultText)
.frame(maxWidth: .infinity, alignment: .leading)
.fixedSize(horizontal: false, vertical: true)
.font(.system(size: 8))
}
.frame(height: 300)
.border(Color.secondary, width: 1)
}
Button("Connect/Close") {
viewModel.connectCloseAction(communicationType: communicationType, ip: ipText)
}
Button("Open") {
viewModel.openAction(communicationType: communicationType)
}
Button("Get Printer Info") {
viewModel.fetchPrinterInfo()
}
Button("Test ODV Monitor") {
viewModel.odvListening()
}
Button("Send Print File") {
viewModel.printTest()
}
}
.navigationBarTitle("Communication")
}
}
}
@objcMembers class CommunicationViewModel: ObservableObject {
@Published var resultText = ""
var tcpComm: TcpComm?
func openAction(communicationType: Int) {
self.resultText = "open error"
tcpComm?.open()
self.resultText = "TCP Connection opened"
}
func fetchPrinterInfo() {
let printerMonitor = PrinterMonitor(tcpComm: self.tcpComm)
let printerInfo = printerMonitor?.getPrinterInfo()
DispatchQueue.main.async {
self.resultText = "======= RFID Printer Info: \n"
self.resultText += "Printer Model: \(String(describing: printerInfo?.model))\n"
self.resultText += "Printer SN: \(String(describing: printerInfo?.serialNumber))\n"
self.resultText += "Printer FW PN: \(String(describing: printerInfo?.firmwarePartNumber))\n"
self.resultText += "Printer FW Ver: \(String(describing: printerInfo?.firmwareVersion))\n"
self.resultText += "Printhead Resolution (Dots/Inch): \(String(describing: printerInfo?.printheadResolution))\n"
self.resultText += "Has ODV: \((printerInfo?.hasOdvOption != nil) ? "Yes" : "No")\n"
}
}
func connectCloseAction(communicationType: Int, ip: String) {
if tcpComm != nil {
tcpComm?.close()
tcpComm = nil
self.resultText = "TCP Connection closed"
} else {
// Reconnect logic
tcpComm = TcpComm(ipAddress: ip, port: 3007)
self.resultText = "TCP Reconnected"
}
}
func odvListening() {
let odvMonitor = OdvMonitor(tcpComm: tcpComm)
odvMonitor?.odvReportCallback = { [weak self] report in
DispatchQueue.main.async {
var receivedString = NSMutableString()
if (report?.failed() == true) {
receivedString.append("\nBarcode Failed.")
} else {
receivedString.append("\nBarcode Passed.")
receivedString.appendFormat("Grade: %.2f", (report?.overallGradeAsFloat())!)
if report!.overallGradeAsFloat() > 3.5 {
receivedString.appendFormat("Print Quality passed. \n Overall Grade= %.2f", report!.overallGradeAsFloat())
} else {
receivedString.appendFormat("Print Quality Failed. \n Overall Grade= %.2f", report!.overallGradeAsFloat())
}
receivedString.appendFormat("Barcode Symbology: %@", report!.symbology())
receivedString.appendFormat("Barcode Data: %@", report!.data())
self?.resultText = receivedString as String
}
}
}
odvMonitor?.setOdvReportListening(true)
}
func printTest() {
let tcpComm2 = TcpComm(ipAddress: "10.0.10.178", port: 9100)
tcpComm2?.sendPrintFile("10.0.10.178", fileName: "/Users/realbuber/Documents/doc/TestOdvMonitor/DM_PRINTRONIX_1.pgl")
}
}
#Preview {
ContentView()
}