Classes and methods related to JSONMng.
@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;
TcpComm *tcpComm = [[
TcpComm alloc] initWithIPAddress:ip port:DEFAULT_MGMT_PORT];
JsonComm *jsonComm = [[JsonComm alloc] initWithComm:tcpComm commType:commType];
jsonComm.usingDataPort = YES;
NSArray<NSString *> *partOfKeys = @[@"TCP.IPAddress", @"TCP.Port"];
NSDictionary<NSString *, NSString *> *partOfValue = [settingReadWrite
getValuesForKeys:partOfKeys];
NSLog(@"Get keys::::%@", partOfValue);
NSDictionary<NSString *, Setting *> *allProperties = [settingReadWrite
getAllProperties];
NSLog(@"All properties:::%@", allProperties);
NSLog(@"Prop keys:::%@", propkeys);
NSLog(@"Property key:::%@", propkey);
NSLog(@"All config:::\r\n%@", allConfig);
CFRunLoopRun();
}
}
用於通過 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 服務器的連接。
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()