cant use stty configured serial ports and console based stdin at the same time












0














I am using stty configured serial ports on an embedded ubuntu 15.10 system to communicate between a machine vision process on the ubuntu system and a flight controller. The ports are used only between the embedded system and the flight controller. This works fine for com between these 2 systems



I log into the embedded system using ssh over wifi. This also works fine.



UNTIL, the machine vision process tries to get console input. Just good old scanf(). Or fgets(). Or cin.



If I turn off the embedded system to flight controller communications, scanf() and similar work fine. But if that underlying code is running, input from stdin no longer works. scan() doesn't wait for any input, and the buffer has garbage in it. Similar results using fgets(), etc.



Reading suggests that stty sets stdin to the port being configured. If so, the open() and close() calls in the communications code are likely closing stdin, and could be the source of my issue. Is there a way to use stty without changing stdin to stop this? I have tried lots of combinations but haven't found one that fixes things.



Here are the current stty config statements:



stty -F /dev/ttyS1 115200



stty -F /dev/ttyS2 115200



Here is the abbreviated com code that uses them - argument dev is cstring of dev name:



    while(keepTryingCount) {

// open dev
// if fd invalid, and open() fails; report and exit
if(fd==-1 && (fd=open(dev, O_RDONLY | O_NOCTTY)==-1)) {
msg("cannot open port from fc %s: errno error: %s. exiting nown", dev, strerror(errno));
exit(0);
}
// check for bytes to read, if here fd is valid
// if ioctl() fails
// report, close and mark fd, dec keepTryingCount: close/open dev seems to fix ioctl() issues
bytesToRead = 0;
if(ioctl(fd, FIONREAD, &bytesToRead)==-1) {
msg("readFCmsg() ioctl error %d %sn", errno, strerror(errno));
close(fd); fd=-1; --keepTryingCount;
}

// if here, fd open, and ioctl() successful, so test for #bytes to read
else if(bytesToRead>0) {

// lots of code doing reading and buffer mgm't omitted


else {
close(fd); fd=-1; keepTryingCount=0;
}
} // end while(keepTryingCount)


I have also tried configuring the ports using setserial. This appears to never work. setserial -a reports the change, but the ports don't work, and stty reports they remain set at 9600 baud. Here are the setserial commands I tried:



setserial /dev/ttyS1 spd_cust baud_base 115200 divisor 1



setserial /dev/ttyS2 spd_cust baud_base 115200 divisor 1



I did try altering the boot time config file - in this case /var/lib/setserial/autoserial.conf. There is no /etc/serial.conf, or /var/run/setserial.conf, that I can find. This also does not seem to work.



So, having experimented a few days away - I thought I'd ask for some help.



Any and all constructive comments welcome!



thanks









share







New contributor




sneiman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    0














    I am using stty configured serial ports on an embedded ubuntu 15.10 system to communicate between a machine vision process on the ubuntu system and a flight controller. The ports are used only between the embedded system and the flight controller. This works fine for com between these 2 systems



    I log into the embedded system using ssh over wifi. This also works fine.



    UNTIL, the machine vision process tries to get console input. Just good old scanf(). Or fgets(). Or cin.



    If I turn off the embedded system to flight controller communications, scanf() and similar work fine. But if that underlying code is running, input from stdin no longer works. scan() doesn't wait for any input, and the buffer has garbage in it. Similar results using fgets(), etc.



    Reading suggests that stty sets stdin to the port being configured. If so, the open() and close() calls in the communications code are likely closing stdin, and could be the source of my issue. Is there a way to use stty without changing stdin to stop this? I have tried lots of combinations but haven't found one that fixes things.



    Here are the current stty config statements:



    stty -F /dev/ttyS1 115200



    stty -F /dev/ttyS2 115200



    Here is the abbreviated com code that uses them - argument dev is cstring of dev name:



        while(keepTryingCount) {

    // open dev
    // if fd invalid, and open() fails; report and exit
    if(fd==-1 && (fd=open(dev, O_RDONLY | O_NOCTTY)==-1)) {
    msg("cannot open port from fc %s: errno error: %s. exiting nown", dev, strerror(errno));
    exit(0);
    }
    // check for bytes to read, if here fd is valid
    // if ioctl() fails
    // report, close and mark fd, dec keepTryingCount: close/open dev seems to fix ioctl() issues
    bytesToRead = 0;
    if(ioctl(fd, FIONREAD, &bytesToRead)==-1) {
    msg("readFCmsg() ioctl error %d %sn", errno, strerror(errno));
    close(fd); fd=-1; --keepTryingCount;
    }

    // if here, fd open, and ioctl() successful, so test for #bytes to read
    else if(bytesToRead>0) {

    // lots of code doing reading and buffer mgm't omitted


    else {
    close(fd); fd=-1; keepTryingCount=0;
    }
    } // end while(keepTryingCount)


    I have also tried configuring the ports using setserial. This appears to never work. setserial -a reports the change, but the ports don't work, and stty reports they remain set at 9600 baud. Here are the setserial commands I tried:



    setserial /dev/ttyS1 spd_cust baud_base 115200 divisor 1



    setserial /dev/ttyS2 spd_cust baud_base 115200 divisor 1



    I did try altering the boot time config file - in this case /var/lib/setserial/autoserial.conf. There is no /etc/serial.conf, or /var/run/setserial.conf, that I can find. This also does not seem to work.



    So, having experimented a few days away - I thought I'd ask for some help.



    Any and all constructive comments welcome!



    thanks









    share







    New contributor




    sneiman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0







      I am using stty configured serial ports on an embedded ubuntu 15.10 system to communicate between a machine vision process on the ubuntu system and a flight controller. The ports are used only between the embedded system and the flight controller. This works fine for com between these 2 systems



      I log into the embedded system using ssh over wifi. This also works fine.



      UNTIL, the machine vision process tries to get console input. Just good old scanf(). Or fgets(). Or cin.



      If I turn off the embedded system to flight controller communications, scanf() and similar work fine. But if that underlying code is running, input from stdin no longer works. scan() doesn't wait for any input, and the buffer has garbage in it. Similar results using fgets(), etc.



      Reading suggests that stty sets stdin to the port being configured. If so, the open() and close() calls in the communications code are likely closing stdin, and could be the source of my issue. Is there a way to use stty without changing stdin to stop this? I have tried lots of combinations but haven't found one that fixes things.



      Here are the current stty config statements:



      stty -F /dev/ttyS1 115200



      stty -F /dev/ttyS2 115200



      Here is the abbreviated com code that uses them - argument dev is cstring of dev name:



          while(keepTryingCount) {

      // open dev
      // if fd invalid, and open() fails; report and exit
      if(fd==-1 && (fd=open(dev, O_RDONLY | O_NOCTTY)==-1)) {
      msg("cannot open port from fc %s: errno error: %s. exiting nown", dev, strerror(errno));
      exit(0);
      }
      // check for bytes to read, if here fd is valid
      // if ioctl() fails
      // report, close and mark fd, dec keepTryingCount: close/open dev seems to fix ioctl() issues
      bytesToRead = 0;
      if(ioctl(fd, FIONREAD, &bytesToRead)==-1) {
      msg("readFCmsg() ioctl error %d %sn", errno, strerror(errno));
      close(fd); fd=-1; --keepTryingCount;
      }

      // if here, fd open, and ioctl() successful, so test for #bytes to read
      else if(bytesToRead>0) {

      // lots of code doing reading and buffer mgm't omitted


      else {
      close(fd); fd=-1; keepTryingCount=0;
      }
      } // end while(keepTryingCount)


      I have also tried configuring the ports using setserial. This appears to never work. setserial -a reports the change, but the ports don't work, and stty reports they remain set at 9600 baud. Here are the setserial commands I tried:



      setserial /dev/ttyS1 spd_cust baud_base 115200 divisor 1



      setserial /dev/ttyS2 spd_cust baud_base 115200 divisor 1



      I did try altering the boot time config file - in this case /var/lib/setserial/autoserial.conf. There is no /etc/serial.conf, or /var/run/setserial.conf, that I can find. This also does not seem to work.



      So, having experimented a few days away - I thought I'd ask for some help.



      Any and all constructive comments welcome!



      thanks









      share







      New contributor




      sneiman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I am using stty configured serial ports on an embedded ubuntu 15.10 system to communicate between a machine vision process on the ubuntu system and a flight controller. The ports are used only between the embedded system and the flight controller. This works fine for com between these 2 systems



      I log into the embedded system using ssh over wifi. This also works fine.



      UNTIL, the machine vision process tries to get console input. Just good old scanf(). Or fgets(). Or cin.



      If I turn off the embedded system to flight controller communications, scanf() and similar work fine. But if that underlying code is running, input from stdin no longer works. scan() doesn't wait for any input, and the buffer has garbage in it. Similar results using fgets(), etc.



      Reading suggests that stty sets stdin to the port being configured. If so, the open() and close() calls in the communications code are likely closing stdin, and could be the source of my issue. Is there a way to use stty without changing stdin to stop this? I have tried lots of combinations but haven't found one that fixes things.



      Here are the current stty config statements:



      stty -F /dev/ttyS1 115200



      stty -F /dev/ttyS2 115200



      Here is the abbreviated com code that uses them - argument dev is cstring of dev name:



          while(keepTryingCount) {

      // open dev
      // if fd invalid, and open() fails; report and exit
      if(fd==-1 && (fd=open(dev, O_RDONLY | O_NOCTTY)==-1)) {
      msg("cannot open port from fc %s: errno error: %s. exiting nown", dev, strerror(errno));
      exit(0);
      }
      // check for bytes to read, if here fd is valid
      // if ioctl() fails
      // report, close and mark fd, dec keepTryingCount: close/open dev seems to fix ioctl() issues
      bytesToRead = 0;
      if(ioctl(fd, FIONREAD, &bytesToRead)==-1) {
      msg("readFCmsg() ioctl error %d %sn", errno, strerror(errno));
      close(fd); fd=-1; --keepTryingCount;
      }

      // if here, fd open, and ioctl() successful, so test for #bytes to read
      else if(bytesToRead>0) {

      // lots of code doing reading and buffer mgm't omitted


      else {
      close(fd); fd=-1; keepTryingCount=0;
      }
      } // end while(keepTryingCount)


      I have also tried configuring the ports using setserial. This appears to never work. setserial -a reports the change, but the ports don't work, and stty reports they remain set at 9600 baud. Here are the setserial commands I tried:



      setserial /dev/ttyS1 spd_cust baud_base 115200 divisor 1



      setserial /dev/ttyS2 spd_cust baud_base 115200 divisor 1



      I did try altering the boot time config file - in this case /var/lib/setserial/autoserial.conf. There is no /etc/serial.conf, or /var/run/setserial.conf, that I can find. This also does not seem to work.



      So, having experimented a few days away - I thought I'd ask for some help.



      Any and all constructive comments welcome!



      thanks







      linux ubuntu stty





      share







      New contributor




      sneiman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      sneiman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      sneiman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 3 mins ago









      sneimansneiman

      11




      11




      New contributor




      sneiman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      sneiman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      sneiman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          sneiman is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493094%2fcant-use-stty-configured-serial-ports-and-console-based-stdin-at-the-same-time%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          sneiman is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          sneiman is a new contributor. Be nice, and check out our Code of Conduct.













          sneiman is a new contributor. Be nice, and check out our Code of Conduct.












          sneiman is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493094%2fcant-use-stty-configured-serial-ports-and-console-based-stdin-at-the-same-time%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          濃尾地震

          How to rewrite equation of hyperbola in standard form

          No ethernet ip address in my vocore2