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()