I'm not sure this is the problem, but it would be good if Read(data) checked
the return status from Read(data, bytes). The read() system call can return
with no data for lots of reasons, especially when O_NONBLOCK is set.
Bob
-----Original Message-----
From: On Behalf Of
machv0
Sent: Thursday, January 03, 2008 9:19 AM
To:
Subject: [ts-7000] Re: RS232 Questions/Problems
Thanks for all the replies so far. Definitely some things to look at.
I am for sure going to try turning off parity checking and see if that
makes a difference. Also the possibility that a flush is happening is
interesting. I don't directly ever flush the buffers, but I wonder if
the way I am writing might be inducing a flush.
The protocol for these valves is that they will respond with an
acknowledgment or error, upon receiving/processing a command. So when
I see this problem it is after calling a write followed immediately by
a read. Therefore I don't think there is anything else going on with
the 7260 to interfere with this. I am not actually logging to flash
during this process as I have to switch the ports to their correct
position before I begin accumulating data. Even then the amount of
data I collect during 1 cycle is small enough that I store it in ram
and don't log to disk until a cycle is complete.
I've already got the consoles turned off in inittab. Definitely a
lesson I think everyone learns the hard way. And I know I have com3
configured correctly as it opens, and I can talk to the valve on that
port successfully minus the quick turnaround condition.
My code is wrapped up in a framework that I've been using for a while
so one thing I will definitely try is to strip out all of the port
handling into a test app that does nothing more than open the port,
and issue a raw write/read. I'm using c++ streams for writing/reading
in a wrapper and maybe that's an issue, inducing a flush? If that
doesn't work I'll have a look at your code Bob and see if I can make
it work. Thanks for sharing.
In any event here is some of the underlying port code for
reading/writing. Sorry for the verbosity.
///////////////////////////////////////////////////////
int CRS232Protocol::Read(char* data)
{
if(m_Opened)
{
if(!Wait()) // Wait for data, exit if timeout occurs
{
return -1;
}
int rsize, tempsize=0;
// Wait for the port to stabilize
while((rsize=ReadWaiting())!=tempsize)
{
SLEEP(100);
tempsize=rsize;
}
Read(data,rsize); // Read response
return rsize;
}
return 0;
}
///////////////////////////////////////////////////////
int CRS232Protocol::Read(char* data, long bytes)
{
if(m_Opened)
{
memset(data,'\0',bytes); // Reset read buffer
return read(m_CommDev,data,bytes);
}
return 0;
}
///////////////////////////////////////////////////////
int CRS232Protocol::ReadWaiting()
{
if(m_Opened)
{
int bytes=0;
ioctl(m_CommDev, FIONREAD, &bytes);
return bytes;
}
return 0;
}
///////////////////////////////////////////////////////
bool CRS232Protocol::Wait()
{
struct timeval tv;
set_usec_timer(tv,m_Timeout*1000);
for(int rsize=ReadWaiting(); rsize==0; rsize=ReadWaiting())
{
//Something went wrong and timeout occured
if(check_usec_timer(tv))
{
return false;
}
SLEEP(100);
}
return true;
}
///////////////////////////////////////////////////////
int CRS232Protocol::Write(const char* data, long bytes)
{
if(m_Opened)
{
return write(m_CommDev,data,bytes);
}
}
Yahoo! Groups Links
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|