UniPRT SDK v1.0.0.0
 
Loading...
Searching...
No Matches
Mgmt

Classes and methods related to JSONMng. More...

Classes

class  JsonMessenger
 A class for managing JSON-based messaging. More...
 
class  JsonMng
 A class for managing JSON messages. More...
 

Detailed Description

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
}
}
A class for managing configuration through JSON communication.
Definition JsonConfig.h:39
NSArray< Config * > * getAllConfig()
Destructor for the JsonConfig object.
A class representing a configurable setting with various properties.
Definition Setting.h:33
Support for reading and writing printer settings.
Definition SettingsReadWrite.h:71
NSDictionary< NSString *, Setting * > * getPropertiesForKeys:(NSArray< NSString * > *keys)
Read settings associated with given list of keys.
NSDictionary< NSString *, Setting * > * getAllProperties()
Read all settings.
Setting * getPropertiesForKey:(NSString *key)
Read multiple settings associated with given list of keys.
NSDictionary< NSString *, NSString * > * getValuesForKeys:(NSArray< NSString * > *keys)
Read multiple settings associated with given list of keys.
A class for TCP communication, inheriting from AComm and conforming to the NSStreamDelegate protocol.
Definition TcpComm.h:101
void open()
Opens the connection to the TCP server.

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