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

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

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