Hallo Forum,
ich brauche Hilfe1
Ich baue gerade an meiner ersten App und möchte mit einem Windows-SocketServer kommunizieren und Telegramme austauschen. Die Kommunikation funktioniert. Die Telegramme welche ausgetauscht werden, sind in einen Header und einen Datenbereich unterteilt. Der Datenbereich besteht aus einer Union. Die Telegramme beinhalten auch eine CheckSumme, die beim Erhalten des Telegramms berechnet und später kontrolliert wird. Da die Telegrammlänge durch die Union nun variable ist, muss meine Telegrammauswertung in einer Endlosschleife laufen, da ich ja nicht immer ein komplettes Telegramm aus dem Stream erhalte. Eventuell lese ich nur ein ganzes und ein halbes Telegramm aus. Beim nächsten Lesen des Streams wird dann der Rest des letzten Telegramms verarbeitet.
Die While-Schleife, die das Auslesen aus dem Stream macht, wird über eine NSOperation und NSOperationQueu aus AppDelegatee gestartet.
Beim Erhalt eines gültigen Telegramms wird dann eine NSNotification ausgelöst. Ein ViewController fängt diese Notification und ruft damit eine Methode auf, welche verschiedene NSLogs schreibt und den ViewController updaten soll.
Dieses alles funktioniert:
Es werden NSLogs mit den erwarteten Werten ausgegeben. _ Nur: Der ViewController wird NICHT upgedatet !!!
Wenn ich den Empfang des Telegramms ohne NSOperation durchführe, funktioniert das Updaten des ViewControllers.
Vielleicht hat jemand eine Idee?
Hier mal der QuellcodeAuszug:
Alles anzeigen
Alles anzeigen
Alles anzeigen
ich brauche Hilfe1
Ich baue gerade an meiner ersten App und möchte mit einem Windows-SocketServer kommunizieren und Telegramme austauschen. Die Kommunikation funktioniert. Die Telegramme welche ausgetauscht werden, sind in einen Header und einen Datenbereich unterteilt. Der Datenbereich besteht aus einer Union. Die Telegramme beinhalten auch eine CheckSumme, die beim Erhalten des Telegramms berechnet und später kontrolliert wird. Da die Telegrammlänge durch die Union nun variable ist, muss meine Telegrammauswertung in einer Endlosschleife laufen, da ich ja nicht immer ein komplettes Telegramm aus dem Stream erhalte. Eventuell lese ich nur ein ganzes und ein halbes Telegramm aus. Beim nächsten Lesen des Streams wird dann der Rest des letzten Telegramms verarbeitet.
Die While-Schleife, die das Auslesen aus dem Stream macht, wird über eine NSOperation und NSOperationQueu aus AppDelegatee gestartet.
Beim Erhalt eines gültigen Telegramms wird dann eine NSNotification ausgelöst. Ein ViewController fängt diese Notification und ruft damit eine Methode auf, welche verschiedene NSLogs schreibt und den ViewController updaten soll.
Dieses alles funktioniert:
Es werden NSLogs mit den erwarteten Werten ausgegeben. _ Nur: Der ViewController wird NICHT upgedatet !!!
Wenn ich den Empfang des Telegramms ohne NSOperation durchführe, funktioniert das Updaten des ViewControllers.
Vielleicht hat jemand eine Idee?
Hier mal der QuellcodeAuszug:
Quellcode
- #import "AppDelegate.h"
- #import "Communicator.h"
- @interface AppDelegate ()
- @property Communicator *communicator;
- @end
- @implementation AppDelegate
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- // create, init and open communication
- self.communicator = [Communicator new];
- self.communicator->host = @"192.168.14.184";
- self.communicator->port = 700;
- self.communicator->clientIP = @"10.0.10.117";
- self.communicator->loggedInUser = @"Apple";
- self.communicator->stationName = @"iPhone5s";
- [self.communicator startCommunicator];
- // init communicator queue
- NSOperationQueue* communicatorQueue = [NSOperationQueue new];
- // start communicator
- [communicatorQueue addOperation:self.communicator];
- return YES;
- }
Quellcode
- #import <UIKit/UIKit.h>
- @interface StoreUtilizationViewController : UIViewController
- @property (strong, nonatomic) IBOutlet UISlider *sliderUtilizationTotal;
- @property (strong, nonatomic) IBOutlet UISlider *sliderUtilizationZL1;
- @property (strong, nonatomic) IBOutlet UISlider *sliderUtilizationZL2;
- @property (strong, nonatomic) IBOutlet UISlider *sliderUtilizationRL;
- @property (strong, nonatomic) IBOutlet UILabel *labelStoreUtilizationTotal;
- @property (strong, nonatomic) IBOutlet UILabel *labelStoreUtilizationZL1;
- @property (strong, nonatomic) IBOutlet UILabel *labelStoreUtilizationZL2;
- @property (strong, nonatomic) IBOutlet UILabel *labelStoreUtilizationRL;
- @property (strong, nonatomic) IBOutlet UILabel *labelUpdateDescription;
- @property (strong, nonatomic) IBOutlet UILabel *labelProcentTotal;
- @property (strong, nonatomic) IBOutlet UILabel *labelProcentZL1;
- @property (strong, nonatomic) IBOutlet UILabel *labelProcentZL2;
- @property (strong, nonatomic) IBOutlet UILabel *labelProcentRL;
- @property (strong, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicatorView;
- @property (strong, nonatomic) IBOutlet UIProgressView *progressBarStoreUtilization;
- - (void) processTelegram: (NSNotification*) notifaction;
- @end
Quellcode
- #import "StoreUtilizationViewController.h"
- #import "StoreUtilization.h"
- @interface StoreUtilizationViewController ()
- @property NSTimer* timer;
- @property int timerTick;
- @end
- @implementation StoreUtilizationViewController
- - (void)viewDidLoad
- {
- // set slider
- self.sliderUtilizationTotal.minimumValue = 0;
- self.sliderUtilizationTotal.maximumValue = 100;
- self.sliderUtilizationZL1.minimumValue = 0;
- self.sliderUtilizationZL1.maximumValue = 100;
- self.sliderUtilizationZL2.minimumValue = 0;
- self.sliderUtilizationZL2.maximumValue = 100;
- self.sliderUtilizationRL.minimumValue = 0;
- self.sliderUtilizationRL.maximumValue = 100;
- // set label
- self.labelStoreUtilizationTotal.text = @"Total:";
- self.labelStoreUtilizationZL1.text = @"Intermediate store 1:";
- self.labelStoreUtilizationZL2.text = @"Intermediate store 2:";
- self.labelStoreUtilizationRL.text = @"Back store:";
- self.labelProcentTotal.text = @"0 %";
- self.labelProcentZL1.text = @"0 %";
- self.labelProcentZL2.text = @"0 %";
- self.labelProcentRL.text = @"0 %";
- // start activityIndicatorView
- CGAffineTransform transform = CGAffineTransformMakeScale(2.0f, 2.0f);
- self.activityIndicatorView.transform = transform;
- [self.activityIndicatorView startAnimating];
- self.activityIndicatorView.hidden = NO;
- self.timerTick = 0;
- [self startTimer];
- // add observer
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(processTelegram:) name:@"STOREUTILIZATION" object:nil];
- }
- - (void) viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [self stopTimer];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:@"STOREUTILIZATION" object:nil];
- }
- -(void) processTelegram: (NSNotification*) notifaction
- {
- StoreUtilization *storeUtilization = [[notifaction userInfo] valueForKey:@"SEARCHKEY"];
- NSLog(@"###########################################################");
- NSLog(@"######### Received Notification - telegram = %d", [storeUtilization nTotal]);
- NSLog(@"######### Received Notification - telegram = %d", [storeUtilization nRL]);
- NSLog(@"######### Received Notification - telegram = %d", [storeUtilization nZL1]);
- NSLog(@"######### Received Notification - telegram = %d", [storeUtilization nZL2]);
- // set slider
- [self.sliderUtilizationTotal setValue:storeUtilization.nTotal animated:YES];
- [self.sliderUtilizationZL1 setValue:storeUtilization.nZL1 animated:YES];
- [self.sliderUtilizationZL2 setValue:storeUtilization.nZL2 animated:YES];
- [self.sliderUtilizationRL setValue:storeUtilization.nRL animated:YES];
- // set progress bar ticker
- self.timerTick = 0;
- // set label
- NSString *string = [NSString stringWithFormat:@"%d %%", storeUtilization.nTotal];
- self.labelProcentTotal.text = string;
- string = [NSString stringWithFormat:@"%d %%", storeUtilization.nZL1];
- self.labelProcentZL1.text = string;
- string = [NSString stringWithFormat:@"%d %%", storeUtilization.nZL2];
- self.labelProcentZL2.text = string;
- string = [NSString stringWithFormat:@"%d %%", storeUtilization.nRL];
- self.labelProcentRL.text = string;
- if( storeUtilization.nTotal > STOREUTILIZATION_RED )
- { self.labelProcentTotal.textColor = [UIColor redColor];
- }
- else if ( storeUtilization.nTotal > STOREUTILIZATION_YELLOW )
- { self.labelProcentTotal.textColor = [UIColor orangeColor];
- }
- else
- { self.labelProcentTotal.textColor = [UIColor blackColor];
- }
- if( storeUtilization.nZL1 > STOREUTILIZATION_RED )
- { self.labelProcentZL1.textColor = [UIColor redColor];
- }
- else if ( storeUtilization.nZL1 > STOREUTILIZATION_YELLOW )
- { self.labelProcentZL1.textColor = [UIColor orangeColor];
- }
- else
- { self.labelProcentZL1.textColor = [UIColor blackColor];
- }
- if( storeUtilization.nZL2 > STOREUTILIZATION_RED )
- { self.labelProcentZL2.textColor = [UIColor redColor];
- }
- else if ( storeUtilization.nZL2 > STOREUTILIZATION_YELLOW )
- { self.labelProcentZL2.textColor = [UIColor orangeColor];
- }
- else
- { self.labelProcentZL2.textColor = [UIColor blackColor];
- }
- if( storeUtilization.nRL > STOREUTILIZATION_RED )
- { self.labelProcentRL.textColor = [UIColor redColor];
- }
- else if ( storeUtilization.nRL > STOREUTILIZATION_YELLOW )
- { self.labelProcentRL.textColor = [UIColor orangeColor];
- }
- else
- { self.labelProcentRL.textColor = [UIColor blackColor];
- }
- // start activityIndicatorView
- [self.activityIndicatorView stopAnimating];
- self.activityIndicatorView.hidden = YES;
- //
- // Bis hier sind alle Variablen richtig gefüllt und es entsteht kein Fehler!!!
- //****************************************************************************************
- }
- - (void)startTimer
- {
- self.timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(tickProgressBar) userInfo:nil repeats:YES];
- }
- - (void)stopTimer
- {
- [self.timer invalidate];
- }
- - (void)tickProgressBar
- {
- self.timerTick++;
- if (self.timerTick <= 30)
- { self.progressBarStoreUtilization.progress = (float) self.timerTick / 30.0f;
- }
- else
- { self.progressBarStoreUtilization.progress = 0;
- self.timerTick = 0;
- }
- }
- - (NSUInteger) supportedInterfaceOrientations
- {
- return UIInterfaceOrientationMaskPortrait;
- }
- @end