سؤال

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?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

Use the format "%c%c%c" instead.

You would use fwrite instead. Printf is by definition an ascii printer.

char buf[] = {0x80, 0x80, 0x80};
fwrite(buf, 1, 3, stdout);

seems to be what you want.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top