//
//  PageModeViewController.m
//  SDK212
//
//  Created by woosimsystems on 2016. 7. 04..
//  Copyright © 2016년 woosimsystems. All rights reserved.
//
#import "PageModeViewController.h"
#import "WSSessionController.h"
#import "WSEncoder.h"




WSEncoder *_wsPM;
NSMutableData *_printDataPM;

@implementation PageModeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setTitle:@"Page Mode"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    [[EAAccessoryManager sharedAccessoryManager] registerForLocalNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_accessoryDidDisconnect:) name:EAAccessoryDidDisconnectNotification object:nil];
    //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_accessoryDidConnect:) name:EAAccessoryDidConnectNotification object:nil];
    //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_sessionDataReceived:) name:WSDataReceivedNotification object:nil];
    
    _sessionController = [WSSessionController sharedController];
    _wsPM = [[WSEncoder alloc]init];
    
}

-(void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    
    [[EAAccessoryManager sharedAccessoryManager] unregisterForLocalNotifications];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:EAAccessoryDidDisconnectNotification object:nil];
    //[[NSNotificationCenter defaultCenter] removeObserver:self name:EAAccessoryDidConnectNotification object:nil];
    //[[NSNotificationCenter defaultCenter] removeObserver:self name:WSDataReceivedNotification object:nil];
    
    if(_sessionController != nil) _sessionController = nil;
    if(_wsPM != nil) _wsPM = nil;
    if (_printDataPM != nil) _printDataPM = nil;
    
}
- (void)_accessoryDidDisconnect:(NSNotification *)notification{
    
    [_sessionController closeSession];
    [self.navigationController popToRootViewControllerAnimated:YES];
    
}

-(IBAction)Btn_DrawArea:(id)sender
{

    _printDataPM = [[NSMutableData alloc]init];
    _wsPM = [[WSEncoder alloc]init];
    
    [_printDataPM appendData:[_wsPM clearPrinterBuffer]];
    //Enter page mode
    [_printDataPM appendData:[_wsPM enterPageMode]];
    //if not create area that can be drawn then set default area size.
    //width: different for each printer.
    //2inch printer: 384 dot
    //3inch printer: 576 dot
    //4inch printer: 832 dot
    
    [_printDataPM appendData:[_wsPM addString:@"Area that can be drawn.\n\n *Default area\n  Width \n  - 2inch printer: 384 dot\n  - 3inch printer: 576 dot\n  - 4inch printer: 832 dot\n  height\n  - 2400 dot(30cm)" encoding:NSASCIIStringEncoding]];
    //print out area.
    [_printDataPM appendData:[_wsPM printDataInPageMode]];
    
    [_printDataPM appendData:[_wsPM clearDataInPageMode]];
    //create area that can be drawn.
    //width: 384 dot
    //height: 800 dot (10cm)
    [_printDataPM appendData:[_wsPM createDrawingAreaWithStartPositionX:0 withStartPositionY:0 withAreaWidth:384 withAreaHeight:[_wsPM changeDotFromCentimeter:10.0]]];
    [_printDataPM appendData:[_wsPM addString:@"width: 384 dot\n height: 800 dot(10cm)" encoding:NSASCIIStringEncoding]];
    //print out area.
    [_printDataPM appendData:[_wsPM printDataInPageMode]];
    [_printDataPM appendData:[_wsPM exitPageMode]];
    
    [_sessionController writeData:_printDataPM];
 
}

-(IBAction)Btn_DrawBox:(id)sender
{
    
    _printDataPM = [[NSMutableData alloc]init];
    _wsPM = [[WSEncoder alloc]init];
    [_printDataPM appendData:[_wsPM clearPrinterBuffer]];
    [_printDataPM appendData:[_wsPM addString:@"* Draw box" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM printDataInStandardMode]];
    [_printDataPM appendData:[_wsPM enterPageMode]];
    
    [_printDataPM appendData:[_wsPM createDrawingAreaWithStartPositionX:0 withStartPositionY:0 withAreaWidth:384 withAreaHeight:[_wsPM changeDotFromCentimeter:10.0]]];
    
    //draw box.
    [_printDataPM appendData:[_wsPM drawBoxWithWidth:384 withHeight:[_wsPM changeDotFromCentimeter:10] withLineThickness:3]];
    [_printDataPM appendData:[_wsPM movePositionToX:20 toY:20]];
    [_printDataPM appendData:[_wsPM drawBoxWithWidth:[_wsPM changeDotFromCentimeter:4.3] withHeight:[_wsPM changeDotFromCentimeter:1.5] withLineThickness:1]];
    
    [_printDataPM appendData:[_wsPM movePositionToX:[_wsPM changeDotFromCentimeter:0.8] toY:[_wsPM changeDotFromCentimeter:2.0]]];
    [_printDataPM appendData:[_wsPM drawBoxWithWidth:[_wsPM changeDotFromCentimeter:2.5] withHeight:[_wsPM changeDotFromCentimeter:4.0] withLineThickness:2]];
    
    
    [_printDataPM appendData:[_wsPM movePositionToX:[_wsPM changeDotFromCentimeter:3.5] toY:[_wsPM changeDotFromCentimeter:5.0]]];
    [_printDataPM appendData:[_wsPM drawBoxWithWidth:[_wsPM changeDotFromCentimeter:1] withHeight:[_wsPM changeDotFromCentimeter:4.5] withLineThickness:3]];
    
    [_printDataPM appendData:[_wsPM movePositionToX:[_wsPM changeDotFromCentimeter:0.3] toY:[_wsPM changeDotFromCentimeter:6.2]]];
    [_printDataPM appendData:[_wsPM drawBoxWithWidth:[_wsPM changeDotFromCentimeter:2.8] withHeight:[_wsPM changeDotFromCentimeter:3.5] withLineThickness:1]];
    
    [_printDataPM appendData:[_wsPM printDataInPageMode]];
    [_printDataPM appendData:[_wsPM exitPageMode]];
    
    [_printDataPM appendData:[_wsPM printAndFeedNLineInStandardMode:5]];
    
    
    [_sessionController writeData:_printDataPM];
    
}

-(IBAction)Btn_DrawLine:(id)sender
{
    _printDataPM = [[NSMutableData alloc]init];
    _wsPM = [[WSEncoder alloc]init];
    [_printDataPM appendData:[_wsPM clearPrinterBuffer]];
    [_printDataPM appendData:[_wsPM addString:@"* Draw horizontal & vertical line\n\n" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM enterPageMode]];
    
    [_printDataPM appendData:[_wsPM createDrawingAreaWithStartPositionX:0 withStartPositionY:0 withAreaWidth:384 withAreaHeight:[_wsPM changeDotFromCentimeter:2.0]]];
    //draw line.
    [_printDataPM appendData:[_wsPM drawHorizontalLineWithLength:[_wsPM changeDotFromCentimeter:3.8] withLineThickness:1]];
    [_printDataPM appendData:[_wsPM movePositionToX:0x00 toY:[_wsPM changeDotFromCentimeter:0.8]]];
    [_printDataPM appendData:[_wsPM drawHorizontalLineWithLength:[_wsPM changeDotFromCentimeter:4] withLineThickness:2]];
    [_printDataPM appendData:[_wsPM movePositionToX:0x00 toY:[_wsPM changeDotFromCentimeter:1.6]]];
    [_printDataPM appendData:[_wsPM drawHorizontalLineWithLength:[_wsPM changeDotFromCentimeter:4.2] withLineThickness:3]];
    [_printDataPM appendData:[_wsPM printDataInPageMode]];
    
    //clear data
    [_printDataPM appendData:[_wsPM clearDataInPageMode]];
    
    [_printDataPM appendData:[_wsPM createDrawingAreaWithStartPositionX:0 withStartPositionY:0 withAreaWidth:384 withAreaHeight:[_wsPM changeDotFromCentimeter:6.0]]];
    [_printDataPM appendData:[_wsPM drawVerticalLineWithLength:[_wsPM changeDotFromCentimeter:3] withLineThickness:3]];
    [_printDataPM appendData:[_wsPM movePositionToX:[_wsPM changeDotFromCentimeter:1] toY:0]];
    [_printDataPM appendData:[_wsPM drawVerticalLineWithLength:[_wsPM changeDotFromCentimeter:3.4] withLineThickness:2]];
    [_printDataPM appendData:[_wsPM movePositionToX:[_wsPM changeDotFromCentimeter:2] toY:0]];
    [_printDataPM appendData:[_wsPM drawVerticalLineWithLength:[_wsPM changeDotFromCentimeter:3.8] withLineThickness:1]];
    [_printDataPM appendData:[_wsPM printDataInPageMode]];
    [_printDataPM appendData:[_wsPM exitPageMode]];
    
    
    [_sessionController writeData:_printDataPM];
    
}

-(IBAction)Btn_DrawTable:(id)sender
{
    NSMutableData *_printDataPM = [[NSMutableData alloc]init];
    WSEncoder *_wsPM = [[WSEncoder alloc]init];
    [_printDataPM appendData:[_wsPM clearPrinterBuffer]];
    [_printDataPM appendData:[_wsPM addString:@"* Draw table" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM printDataInStandardMode]];
    [_printDataPM appendData:[_wsPM enterPageMode]];
    [_printDataPM appendData:[_wsPM createDrawingAreaWithStartPositionX:0x00 withStartPositionY:0x00 withAreaWidth:384 withAreaHeight:[_wsPM changeDotFromCentimeter:6]]];
    [_printDataPM appendData:[_wsPM drawBoxWithWidth:384 withHeight:[_wsPM changeDotFromCentimeter:5] withLineThickness:3]];
    [_printDataPM appendData:[_wsPM movePositionToX:0x00 toY:[_wsPM changeDotFromCentimeter:1]]];
    [_printDataPM appendData:[_wsPM drawHorizontalLineWithLength:384 withLineThickness:2]];
    [_printDataPM appendData:[_wsPM movePositionToX:0x00 toY:[_wsPM changeDotFromCentimeter:2]]];
    [_printDataPM appendData:[_wsPM drawHorizontalLineWithLength:384 withLineThickness:2]];
    [_printDataPM appendData:[_wsPM movePositionToX:0x00 toY:[_wsPM changeDotFromCentimeter:3]]];
    [_printDataPM appendData:[_wsPM drawHorizontalLineWithLength:384 withLineThickness:2]];
    [_printDataPM appendData:[_wsPM movePositionToX:0x00 toY:[_wsPM changeDotFromCentimeter:4]]];
    [_printDataPM appendData:[_wsPM drawHorizontalLineWithLength:384 withLineThickness:2]];
    
    [_printDataPM appendData:[_wsPM movePositionToX:128 toY:0]];
    [_printDataPM appendData:[_wsPM drawVerticalLineWithLength:[_wsPM changeDotFromCentimeter:5] withLineThickness:1]];
    [_printDataPM appendData:[_wsPM movePositionToX:256 toY:0]];
    [_printDataPM appendData:[_wsPM drawVerticalLineWithLength:[_wsPM changeDotFromCentimeter:5] withLineThickness:1]];
    
    [_printDataPM appendData:[_wsPM printDataInPageMode]];
    [_printDataPM appendData:[_wsPM exitPageMode]];
    [_printDataPM appendData:[_wsPM printAndFeedNLineInStandardMode:2]];
    
    [_sessionController writeData:_printDataPM];
    
}

-(IBAction)Btn_PrintingDirection:(id)sender
{
    NSMutableData *_printDataPM = [[NSMutableData alloc]init];
    
    WSEncoder *_wsPM = [[WSEncoder alloc]init];
    
    [_printDataPM appendData:[_wsPM clearPrinterBuffer]];
    [_printDataPM appendData:[_wsPM addString:@"* Set printing direction" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM printDataInStandardMode]];
    [_printDataPM appendData:[_wsPM enterPageMode]];
    [_printDataPM appendData:[_wsPM createDrawingAreaWithStartPositionX:0 withStartPositionY:0 withAreaWidth:384 withAreaHeight:[_wsPM changeDotFromCentimeter:3.0]]];
    [_printDataPM appendData:[_wsPM setPrintingDirectionInPageMode:DIRECTION_LEFTTORIGHT]];
    [_printDataPM appendData:[_wsPM addString:@"Left to right" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM setPrintingDirectionInPageMode:DIRECTION_BOTTOMTOTOP]];
    [_printDataPM appendData:[_wsPM addString:@"Bottom to top" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM setPrintingDirectionInPageMode:DIRECTION_RIGHTTOLEFT]];
    [_printDataPM appendData:[_wsPM addString:@"Right to left" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM setPrintingDirectionInPageMode:DIRECTION_TOPTOBOTTOM]];
    [_printDataPM appendData:[_wsPM addString:@"Top to bottom" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM printDataInPageMode]];
    
    [_printDataPM appendData:[_wsPM exitPageMode]];
    [_printDataPM appendData:[_wsPM printAndFeedNLineInStandardMode:5]];
    
    [_sessionController writeData:_printDataPM];
    
}

-(IBAction)Btn_MovePosition:(id)sender
{
    _printDataPM = [[NSMutableData alloc]init];
    _wsPM = [[WSEncoder alloc]init];
    [_printDataPM appendData:[_wsPM clearPrinterBuffer]];
    [_printDataPM appendData:[_wsPM addString:@"* Move position(cm)" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM printDataInStandardMode]];
    
    [_printDataPM appendData:[_wsPM enterPageMode]];
    [_printDataPM appendData:[_wsPM createDrawingAreaWithStartPositionX:0 withStartPositionY:0 withAreaWidth:384 withAreaHeight:[_wsPM changeDotFromCentimeter:7.0]]];
    [_printDataPM appendData:[_wsPM movePositionToX:0 toY:0]];
    [_printDataPM appendData:[_wsPM addString:@"(0,0)" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM movePositionToX:[_wsPM changeDotFromCentimeter:1.0] toY:[_wsPM changeDotFromCentimeter:1.0]]];
    [_printDataPM appendData:[_wsPM addString:@"(1,1)" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM movePositionToX:[_wsPM changeDotFromCentimeter:2.0] toY:[_wsPM changeDotFromCentimeter:2.0]]];
    [_printDataPM appendData:[_wsPM addString:@"(2,2)" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM movePositionToX:[_wsPM changeDotFromCentimeter:3.0] toY:[_wsPM changeDotFromCentimeter:3.0]]];
    [_printDataPM appendData:[_wsPM addString:@"(3,3)" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM movePositionToX:[_wsPM changeDotFromCentimeter:4.0] toY:[_wsPM changeDotFromCentimeter:4.0]]];
    [_printDataPM appendData:[_wsPM addString:@"(4,4)" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM movePositionToX:[_wsPM changeDotFromCentimeter:4.0] toY:[_wsPM changeDotFromCentimeter:0.0]]];
    [_printDataPM appendData:[_wsPM addString:@"(4,0)" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM movePositionToX:[_wsPM changeDotFromCentimeter:0.0] toY:[_wsPM changeDotFromCentimeter:4.0]]];
    [_printDataPM appendData:[_wsPM addString:@"(0,4)" encoding:NSASCIIStringEncoding]];
    
    [_printDataPM appendData:[_wsPM printDataInPageMode]];
    [_printDataPM appendData:[_wsPM exitPageMode]];
    
    [_sessionController writeData:_printDataPM];
    
}

-(IBAction)Btn_FeedLine:(id)sender;
{
    
    _printDataPM = [[NSMutableData alloc]init];
    _wsPM = [[WSEncoder alloc]init];
    [_printDataPM appendData:[_wsPM clearPrinterBuffer]];
    
    [_printDataPM appendData:[_wsPM addString:@"* Feed paper a line." encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM printDataInStandardMode]];
    //set page mode
    [_printDataPM appendData:[_wsPM enterPageMode]];
    
    [_printDataPM appendData:[_wsPM createDrawingAreaWithStartPositionX:0 withStartPositionY:0 withAreaWidth:384 withAreaHeight:[_wsPM changeDotFromCentimeter:4.0]]];
    
    [_printDataPM appendData:[_wsPM addString:@"Start feeding" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM feedLineInPageMode]];
    [_printDataPM appendData:[_wsPM addString:@"Line is changed" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM printDataInPageMode]];
    [_printDataPM appendData:[_wsPM exitPageMode]];
    
    [_sessionController writeData:_printDataPM];
    
}

-(IBAction)Btn_FeedNDot:(id)sender
{
    
    _printDataPM = [[NSMutableData alloc]init];
    _wsPM = [[WSEncoder alloc]init];
    
    [_printDataPM appendData:[_wsPM clearPrinterBuffer]];
    
    [_printDataPM appendData:[_wsPM addString:@"* Feed paper n line." encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM printDataInStandardMode]];
    //set page mode
    [_printDataPM appendData:[_wsPM enterPageMode]];
    //
    [_printDataPM appendData:[_wsPM createDrawingAreaWithStartPositionX:0 withStartPositionY:0 withAreaWidth:384 withAreaHeight:[_wsPM changeDotFromCentimeter:6.0]]];
    
    [_printDataPM appendData:[_wsPM addString:@"Start feeding" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM feedNDotInPageMode:20]];
    [_printDataPM appendData:[_wsPM addString:@"Feed 20dot" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM feedLineInPageMode]];
    [_printDataPM appendData:[_wsPM addString:@"Start feeding" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM feedNDotInPageMode:100]];
    [_printDataPM appendData:[_wsPM addString:@"Feed 100dot" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM printDataInPageMode]];
    [_printDataPM appendData:[_wsPM exitPageMode]];
    
    [_sessionController writeData:_printDataPM];
    
}
-(IBAction)Btn_FeedNLine:(id)sender
{
    
    _printDataPM = [[NSMutableData alloc]init];
    _wsPM = [[WSEncoder alloc]init];
    [_printDataPM appendData:[_wsPM clearPrinterBuffer]];
    
    [_printDataPM appendData:[_wsPM addString:@"*Feed paper n line." encoding:NSASCIIStringEncoding] ];
    [_printDataPM appendData:[_wsPM printDataInStandardMode]];
    //set page mode
    [_printDataPM appendData:[_wsPM enterPageMode] ];
    
    [_printDataPM appendData:[_wsPM createDrawingAreaWithStartPositionX:0 withStartPositionY:0 withAreaWidth:384 withAreaHeight:[_wsPM changeDotFromCentimeter:6.0]]];
    
    [_printDataPM appendData:[_wsPM addString:@"Start feeding" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM feedNLineInPageMode:2]];
    [_printDataPM appendData:[_wsPM addString:@"Feed 2 lines" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM feedLineInPageMode]];
    [_printDataPM appendData:[_wsPM addString:@"Start feeding" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM feedNLineInPageMode:5]];
    [_printDataPM appendData:[_wsPM addString:@"Feed 5 lines" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM printDataInPageMode]];
    [_printDataPM appendData:[_wsPM exitPageMode]];
    
    [_sessionController writeData:_printDataPM];
    
}

-(IBAction)Btn_DrawImage:(id)sender
{
    _printDataPM = [[NSMutableData alloc]init];
    _wsPM = [[WSEncoder alloc]init];
    [_printDataPM appendData:[_wsPM clearPrinterBuffer]];
    [_printDataPM appendData:[_wsPM addString:@"* Image" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM printDataInStandardMode]];
    
    [_printDataPM appendData:[_wsPM enterPageMode]];
    [_printDataPM appendData:[_wsPM createDrawingAreaWithStartPositionX:0x00 withStartPositionY:0x00 withAreaWidth:832 withAreaHeight:[_wsPM changeDotFromCentimeter:7]]];
    
    UIImage *logo = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"woosim" ofType:@"bmp"]];
    
    [_printDataPM appendData:[_wsPM createImageInPageMode:[logo CGImage] withStartPositionX:0x00 withStartPositionY:0x00 withDithering:YES]];
    [_printDataPM appendData:[_wsPM createImageInPageMode:[logo CGImage] withStartPositionX:0x50 withStartPositionY:[_wsPM changeDotFromCentimeter:5.0] withDithering:YES]];
    [_printDataPM appendData:[_wsPM printDataInPageMode]];
    
    [_printDataPM appendData:[_wsPM exitPageMode]];
    
    [_sessionController writeData:_printDataPM];
    
}

-(IBAction)Btn_DrawEllipse:(id)sender
{
    _printDataPM = [[NSMutableData alloc]init];
    _wsPM = [[WSEncoder alloc]init];
    [_printDataPM appendData:[_wsPM clearPrinterBuffer]];
    [_printDataPM appendData:[_wsPM addString:@"* Draw Ellipse" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM printDataInStandardMode]];
    
    [_printDataPM appendData:[_wsPM enterPageMode]];
    [_printDataPM appendData:[_wsPM createDrawingAreaWithStartPositionX:0 withStartPositionY:0 withAreaWidth:384 withAreaHeight:[_wsPM changeDotFromCentimeter:13]]];
    [_printDataPM appendData:[_wsPM drawEllipseWithCenterPositionX:[_wsPM changeDotFromCentimeter:2.2] withCenterPositionY:[_wsPM changeDotFromCentimeter:2] withRadiusX:[_wsPM changeDotFromCentimeter:1] withRadiusY:[_wsPM changeDotFromCentimeter:1.6] withThickness:5]];
    
    
    [_printDataPM appendData:[_wsPM drawEllipseWithCenterPositionX:[_wsPM changeDotFromCentimeter:2.5] withCenterPositionY:[_wsPM changeDotFromCentimeter:5] withRadiusX:[_wsPM changeDotFromCentimeter:1.5] withRadiusY:[_wsPM changeDotFromCentimeter:1] withThickness:3]];
    
    
    [_printDataPM appendData:[_wsPM drawEllipseWithCenterPositionX:[_wsPM changeDotFromCentimeter:2.5] withCenterPositionY:[_wsPM changeDotFromCentimeter:7.3] withRadiusX:[_wsPM changeDotFromCentimeter:1] withRadiusY:[_wsPM changeDotFromCentimeter:1] withThickness:2]];
    
    [_printDataPM appendData:[_wsPM drawEllipseWithCenterPositionX:[_wsPM changeDotFromCentimeter:1.5] withCenterPositionY:[_wsPM changeDotFromCentimeter:9.5] withRadiusX:[_wsPM changeDotFromCentimeter:1] withRadiusY:[_wsPM changeDotFromCentimeter:1] withThickness:2]];
    
    [_printDataPM appendData:[_wsPM drawEllipseWithCenterPositionX:[_wsPM changeDotFromCentimeter:2] withCenterPositionY:[_wsPM changeDotFromCentimeter:9.5] withRadiusX:[_wsPM changeDotFromCentimeter:1] withRadiusY:[_wsPM changeDotFromCentimeter:1] withThickness:2]];
    
    [_printDataPM appendData:[_wsPM drawEllipseWithCenterPositionX:[_wsPM changeDotFromCentimeter:2.5] withCenterPositionY:[_wsPM changeDotFromCentimeter:9.5] withRadiusX:[_wsPM changeDotFromCentimeter:1] withRadiusY:[_wsPM changeDotFromCentimeter:1] withThickness:2]];
    
    [_printDataPM appendData:[_wsPM drawEllipseWithCenterPositionX:[_wsPM changeDotFromCentimeter:3] withCenterPositionY:[_wsPM changeDotFromCentimeter:9.5] withRadiusX:[_wsPM changeDotFromCentimeter:1] withRadiusY:[_wsPM changeDotFromCentimeter:1] withThickness:2]];
    
    
    
    [_printDataPM appendData:[_wsPM printDataInPageMode]];
    [_printDataPM appendData:[_wsPM exitPageMode]];
    
    [_sessionController writeData:_printDataPM];
    
}

-(IBAction)Btn_DrawDiagonalLine:(id)sender
{
    _printDataPM = [[NSMutableData alloc]init];
    _wsPM = [[WSEncoder alloc]init];
    [_printDataPM appendData:[_wsPM clearPrinterBuffer]];
    [_printDataPM appendData:[_wsPM addString:@"* Draw diagonal line" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM printDataInStandardMode]];
    
    [_printDataPM appendData:[_wsPM enterPageMode]];
    
    [_printDataPM appendData:[_wsPM createDrawingAreaWithStartPositionX:0 withStartPositionY:0 withAreaWidth:384 withAreaHeight:[_wsPM changeDotFromCentimeter:8.0]]];
    [_printDataPM appendData:[_wsPM drawDiagonalLineWithStartPositionX:[_wsPM changeDotFromCentimeter:1] withStartPositionY:[_wsPM changeDotFromCentimeter:1] withEndPositionX:[_wsPM changeDotFromCentimeter:5.0] withEndPositionY:[_wsPM changeDotFromCentimeter:5.0] withThickness:5]];
    [_printDataPM appendData:[_wsPM drawDiagonalLineWithStartPositionX:0x00 withStartPositionY:[_wsPM changeDotFromCentimeter:3.5] withEndPositionX:[_wsPM changeDotFromCentimeter:5] withEndPositionY:[_wsPM changeDotFromCentimeter:1] withThickness:2]];
    [_printDataPM appendData:[_wsPM drawDiagonalLineWithStartPositionX:[_wsPM changeDotFromCentimeter:0.7] withStartPositionY:[_wsPM changeDotFromCentimeter:4.7] withEndPositionX:[_wsPM changeDotFromCentimeter:4.5] withEndPositionY:[_wsPM changeDotFromCentimeter:6] withThickness:4]];
    
    [_printDataPM appendData:[_wsPM drawDiagonalLineWithStartPositionX:[_wsPM changeDotFromCentimeter:1.5] withStartPositionY:[_wsPM changeDotFromCentimeter:6.5] withEndPositionX:[_wsPM changeDotFromCentimeter:4.8] withEndPositionY:[_wsPM changeDotFromCentimeter:1.5] withThickness:3]];
    


    [_printDataPM appendData:[_wsPM printDataInPageMode]];
    [_printDataPM appendData:[_wsPM exitPageMode]];
    
    [_sessionController writeData:_printDataPM];
    
}

-(IBAction)Btn_ExitPageMode:(id)sender
{

    _printDataPM = [[NSMutableData alloc]init];
    _wsPM = [[WSEncoder alloc]init];
    
    [_printDataPM appendData:[_wsPM clearPrinterBuffer]];
    
    [_printDataPM appendData:[_wsPM addString:@"* Exit page mode\n" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM enterPageMode]];
    
    [_printDataPM appendData:[_wsPM createDrawingAreaWithStartPositionX:0x00 withStartPositionY:0x00 withAreaWidth:384 withAreaHeight:[_wsPM changeDotFromCentimeter:2.0]]];
    [_printDataPM appendData:[_wsPM movePositionToX:0x00 toY:0x00]];
    [_printDataPM appendData:[_wsPM addString:@"Start page mode" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM movePositionToX:[_wsPM changeDotFromCentimeter:2.7] toY:[_wsPM changeDotFromCentimeter:1.6]]];
    [_printDataPM appendData:[_wsPM addString:@"End page mode" encoding:NSASCIIStringEncoding]];
    
    [_printDataPM appendData:[_wsPM printDataInPageMode]];
    
    [_printDataPM appendData:[_wsPM exitPageMode]];
    
    [_printDataPM appendData:[_wsPM printDataInStandardMode]];
    [_printDataPM appendData:[_wsPM addString:@"Start standard mode" encoding:NSASCIIStringEncoding]];
    [_printDataPM appendData:[_wsPM printAndFeedNLineInStandardMode:5]];
    
    [_sessionController writeData:_printDataPM];
    
}


@end
