All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: Eric Noulard <eric.noulard@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] too fast write to serialport?
Date: Fri, 14 Sep 2007 09:03:47 +0200	[thread overview]
Message-ID: <46EA3253.3010901@domain.hid> (raw)
In-Reply-To: <cbe23c50709130434x127c8e86nfb061ac71555cd68@domain.hid>

[-- Attachment #1: Type: text/plain, Size: 2416 bytes --]

Eric Noulard wrote:
> 2007/9/13, Bachman Kharazmi <bahkha@domain.hid>:
>> Hi!
>> I try to print to serialport using rtdm according to: http://pastebin.ca/695418
>>
>> But if I don't have sleep(1) only "hello   " or similar is written to
>> the serialport.
>> But if I've sleep(1) "helloworld" is written every second as expected.
> 
> I'm no xenomai expert but I think
> you shouldn't write to serial device in such a tight loop:
> 
> while(counter <100){
>         rt_dev_write(fd, myString, strlen(myString));
>        printf("%d\n",counter);
>       // sleep(1);  WITHOUT THIS SLEEP helloworld is sent on serial once.
>      counter++;
> }

The _will_ work, but the problem is that pending bytes are dropped on
rt_dev_close + the shortcoming that there is no way to synchronise on
the buffer being flushed reliably. That's a shortcoming of the current
driver (+ the serial profile spec) I trapped in myself - as the
developer of this code. :(

> 
> because you will certainly fills the send buffer without giving a chance
> to the drive to send more data than the one that fits in the buffer
> (this heavily depends wether if the device is opened in blocking
>  or non-blocking mode)

Nope, the problem here has nothing to do with the timeout or the
blocking mode. That write will block (given a timeout > 0 or infinite)
when the software buffer (4k) is full. That's not specific in the serial
profile, and that's bad.

> 
> FIRST of ALL you should check the return value of your function call
> 
> rt_dev_write should return either the number of written bytes
> http://www.xenomai.org/documentation/branches/v2.3.x/html/api/group__userapi.html#ge966625748b547779bb8c5385e7fb2aa
> 
> or a negative error code:
> http://www.xenomai.org/documentation/branches/v2.3.x/html/api/group__rtserial.html
> 
> 
>> Is this some kind of limit how quickly I can write stuff on the rtser0?
> 
> Yes there must be.
> Serial device are not as fast as any recent CPU.
> Beginning with the fact that you did configure the serial link at 115200 bauds
> it would'nt wise to try to feed at an "average" speed that exceed this number.
> 
> 
>> How do I handle this?
> 
> Check the return value of your rt_dev_write calls :)
> 

Won't help here as I explained above. Still, my beer-ware was lacking
return code checks, and that is never recommendable for real code.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

  parent reply	other threads:[~2007-09-14  7:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-13  9:45 [Xenomai-help] too fast write to serialport? Bachman Kharazmi
2007-09-13 11:34 ` Eric Noulard
2007-09-13 14:06   ` Bachman Kharazmi
2007-09-13 14:16     ` Eric Noulard
2007-09-14  7:03   ` Jan Kiszka [this message]
2007-09-14  8:12     ` Eric Noulard
2007-09-14 17:32       ` Jan Kiszka
2007-09-15 11:46         ` Anders Blomdell
2007-09-15 14:00         ` Eric Noulard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46EA3253.3010901@domain.hid \
    --to=jan.kiszka@domain.hid \
    --cc=eric.noulard@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.