printf raw data -- get printf or print to NOT send characters

ZacAttack picture ZacAttack · Dec 3, 2011 · Viewed 10.8k times · Source

I have a Xilinx Virtex-II Pro FPGA board that is attached via RS232 to an iRobot Create.

The iRobot takes a stream of byte integers as commands.

I've found that printf will actually send over the serial port (Hypterminal is able to pick up whatever I print), and I figure that I can use printf to send my data to the iRobot.

The problem is that printf seems to format the data for ascii output, but I'd REALLY like it to simply send out the data raw.

I'd like something like:

printf(%x %x %x, 0x80, 0x88, 0x08);

But instead of the hexadecimal getting formatted, I'd like it to be the actual 0x80 value sent.

Any ideas?

Answer

Kerrek SB picture Kerrek SB · Dec 3, 2011

Use fwrite:

char buf[] = { 0x80, 0x80, 0x80 };

fwrite(buf, 1, sizeof(buf), stdout);

You can write to any file handle; stdout is just an example to mirror your printf.

On a Posix system, you can also use the platform-specific write function that writes to a file descriptor.