UniPRT SDK v1.0.0.0
 
载入中...
搜索中...
未找到
Mgmt

Classes and methods related to JSONMng. 更多...

class  JsonMessenger
 用于管理基于 JSON 的讯息传递的类。 更多...
 
class  JsonMng
 用于管理 JSON 讯息的类。 更多...
 

详细描述

Classes and methods related to JSONMng.

For the Objective-C example, see here.

For the Swift example, see here.

Example

Objective-C:

@import UniPRT;
#import <Foundation/Foundation.h>
#define MAX_INPUT_MSG_CAPACITY 20
#define MAX_WAIT_TIME_SECS 15
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *ip = @"10.100.15.201";
CommType commType = TCP_COMM;
// Initialize TCP communication
TcpComm *tcpComm = [[TcpComm alloc] initWithIPAddress:ip port:DEFAULT_MGMT_PORT];
[tcpComm open];
// Initialize JsonComm for TCP communication
JsonComm *jsonComm = [[JsonComm alloc] initWithComm:tcpComm commType:commType];
jsonComm.usingDataPort = YES;
// Initialize SettingsReadWrite with JsonComm
SettingsReadWrite *settingReadWrite = [[SettingsReadWrite alloc] initWithJsonComm:jsonComm];
// Example usage: Get values for specific keys
NSArray<NSString *> *partOfKeys = @[@"TCP.IPAddress", @"TCP.Port"];
NSDictionary<NSString *, NSString *> *partOfValue = [settingReadWrite getValuesForKeys:partOfKeys];
NSLog(@"Get keys::::%@", partOfValue);
// Get all properties
NSDictionary<NSString *, Setting *> *allProperties = [settingReadWrite getAllProperties];
NSLog(@"All properties:::%@", allProperties);
// Get properties for specific keys
NSDictionary<NSString *, Setting *> *propkeys = [settingReadWrite getPropertiesForKeys:partOfKeys];
NSLog(@"Prop keys:::%@", propkeys);
// Get a specific property
Setting *propkey = [settingReadWrite getPropertiesForKey:@"TCP.IPAddress"];
NSLog(@"Property key:::%@", propkey);
// Initialize JsonConfig with JsonComm for configuration handling
JsonConfig *jsonconfig = [[JsonConfig alloc] initWithJsonComm:jsonComm];
// Get all configurations
NSArray<Config *> *allConfig = [jsonconfig getAllConfig];
NSLog(@"All config:::\r\n%@", allConfig);
CFRunLoopRun(); // Keeps the application running
}
}
用于通过 JSON 通信管理配置的类。
Definition JsonConfig.h:39
NSArray< Config * > * getAllConfig()
JsonConfig 对象的析构函数。
表示具有各种属性的可配置设置的类。
Definition Setting.h:33
支持读取和写入印表机设置。
Definition SettingsReadWrite.h:71
NSDictionary< NSString *, Setting * > * getPropertiesForKeys:(NSArray< NSString * > *keys)
读取与给定键列表关联的设置。
NSDictionary< NSString *, Setting * > * getAllProperties()
读取所有设置。
Setting * getPropertiesForKey:(NSString *key)
读取与给定键列表关联的多个设置。
NSDictionary< NSString *, NSString * > * getValuesForKeys:(NSArray< NSString * > *keys)
读取与给定键列表关联的多个设置。
一个用于 TCP 通信的类,继承自 AComm 并符合 NSStreamDelegate 协议。
Definition TcpComm.h:101
void open()
打开与 TCP 服务器的连接。

Swift:

import Foundation
import UniPRT
let MAX_INPUT_MSG_CAPACITY = 20
let MAX_WAIT_TIME_SECS = 15
func main() {
//// TCP Connection example
let ip = "10.0.10.170"
let commType = CommType.TCP_COMM
if let comm = TcpComm(ipAddress: ip, port: UInt(DEFAULT_MGMT_PORT)) {
comm.open()
// let jsonMessenger = JsonMessenger(commToPtr: comm, iCommTyp: commType, maxInputMsgCapacity: Int32(MAX_INPUT_MSG_CAPACITY), usingDataPort: false)
//
// if let jsonMessenger = jsonMessenger {
// let command = "Cfg.Prop"
// let content = "{\n\"all\" : null\n}\n"
//
// print("\nSend to Printer:\n\"Command\": \"\‍(command)\"\n\"Content\":\n\‍(content)")
//
// if let trackNumber = jsonMessenger.sendMsgAndWaitForResponse(withCommand: command, content: content, maxWaitTimeSecs: Int32(MAX_WAIT_TIME_SECS)) {
// let receivedString = trackNumber.strResponse
// print("receivedString: \‍(receivedString ?? "")")
//
// }
// }
//
let jsonComm = JsonComm(comm: comm, commType: commType.rawValue)
jsonComm?.usingDataPort = true
let settingReadWrite = SettingsReadWrite(jsonComm: jsonComm)
// let settingReadWrite = SettingsReadWrite(tcpComm: comm)
// if let setting = settingReadWrite?.setValue("eJustWork", forKey: "BT.PairMethod"){
// print("setValue:::: \‍(setting)")
// }
//
// if let settings = settingReadWrite?.setValues(["BT.PairMethod":"eNumericComp","BT.ConnectName":"BT-PTX3"]){
// print("setValues:::: \‍(settings)")
// }
//
// let partOfKeys = ["BT.PairMethod", "BT.ConnectName"]
//
// if let propkey = settingReadWrite?.getPropertiesForKey("BT.PairMethod"){
// print("getPropertiesForKey:::\‍(String(describing: propkey))")
// }
//
//
// if let partOfValue = settingReadWrite?.getValuesForKeys(partOfKeys) {
// print("getValuesForKeys:::: \‍(partOfValue)")
// }
//
// if let AllValue = settingReadWrite?.getAllValues(){
// print("getAllValues:::: \‍(AllValue)")
// }
//
// if let partOfValue = settingReadWrite?.getValuesForKeys(partOfKeys) {
// print("getValuesForKeys:::: \‍(partOfValue)")
// }
//
// if let propKeys = settingReadWrite?.getPropertiesForKeys(partOfKeys) {
// print("getPropertiesForKeys::: \‍(propKeys)")
// }
if let allProperties = settingReadWrite?.getAllProperties() {
print("getAllProperties::: \‍(allProperties)")
}
let jsonconfig = JsonConfig(jsonComm: jsonComm)
//
// let config = jsonconfig?.getWithNumber(1)
//
// print("Config: \‍(String(describing: config))")
//
//
// config?.setName("123")
// config?.setNumber(1)
// config?.setModel("T820")
// let success = jsonconfig?.setConfig(config)
//
// if success == true {
// print("Configuration set successfully.")
// } else {
// print("Failed to set configuration.")
// }
//
// let tempConfig: Config? = config
// print("tempConfig:::\‍(String(describing: tempConfig))")
// let allCfg = jsonconfig?.getAllConfig()
// print("allConfig:::\‍(String(describing: allCfg))")
}
}
main()