AppController.m 22.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
#import "AppController.h"
#import "AsyncSocket.h"

#define WELCOME_MSG  0
#define ECHO_MSG     1

#define FORMAT(format, ...) [NSString stringWithFormat:(format), ##__VA_ARGS__]

@interface AppController (PrivateAPI)
- (void)logError:(NSString *)msg;
- (void)logInfo:(NSString *)msg;
- (void)logMessage:(NSString *)msg;
@end


@implementation AppController

//@synthesize DisConnectButton = DisconectButton ;

- (id)init
{
	if(self = [super init])
	{
		listenSocket = [[AsyncSocket alloc] initWithDelegate:self];
        acceptSocket = nil;//[[AsyncSocket alloc] init] ;
		connectedSockets = [[NSMutableArray alloc] initWithCapacity:1];
        
      
        
       // [portField intValue] = 6000;

        
      //it is running or not.	  
		isRunning = NO;
	}
	return self;
}

- (void)awakeFromNib
{
	[logView setString:@""];
    [ConnectButton setEnabled:YES] ; 
    [DisConnectButton setEnabled:NO] ;
    portField.stringValue  = @"6000";
    
    [scanButton setEnabled:NO] ;
    [swipButton setEnabled:NO] ;
    
//    NSTableColumn *firstNameColumn = [barcodetableView tableColumnWithIdentifier:@"barcode"];
//	[firstNameColumn bind:@"value" toObject:mybarcodeContentArray withKeyPath:@"arrangedObjects.barcode" options:nil];
    
    //for barcode setting listview.
    [self startStop:nil] ;
    
    [settingbutton setEnabled:NO] ;
    
    NSArray *barcodearray = [[NSUserDefaults standardUserDefaults] objectForKey:USER_DEFAULT_BARCODE_S];
    [mybarcodeContentArray removeObjects:barcodearray] ;
    for (NSDictionary *dict in barcodearray) {
        [mybarcodeContentArray addObject: dict];
    }
    
    NSArray *msrarray = [[NSUserDefaults standardUserDefaults] objectForKey:USER_DEFAULT_MSR_S] ;
    [myMSRContentArray removeObjects:msrarray] ;
    for (NSDictionary *dict in msrarray) {
        [myMSRContentArray addObject:dict] ;
    }

    
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
	NSLog(@"Ready");
	
	// Advanced options - enable the socket to contine operations even during modal dialogs, and menu browsing
	[listenSocket setRunLoopModes:[NSArray arrayWithObject:NSRunLoopCommonModes]];
}

- (void)scrollToBottom
{
	NSScrollView *scrollView = [logView enclosingScrollView];
	NSPoint newScrollOrigin;
	
	if ([[scrollView documentView] isFlipped])
		newScrollOrigin = NSMakePoint(0.0, NSMaxY([[scrollView documentView] frame]));
	else
		newScrollOrigin = NSMakePoint(0.0, 0.0);
	
	[[scrollView documentView] scrollPoint:newScrollOrigin];
}

- (void)logError:(NSString *)msg
{
	NSString *paragraph = [NSString stringWithFormat:@"%@\n", msg];
	
	NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1];
	[attributes setObject:[NSColor redColor] forKey:NSForegroundColorAttributeName];
	
	NSAttributedString *as = [[NSAttributedString alloc] initWithString:paragraph attributes:attributes];
	[as autorelease];
	
	[[logView textStorage] appendAttributedString:as];
	[self scrollToBottom];
}

- (void)logInfo:(NSString *)msg
{
	NSString *paragraph = [NSString stringWithFormat:@"%@\n", msg];
	
	NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1];
	[attributes setObject:[NSColor purpleColor] forKey:NSForegroundColorAttributeName];
	
	NSAttributedString *as = [[NSAttributedString alloc] initWithString:paragraph attributes:attributes];
	[as autorelease];
	
	[[logView textStorage] appendAttributedString:as];
	[self scrollToBottom];
}

- (void)logMessage:(NSString *)msg
{
	NSString *paragraph = [NSString stringWithFormat:@"%@\n", msg];
	
	NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithCapacity:1];
	[attributes setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
	
	NSAttributedString *as = [[NSAttributedString alloc] initWithString:paragraph attributes:attributes];
	[as autorelease];
	
	[[logView textStorage] appendAttributedString:as];
	[self scrollToBottom];
}

- (IBAction)startStop:(id)sender
{
	if(!isRunning)
	{
		int port = [portField intValue];
		
		if(port < 0 || port > 65535)
		{
			port = 0;
		}
		[listenSocket disconnect] ;
        
		for(int i = 0; i < [connectedSockets count]; i++)
		{
			// Call disconnect on the socket,
			// which will invoke the onSocketDidDisconnect: method,
			// which will remove the socket from the list.
			[[connectedSockets objectAtIndex:i] disconnect];
		}

        
		NSError *error = nil;
		if(![listenSocket acceptOnPort:port error:&error])
		{
			[self logError:FORMAT(@"Error starting server: %@", error)];
			return;
		}
		
		[self logInfo:FORMAT(@"Captuvo Emulator Controller server started on port %hu", [listenSocket localPort])];
		isRunning = YES;
		
		[portField setEnabled:NO];
		[startStopButton setTitle:@"Stop Server"];

	}
	else
	{
		// Stop accepting connections
		[listenSocket disconnect];
			
		// Stop any client connections
		int i;
		for(i = 0; i < [connectedSockets count]; i++)
		{
			// Call disconnect on the socket,
			// which will invoke the onSocketDidDisconnect: method,
			// which will remove the socket from the list.
			[[connectedSockets objectAtIndex:i] disconnect];
		}
		
		[self logInfo:@"Stopped Captuvo Emulator Controller Server"];
		isRunning = false;
		
		[portField setEnabled:YES];
		[startStopButton setTitle:@"Start Server"];
	}
}

- (IBAction)scanAction:(id)sender
{
//    NSString *sendstring = @"HoneywellCommand10:123456789" ;
//    NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
//    
//    if (acceptSocket)
//    {
//        [acceptSocket writeData:data withTimeout:-1 tag:1] ;
//    }
    
    NSString *sendstring = @"HoneywellCommand00:" ;
    NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
    
    if (acceptSocket)
    {
      [acceptSocket writeData:data withTimeout:-1 tag:1] ;
    }
    
}

- (IBAction)SwipeCardAction:(id)sender
{
//        NSString *sendstring = @"HoneywellCommand00:" ;
//        NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
//    
//        if (acceptSocket)
//        {
//          [acceptSocket writeData:data withTimeout:-1 tag:1] ;
//        }
    
    NSString *sendstring = @"HoneywellCommand01:" ;
    
    NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
    {
      [acceptSocket writeData:data withTimeout:-1 tag:1] ;
    }
    
}

- (IBAction)NotificationConnectAction:(id)sender
{
    [DisConnectButton  setEnabled:YES];
    [ConnectButton  setEnabled:NO];
    [settingbutton setEnabled:YES] ;
    NSString *sendstring = @"HoneywellCommand02:" ;
    NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
    
    if (acceptSocket)
    {
      [acceptSocket writeData:data withTimeout:-1 tag:1] ;
    }

}

- (IBAction)NotificationDisConnectAction:(id)sender
{
    [ConnectButton  setEnabled:YES];
    [DisConnectButton setEnabled:NO] ;
    [settingbutton setEnabled:NO] ;
    
    
    NSString *sendstring = @"HoneywellCommand03:" ;
    NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
    
    if (acceptSocket)
    {
      [acceptSocket writeData:data withTimeout:-1 tag:1] ;
    }

}

- (IBAction)setAccessoryname:(id)sender
{
    NSString *sendstring =[NSString stringWithFormat:@"HoneywellCommand04:%@",sender] ;
    
    NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
    
    if (acceptSocket)
    {
        [acceptSocket writeData:data withTimeout:-1 tag:1] ;
    }
}

- (IBAction)setManufacture:(id)sender
{
    NSString *sendstring =[NSString stringWithFormat:@"HoneywellCommand05:%@",sender] ;
    NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
    
    if (acceptSocket)
    {
        [acceptSocket writeData:data withTimeout:-1 tag:1] ;
    }
}

- (IBAction)setModelNumber:(id)sender
{
    NSString *sendstring =[NSString stringWithFormat:@"HoneywellCommand06:%@",sender];
    NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
    
    if (acceptSocket)
    {
        [acceptSocket writeData:data withTimeout:-1 tag:1] ;
    }
}

- (IBAction)setSerialNumber:(id)sender
{
    NSString *sendstring =[NSString stringWithFormat:@"HoneywellCommand07:%@",sender];
    NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
    
    if (acceptSocket)
    {
        [acceptSocket writeData:data withTimeout:-1 tag:1] ;
    }
}

- (IBAction)setFirmwareRev:(id)sender
{
    
    NSString *sendstring =[NSString stringWithFormat:@"HoneywellCommand08:%@",sender];
    NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
    
    if (acceptSocket)
    {
        [acceptSocket writeData:data withTimeout:-1 tag:1] ;
    }
}

-(IBAction)setHardwareRev:(id)sender
{
    NSString *sendstring =[NSString stringWithFormat:@"HoneywellCommand09:%@",sender];
    NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
    
    if (acceptSocket)
    {
        [acceptSocket writeData:data withTimeout:-1 tag:1] ;
    }
}

-(IBAction)setSDKRev:(id)sender
{
    NSString *sendstring =[NSString stringWithFormat:@"HoneywellCommand10:%@",sender];
    NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
    
    if (acceptSocket)
    {
        [acceptSocket writeData:data withTimeout:-1 tag:1] ;
    }
}


- (IBAction)setBarcodeData:(id)sender
{
    NSString *sendstring = @"HoneywellCommand11:123456789" ;
    NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
    
    if (acceptSocket)
    {
        [acceptSocket writeData:data withTimeout:-1 tag:1] ;
    }
}

- (IBAction)setMsrData:(id)sender
{
    NSString *sendstring = @"HoneywellCommand12:0000123456789" ;
    NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
    
    if (acceptSocket)
    {
        [acceptSocket writeData:data withTimeout:-1 tag:1] ;
    }
}


- (IBAction)settingAction:(id)sender
{
     NSMutableArray*existbarArray = (NSMutableArray*)[mybarcodeContentArray arrangedObjects] ;
    
     NSMutableArray *existMsrobjsArray = (NSMutableArray*)[myMSRContentArray arrangedObjects] ;
    
   if(([existbarArray count] <=0) &&  ([existMsrobjsArray count] <=0))
   {
       NSAlert *alert=[NSAlert alertWithMessageText:@"warning" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"barcode list or msr list is empty currently, you should input some data."];
       [alert beginSheetModalForWindow:nil modalDelegate:self didEndSelector:@selector(alertEnded:code:context:) contextInfo:nil];
       return;

   }
    
    [settingbutton setEnabled:NO] ;
    
    [self barcodeConfigAction:nil] ;
    [self msrConfigAction:nil] ;
}


- (void)onSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket
{
   // if (!acceptSocket) {
       acceptSocket = [newSocket retain] ;
        NSLog(@"did accept new socket") ;
   // }
	[connectedSockets addObject:newSocket];
}

- (NSRunLoop *)onSocket:(AsyncSocket *)sock wantsRunLoopForNewSocket:(AsyncSocket *)newSocket{
    NSLog(@"wants runloop for new socket.");
    return [NSRunLoop currentRunLoop];
}

- (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port
{
	[self logInfo:FORMAT(@"Accepted client %@:%hu", host, port)];
	
//	NSString *welcomeMsg = @"Welcome to the AsyncSocket Captuvo Simulator Controller\r\n";
//	NSData *welcomeData = [welcomeMsg dataUsingEncoding:NSUTF8StringEncoding];
	
//	[sock writeData:welcomeData withTimeout:-1 tag:WELCOME_MSG];
    [self NotificationConnectAction:nil] ;
    
    
     NSLog(@"did connect to host");
     if (acceptSocket)
     {
	     [acceptSocket readDataWithTimeout:-1 tag:1] ;
        
     }
    
    [self configureMFG:nil] ;
    
	// We could call readDataToData:withTimeout:tag: here - that would be perfectly fine.
	// If we did this, we'd want to add a check in onSocket:didWriteDataWithTag: and only
	// queue another read if tag != WELCOME_MSG.
}

//- (void)onSocket:(AsyncSocket *)sock didWriteDataWithTag:(long)tag
//{
//	[sock readDataToData:[AsyncSocket CRLFData] withTimeout:-1 tag:0];
//}

- (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
{
//	NSData *strData = [data subdataWithRange:NSMakeRange(0, [data length] - 2)];
//	NSString *msg = [[[NSString alloc] initWithData:strData encoding:NSUTF8StringEncoding] autorelease];
//	if(msg)
//	{
//		[self logMessage:msg];
//	}
//	else
//	{
//		[self logError:@"Error converting received data into UTF-8 String"];
//	}
//	
//	// Even if we were unable to write the incoming data to the log,
//	// we're still going to echo it back to the client.
//	[sock writeData:data withTimeout:-1 tag:ECHO_MSG];
    
    NSLog(@"did read data");
    NSString* message = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
    NSLog(@"message is: \n%@",message);
    
    [self logInfo:message] ;
//    [acceptSocket writeData:data withTimeout:-1 tag:1];
}

- (void)onSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err
{
	[self logInfo:FORMAT(@"Client Disconnected: %@:%hu", [sock connectedHost], [sock connectedPort])];
}


- (void)onSocket:(AsyncSocket *)sock didWriteDataWithTag:(long)tag{
    NSLog(@"message did write");
    if (acceptSocket)
    {
       [acceptSocket readDataWithTimeout:-1 tag:1];
    }
}

- (void)onSocketDidDisconnect:(AsyncSocket *)sock
{
    
    [DisConnectButton  setEnabled:NO];
    [ConnectButton  setEnabled:YES];
    [scanButton setEnabled:NO] ;
    [swipButton setEnabled:NO] ;
    [settingbutton setEnabled:NO] ;    
//    NSInteger indexofitem = [tabView indexOfTabViewItem:barcodeItem] ;
//    if (indexofitem!=NSNotFound) {
//        [tabView removeTabViewItem:barcodeItem] ;
//    }
//    
//    indexofitem = [tabView indexOfTabViewItem:msrItem] ;
//    if (indexofitem!=NSNotFound) {
//        [tabView removeTabViewItem:msrItem] ;
//    }

    NSLog(@"socket did disconnect");
    [acceptSocket release];
    acceptSocket=nil;
    
}

#pragma mark ---
#pragma barcode data setting.

- (void)updateClientBarcodelist:(NSString*)barcodelist
{
    //barcodelist separate by '--';
    NSString *sendstring = nil;
    if ([barcodelist length]==0) {
       sendstring = [NSString stringWithFormat:@"HoneywellCommand11:"];
    }else{
       sendstring =  [NSString stringWithFormat:@"HoneywellCommand11:%@",barcodelist];
    }
    
    NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
    
    if (acceptSocket)
    {
        [acceptSocket writeData:data withTimeout:-1 tag:1] ;
    }

}

-(void)alertEnded:(NSAlert *)alert code:(int)choice context:(void *)v{
 if (choice==NSAlertDefaultReturn) {
        NSLog(@"----------------0");
    } else if(choice==NSAlertAlternateReturn){
        NSLog(@"----------------1");
    }
}
- (IBAction)AddnewBarContentcode:(id)sender
{
    NSMutableArray *existobjsArray = (NSMutableArray*)[mybarcodeContentArray arrangedObjects] ;
    //add complete should clear the barcodeField value.
    NSLog(@"%@",existobjsArray) ;
    
    NSString *barcodevalue = barcodeField.stringValue ;
    if (barcodevalue==nil||[barcodevalue length]==0) {
        NSAlert *alert=[NSAlert alertWithMessageText:@"Add barcode warning" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"You should input content into barcode field to add barcode list."];
        [alert beginSheetModalForWindow:nil modalDelegate:self didEndSelector:@selector(alertEnded:code:context:) contextInfo:nil];
        return ;
    }
    
    NSDictionary *addDictionary = [NSDictionary dictionaryWithObject:barcodevalue forKey:@"barcode"] ;
    
    if([existobjsArray containsObject:addDictionary]){
        NSAlert *alert=[NSAlert alertWithMessageText:@"Add barcode warning" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"You input barcode duplicate, please add a new different barcode content."];
        [alert beginSheetModalForWindow:nil modalDelegate:self didEndSelector:@selector(alertEnded:code:context:) contextInfo:nil];
        
        return ;
    }
    [mybarcodeContentArray addObject:addDictionary];
    
    [[NSUserDefaults standardUserDefaults] setObject:existobjsArray forKey:USER_DEFAULT_BARCODE_S] ;
    [barcodeField setStringValue:@""] ;
    
    [self barcodeConfigAction:nil] ;
//    NSString *barcodelist = nil;
//    for (NSDictionary *subdict in existobjsArray) {
//        if (barcodelist==nil||[barcodelist length]==0) {
//            barcodelist = [subdict objectForKey:@"barcode"] ;
//        }else{
//            barcodelist = [NSString stringWithFormat:@"%@--%@",barcodelist,[subdict objectForKey:@"barcode"]];
//        }
//    }
//    //send to client to update the current newest barcode list.
//    [self updateClientBarcodelist:barcodelist] ;
    
}
- (IBAction)RemoveBarContentcode:(id)sender
{
   int selectindex =  barcodetableView.selectedRow  ;
    if (selectindex>=0) {
        [mybarcodeContentArray removeObjectAtArrangedObjectIndex:selectindex] ;
        NSMutableArray*existArray = (NSMutableArray*)[mybarcodeContentArray arrangedObjects] ;
        [[NSUserDefaults standardUserDefaults] setObject:existArray forKey:USER_DEFAULT_BARCODE_S] ;
        [self barcodeConfigAction:nil] ;
    }else{
        NSAlert *alert=[NSAlert alertWithMessageText:@"Remove barcode warning" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"barcode list is empty currently, you can not do remove action."];
        [alert beginSheetModalForWindow:nil modalDelegate:self didEndSelector:@selector(alertEnded:code:context:) contextInfo:nil];
    }

}

- (IBAction)barcodeConfigAction:(id)sender
{
    NSMutableArray*existArray = (NSMutableArray*)[mybarcodeContentArray arrangedObjects] ;
    NSString *barcodelist = nil;
    for (NSDictionary *subdict in existArray) {
        if (barcodelist==nil||[barcodelist length]==0) {
            barcodelist = [subdict objectForKey:@"barcode"] ;
        }else{
            barcodelist = [NSString stringWithFormat:@"%@--%@",barcodelist,[subdict objectForKey:@"barcode"]];
        }
    }
    //send to client to update the current newest barcode list.
    [self updateClientBarcodelist:barcodelist] ;

    [scanButton setEnabled:YES] ; 
}

#pragma mark ----
#pragma msr data setting.
- (void)updateClientMSRList:(NSString*)msrList
{
    //barcodelist separate by '--';
    NSString *sendstring = nil;
    if ([msrList length]==0) {
        sendstring = [NSString stringWithFormat:@"HoneywellCommand12:"];
    }else{
        sendstring =  [NSString stringWithFormat:@"HoneywellCommand12:%@",msrList];
    }
    
    NSData *data = [sendstring dataUsingEncoding:NSUTF8StringEncoding] ;
    
    if (acceptSocket)
    {
        [acceptSocket writeData:data withTimeout:-1 tag:1] ;
    }

}
- (IBAction)AddnewMSRContent:(id)sender
{
    NSMutableArray *existobjsArray = (NSMutableArray*)[myMSRContentArray arrangedObjects] ;
    //add complete should clear the barcodeField value.
    NSLog(@"%@",existobjsArray) ;

    NSString *msrValue = msrField.stringValue ;
    if (msrValue==nil||[msrValue length]==0) {
        NSAlert *alert=[NSAlert alertWithMessageText:@"Add msr content warning" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"You should input content into msr field to add msr list."];
        [alert beginSheetModalForWindow:nil modalDelegate:self didEndSelector:@selector(alertEnded:code:context:) contextInfo:nil];

        return ;
    }
    NSDictionary *addDictionary = [NSDictionary dictionaryWithObject:msrValue forKey:@"msr"] ;
    if([existobjsArray containsObject:addDictionary]){
        NSAlert *alert=[NSAlert alertWithMessageText:@"Add msr warning" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"You input msr duplicate, please add a new different msr content."];
        [alert beginSheetModalForWindow:nil modalDelegate:self didEndSelector:@selector(alertEnded:code:context:) contextInfo:nil];
        return ;
    }
    [myMSRContentArray addObject:addDictionary];
    
    [[NSUserDefaults standardUserDefaults] setObject:existobjsArray forKey:USER_DEFAULT_MSR_S] ;
    //add complete should clear the barcodeField value.
    [msrField setStringValue:@""] ;
    
    [self msrConfigAction:nil] ;
//    NSString *msrlist = nil;
//    for (NSDictionary *subdict in existobjsArray) {
//        if (msrlist==nil||[msrlist length]==0) {
//            msrlist = [subdict objectForKey:@"msr"] ;
//        }else{
//            msrlist = [NSString stringWithFormat:@"%@--%@",msrlist,
//                           [subdict objectForKey:@"msr"]];
//        }
//    }
//    //send to client to update the current newest barcode list.
//    [self updateClientMSRList:msrlist] ;

}

- (IBAction)RemoveMSRContent:(id)sender
{
    int selectindex =  msrTableView.selectedRow  ;
    if (selectindex>=0) {
        [myMSRContentArray removeObjectAtArrangedObjectIndex:selectindex] ;
        NSMutableArray *existobjsArray = (NSMutableArray*)[myMSRContentArray arrangedObjects] ;
        [[NSUserDefaults standardUserDefaults] setObject:existobjsArray forKey:USER_DEFAULT_MSR_S] ;
        
        [self msrConfigAction:nil] ;
    }else{
        NSAlert *alert=[NSAlert alertWithMessageText:@"Remove msr warning" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"msr list is empty currently, you can not do remove action."];

        [alert beginSheetModalForWindow:nil modalDelegate:self didEndSelector:@selector(alertEnded:code:context:) contextInfo:nil];

    }


}
- (IBAction)msrConfigAction:(id)sender
{
    NSMutableArray *existobjsArray = (NSMutableArray*)[myMSRContentArray arrangedObjects] ;
    NSString *msrlist = nil;
    for (NSDictionary *subdict in existobjsArray) {
        if (msrlist==nil||[msrlist length]==0) {
            msrlist = [subdict objectForKey:@"msr"] ;
        }else{
            msrlist = [NSString stringWithFormat:@"%@--%@",msrlist,
                       [subdict objectForKey:@"msr"]];
        }
    }
    //send to client to update the current newest barcode list.
    [self updateClientMSRList:msrlist] ;

    [swipButton setEnabled:YES] ;
}
#pragma mark ----
#pragma configuration Manufacturer.
- (IBAction)configureMFG:(id)sender
{
    [self setAccessoryname:accessoryField.stringValue] ;
    [self setManufacture:ManufacturerField.stringValue] ;
    [self setModelNumber:ModelNumberField.stringValue] ;
    [self setSerialNumber:SerialNumberField.stringValue] ;
    [self setFirmwareRev:FirmwareRevField.stringValue] ;
    [self setHardwareRev:HardwareRevField.stringValue] ;
    [self setSDKRev:SDKRevField.stringValue] ;
    
}



@end