serial.c 613 B

12345678910111213141516171819202122232425
  1. #include <uefi.h>
  2. /**
  3. * Use serial port
  4. */
  5. int main(int argc, char **argv)
  6. {
  7. (void)argc;
  8. (void)argv;
  9. FILE *f;
  10. char buff[2];
  11. if((f = fopen("/dev/serial", "r"))) {
  12. fwrite("sending bytes as-is with fwrite\r\n", 33, 1, f);
  13. fprintf(f, "sending characters automatically wchar_t/char converted with fprintf\n");
  14. printf("Press a key on the other side\n");
  15. while(!fread(buff, 1, 1, f));
  16. buff[1] = 0;
  17. printf("Got key: %02x '%s'\n", buff[0], buff);
  18. fclose(f);
  19. } else
  20. fprintf(stderr, "Unable to open serial port\n");
  21. return 0;
  22. }