GIOChannel sometimes it reads sometimes not

Here is piece of my code. I will explain the problem right after. GIOStatus ret; GError *err = NULL; gchar *msg; gsize *len; ret = g_io_channel_read_chars (koncentrator, &msg, 13, &len, err); printf ("Read %u bytes: %hx\n", len, msg); My device sends chains of 13 bytes over the serial port. Unfortunately only first two bytes are read correctly. Maybe this is because only first two bytes can be interpreted as ASCII characters, this would be strange because I set the encoding as NULL with the function `g_io_channel_set_encoding(koncentrator, NULL, NULL);` If I try to access the bytes after first two I get `Segmentation fault`, which is also strange because variable `ret` after reading contains `13` which means it had read 13 bytes. I tryed to use `g_io_channel_read_line` and `g_io_channel_read_to_end`. With those two the program stucks at infinite loop (even when I verify the condition `G_IO_STATUS_EOF`). The last problem, and maybe the most annoying is that it doesn't work at first time, I need to open the serial port with the terminal, like `cutecom` for example. Otherwise I can send the data but it doesn't detect any callback. I am sure of it because the device has diodes to indicate states of `RX` and `TX`. I have no idea what is wrong, I will be very greatfull for giving me some tips or links to the suitable example. I feel like there is nothing more on google I could find. Thanks, cheers!

以上就是GIOChannel sometimes it reads sometimes not的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准