Commit 9ce79082 authored by Pavel Vainerman's avatar Pavel Vainerman

(ComPort): Попытка решить проблему с периодическим зависанием обмена

parent 940d217c
......@@ -3,7 +3,7 @@
Name: libuniset
Version: 1.0
Release: alt36
Release: alt37
Summary: UniSet - library for building distributed industrial control systems
License: GPL
Group: Development/C++
......@@ -207,6 +207,9 @@ rm -f %buildroot%_libdir/*.la
%changelog
* Sun Jun 05 2011 Pavel Vainerman <pv@altlinux.ru> 1.0-alt37
- add cleanup before send for ComPort
* Tue May 24 2011 Pavel Vainerman <pv@altlinux.ru> 1.0-alt36
- add 'node' param processing for uniset-codegen
......
......@@ -22,6 +22,8 @@ class ModbusRTUSlaveSlot:
virtual ~ModbusRTUSlaveSlot();
virtual void sigterm( int signo );
inline ComPort* getComPort(){ return port; }
protected:
......
......@@ -51,6 +51,8 @@ class ModbusServer
inline void setBroadcastMode( bool set ){ onBroadcast = set; }
inline bool getBroadcastMode(){ return onBroadcast; }
inline void setCleanBeforeSend( bool set ){ cleanBeforeSend = set; }
inline bool getCleanBeforeSend(){ return cleanBeforeSend; }
/*! Вспомогательная функция реализующая обработку запроса на установку времени.
Основана на использовании gettimeofday и settimeofday.
......@@ -209,6 +211,7 @@ class ModbusServer
timeout_t sleepPause_usec; /*!< пауза между попытками чтения символа из канала */
bool onBroadcast; /*!< включен режим работы с broadcst-сообщениями */
bool crcNoCheckit;
bool cleanBeforeSend;
void printProcessingTime();
PassiveTimer tmProcessing;
......
......@@ -298,6 +298,7 @@ void ComPort::cleanupChannel()
if( fd < 0 )
return;
/*
unsigned char tmpbuf[100];
int k = 0;
do
......@@ -305,6 +306,18 @@ void ComPort::cleanupChannel()
k = ::read(fd,tmpbuf,sizeof(tmpbuf));
}
while( k>0 );
*/
unsigned char tmpbuf[100];
int k = 0;
try
{
do
{
k = receiveBlock(tmpbuf,sizeof(tmpbuf));
}
while( k>0 );
}
catch(...){}
// #warning Обнулять нельзя, может надо делать что-то интелектуальнее...
// curSym = 0;
......
......@@ -17,7 +17,8 @@ ModbusServer::ModbusServer():
aftersend_msec(0),
sleepPause_usec(100),
onBroadcast(false),
crcNoCheckit(false)
crcNoCheckit(false),
cleanBeforeSend(false)
{
tmProcessing.setTiming(replyTimeout_ms);
}
......@@ -1206,6 +1207,9 @@ ModbusRTU::mbErrCode ModbusServer::replySetDateTime( ModbusRTU::SetDateTimeMessa
// -------------------------------------------------------------------------
mbErrCode ModbusServer::send( ModbusMessage& msg )
{
if( cleanBeforeSend )
cleanupChannel();
mbErrCode ret = pre_send_request(msg);
if( ret!=erNoError )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment