Re: Writing a 0xFE to the serial port
Re: Writing a 0xFE to the serial port
- Subject: Re: Writing a 0xFE to the serial port
- From: Sherm Pendley <email@hidden>
- Date: Sat, 1 Mar 2003 01:29:34 -0500
On Saturday, March 1, 2003, at 12:41 AM, Chuck Rice wrote:
This may be a really trivial question, but I am more of an assembler
programmer than a C programmer. The following code works, i.e., it
accomplishes sending the right string (a 0xFE) out to the serial port,
but I am unsure if it is the correct way to do it.
NSString * xFE;
char FE = 0xFE;
xFE = &FE; //Point the string at a Hex FE byte
numBytes = write(fileDescriptor, str, strlen(str)); //Write some
data to LCD
numBytes = write(fileDescriptor,xFE, 1); //Send Command
Escape byte
numBytes = write(fileDescriptor,"X", 1); //Send the
ClearScreen byte
The only issue I see is that you're declaring xFE as a pointer to an
NSString object - but you're using it as a pointer to a char. That's not
a fatal error, but I'd bet you're getting an "assignment to incompatible
pointer type" warning on that line. Declaring xFE as a "char *" would
get rid of the warning.
For that matter, you don't really need a pointer to FE at all - you
could use C's "address of" (&) operator to directly pass the address of
the variable.
Here's how I'd write it:
char FE=0xFE;
numBytes = write(fd, str, strlen(str));
numBytes = write(fd, &FE, 1); // Note the & operator here
numBytes = write(fd, "X", 1);
sherm--
C programmers never die - they're just cast into void.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.