Using char[] and Applescriptobjc

Dear friends,

These are two methods I have in objective C written in a class:

(the first method is hardcoded, I think I better add the parameter sizeOfChar, so it flows better)


-(BOOL)sendChars:(char*) charsParsed
         
{
    char someChar[2] ;
    
    // feeds the paper in the printer:
    someChar[0] = 13;
    someChar[1] = 10;
    int sz;
    sz = (sizeof someChar) / (sizeof someChar[0]);
    NSLog(@"someChar count = %i",sz);
    
    [ self dumpCharsToPrinter:someChar length:sz ];

    return YES;
}

- (void)dumpCharsToPrinter:(char*)charSet length:(int)length
{

    write( outputfd, charSet,length ) ; // will send the characters to the printer and perform the desired task.
    
}

Now, I don’t find a way to call method “sendChars” from my ASOC class, how do I parse chars from an ASOC method?

Thanks for any suggestions,

You will need to change your methods to accept strings, and then convert it to char * in Objective-C.

Dear Shane,

Thanks.

But I have to parse characters that are lower than 32, non printable chars, for example “GS”, “FS”, etc…

I have no idea how to do this.

Thanks for any suggestions…

To get C strings just use the utf8String method of NSString and use stringWithUTF8String method to set:

p.s. the code isn’t tested or anything

Dear Bazzie and Shane,

Thank you for replying…

I found a solution:

I create a list of integers and pass it to my objc method:



-(NSString*)sendChars:(NSMutableArray *) theArray
         //length2:(int)length
{
    
    NSLog(@"Inside sendChars...");
   
    NSLog(@"theArray = <%@>", theArray);
    
    char someChar[theArray.count];
    
    NSUInteger i = 0;
    
    for (NSNumber *number in theArray) {
        NSUInteger numValue = [number unsignedIntegerValue];
        someChar[i] = numValue;
        i++;
    }
    
    for (NSUInteger i = 0; i < sizeof(someChar); i++) {
        
        NSLog(@"someChar[i] CHAR == '%c'", someChar[i]);
        NSLog(@"someChar[i] HEX == '%x'", someChar[i]);
    }
    
    int sz;
    sz = (sizeof someChar) / (sizeof someChar[0]);
    NSLog(@"someChar count = %i",sz);
   
    NSString *response;
    
    response = [ self dumpCharsToPrinter:someChar length:sz ] ;
    
    NSLog(@"Inside send chars method, response from dump = %@", response);
    
    if(response != nil){
        return response;
    }else {
        return @"";
    }

}

My dump method now returns a response too:


- (NSString*)dumpCharsToPrinter:(char*)charSet length:(int)length
{

    //reset printerResponse:
    printerResponse = @"";
    NSLog(@"\nInside dumpCharsToPrinter...");
    NSLog(@"Now I dump the characters in printer port:");
    write( outputfd, charSet,length ) ;
    [ NSThread sleepUntilDate:[ NSDate dateWithTimeIntervalSinceNow:1 ] ];
    return printerResponse;
}

Thanks!