This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Array as Argument

I want to send control codes to a printer
they look like this :

	unsigned char cntrl_codes[6] = { 0x0d, 0x14, 0x1b, 0x4c, 0x0d, 0x0d};

I have made a function to send this array to serial port :
//this function takes two arguments
//    1)the array
//    2)time delay between successive codes

void print(unsigned char* c,unsigned char del)
{				
	int x,y;		
	y=strlen(c);//y++;      
	for(x=0;x<y;x++)
	{

		putchar(c[x]);
		delay(del);
		
	}
}

There has to be a more graceful way to do this !!!

Parents
  • It is not clear what the problem is.

    You could define your control codes as a null terminated string if you prefer:

    unsigned char cntrl_codes = "\0x0d\0x14\0x1b\0x4c\0x0d\0x0d";
    
    Is the problem that you do not want to hold up the CPU while waiting for the delay time? To do this it is necessary to buffer the output and to have a special version of putchar() that detects a non-ASCII command character and interprets it as a wait command. This may get more complicated that you really want...

Reply
  • It is not clear what the problem is.

    You could define your control codes as a null terminated string if you prefer:

    unsigned char cntrl_codes = "\0x0d\0x14\0x1b\0x4c\0x0d\0x0d";
    
    Is the problem that you do not want to hold up the CPU while waiting for the delay time? To do this it is necessary to buffer the output and to have a special version of putchar() that detects a non-ASCII command character and interprets it as a wait command. This may get more complicated that you really want...

Children