Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 822
ZacAttack Avatar asked Nov 29 '22 03:11

ZacAttack


1 Answers

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.

like image 141
Kerrek SB Avatar answered Dec 01 '22 15:12

Kerrek SB