Note that there are some explanatory texts on larger screens.

plurals
  1. POttyACM0 only reads 64 bytes
    text
    copied!<p>I'm bit of a newbie but I have an legacy app that reads 64 bytes of AES encrypted data from a device using ttyACM0. I now need to read 128 bytes. Sounded simple; increase the sizes of buffers etc. But no matter what I try, I still can only read 64 bytes. After that it just hangs. I verified the communications in Windows with a terminal and cdc-acm driver. Device does not use flow control. I cant upload code because its proprietary but below are some snippets:</p> <p>The Intialization: CACS_RefID::Initialise() { int iRet = 1; struct termios dev_settings;</p> <pre><code> if(( m_fdRefdev = open("/dev/ttyACM0", O_RDWR))&lt;0) { g_dbg-&gt;debug("CACS_RefID::Failed to open device\n"); return 0; } g_dbg-&gt;debug("CACS_RefID::Initialse completed\n"); // Configure the port tcgetattr(m_fdRefdev, &amp;dev_settings); cfmakeraw(&amp;dev_settings); //*tcflush //tcflush(m_fdRefdev, TCIOFLUSH); tcsetattr(m_fdRefdev, TCSANOW, &amp;dev_settings); return iRet; } </code></pre> <p>The implementation:</p> <pre><code> int CACS_RefID::Readport_Refid(int ilen, char* buf) { int ierr=0, iret = 0, ictr=0; fd_set fdrefid; struct timeval porttime_refrd; FD_ZERO(&amp;fdrefid); FD_SET(m_fdRefdev,&amp;fdrefid); porttime_refrd.tv_sec = 1; porttime_refrd.tv_usec = 0; //10 Seconds wait time for read port do { iret = select(m_fdRefdev + 1, &amp;fdrefid, NULL, NULL, &amp;porttime_refrd); switch(iret) { case READ_TIMEOUT: g_dbg-&gt;debug("Refid portread: Select timeout:readlen=%d \n",ilen); ierr = -1; break; case READ_ERROR: g_dbg-&gt;debug("Refid portread: Select error:readlen=%d \n",ilen); ierr = -1; break; default: iret = read(m_fdRefdev, buf, ilen); g_dbg-&gt;debug("Refid portread: Read len(%d):%d\n",ilen,iret); break; } }while((ierr == 0) &amp;&amp; (iret&lt;ilen) ); //Flush terminal content at Input and Output after every read completion // tcflush(m_fdRefdev, TCIOFLUSH); return ierr; </code></pre> <p>}</p> <p>If I initialize every time that I before running the implementation, I get 128 bytes but the data is corrupt after 64 bytes. Even before working on it, I get a lot of READ_ERRORs. Looks like the original author expected the device to block with select() but it doesn't.<br> Is there some type of limitation on ttyACM0 buffer size in the system? Does baud rate matter with the ttyACM driver? Does read() stop reading after all bytes are read (thinking the first 64 are available, then empty, then more data)? </p> <p>Pouring thru man pages but I'm stymied. ANY help would be greatly appreciated.</p> <p>Heres my latest:</p> <pre><code> int CACS_RefID::Get_GasTest_Result(int ilen) { int ierr=0, iret = 0, ictr=0, iread=0; fd_set fdrefid; struct timeval porttime_refrd; porttime_refrd.tv_sec = 5; porttime_refrd.tv_usec = 0; //10 Seconds wait time for read port if (Get_GasTest_FirstPass == 0) { g_dbg-&gt;debug("GasTest_Result_firstPass\n"); memset(strresult, 0, sizeof(strresult)); //SLY clear out result buffer iread=0; Get_GasTest_FirstPass = 1; } do { iread = strlen(strresult); FD_ZERO(&amp;fdrefid); FD_SET(m_fdRefdev,&amp;fdrefid); iret = select(m_fdRefdev + 1, &amp;fdrefid, NULL, NULL, &amp;porttime_refrd); switch(iret) { case READ_TIMEOUT: //0 g_dbg-&gt;debug("Get_GasTest_Result: Select timeout\n"); ierr = -1; break; case READ_ERROR: //-1 g_dbg-&gt;debug("Get_GasTest_Result: Select error=%d %s \n", errno,strerror(errno)) ; ierr = -1; break; } iret = read(m_fdRefdev, (&amp;strresult[0] + iread), (ilen-iread)); g_dbg-&gt;debug("Get_GasTest_Result: ilen=%d,iret=%d,iread=%d \n",ilen,iret,iread); }while((ierr == 0) &amp;&amp; (iread&lt;ilen) ); return ierr; </code></pre> <p>Note: I am now reading data regardless of select errors and STILL only getting 64bytes. I've contacted my device mfg. Must be something odd going on.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload