Important Update:
- Added SendEnable (vir RTS pin) for TTL/RS485 converter - Bug fix: Check for Handle->InTimeout before force output
This commit is contained in:
@@ -128,6 +128,8 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig )
|
|||||||
FlowCtrl = HW_FLOWCTRL;
|
FlowCtrl = HW_FLOWCTRL;
|
||||||
else if (!strcasecmp( FlowCtrlText, "software" ))
|
else if (!strcasecmp( FlowCtrlText, "software" ))
|
||||||
FlowCtrl = SW_FLOWCTRL;
|
FlowCtrl = SW_FLOWCTRL;
|
||||||
|
else if (!strcasecmp( FlowCtrlText, "rs485" ))
|
||||||
|
FlowCtrl = RS485_FLOWCTRL;
|
||||||
else
|
else
|
||||||
FlowCtrl = NO_FLOWCTRL;
|
FlowCtrl = NO_FLOWCTRL;
|
||||||
|
|
||||||
@@ -652,6 +654,12 @@ THandle * CSelectableCore::OpenSerialPort( THandle * Handle )
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set Send Enable (via RTS) for RS485
|
||||||
|
if ((Handle->Type == ctSerial) && (Handle->FlowCtrl == RS485_FLOWCTRL)) {
|
||||||
|
int sercmd = TIOCM_RTS;
|
||||||
|
ioctl( Handle->FD, TIOCMBIS, &sercmd );
|
||||||
|
}
|
||||||
|
|
||||||
// Log Event
|
// Log Event
|
||||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Handle '%s' - Serial Port opened [%s]",
|
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Handle '%s' - Serial Port opened [%s]",
|
||||||
ProcessName, Name, Handle->Name, Handle->Path );
|
ProcessName, Name, Handle->Name, Handle->Path );
|
||||||
@@ -1748,6 +1756,12 @@ bool CSelectableCore::Close( THandle * Handle, bool QuickReopen )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set Send Enable (via RTS) for RS485
|
||||||
|
if ((Handle->Type == ctSerial) && (Handle->FlowCtrl == RS485_FLOWCTRL)) {
|
||||||
|
int sercmd = TIOCM_RTS;
|
||||||
|
ioctl( Handle->FD, TIOCMBIC, &sercmd );
|
||||||
|
}
|
||||||
|
|
||||||
// Close Handle
|
// Close Handle
|
||||||
if (Handle->Type == ctUDPremote) {
|
if (Handle->Type == ctUDPremote) {
|
||||||
Fail = false;
|
Fail = false;
|
||||||
@@ -2099,10 +2113,22 @@ bool CSelectableCore::Write( THandle * Handle )
|
|||||||
{
|
{
|
||||||
// Write directly to handle / socket
|
// Write directly to handle / socket
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if ((Handle->Type == ctUDPclient)|| (Handle->Type == ctUDPremote)) {
|
if ((Handle->Type == ctUDPclient) || (Handle->Type == ctUDPremote)) {
|
||||||
Len = Handle->OutBuffer->Peek( &Data );
|
Len = Handle->OutBuffer->Peek( &Data );
|
||||||
BytesWritten = WriteToUDP( Handle, Data, Len, true );
|
BytesWritten = WriteToUDP( Handle, Data, Len, true );
|
||||||
}
|
}
|
||||||
|
else if ((Handle->Type == ctSerial) && (Handle->FlowCtrl == RS485_FLOWCTRL)) {
|
||||||
|
// Set Send Enable (via RTS pin) when sending data
|
||||||
|
int sercmd = TIOCM_RTS;
|
||||||
|
ioctl( Handle->FD, TIOCMBIC, &sercmd );
|
||||||
|
usleep( 1000 );
|
||||||
|
|
||||||
|
BytesWritten = Handle->OutBuffer->WriteToFD( Handle->FD );
|
||||||
|
|
||||||
|
tcdrain( Handle->FD );
|
||||||
|
usleep( 1000 );
|
||||||
|
ioctl( Handle->FD, TIOCMBIS, &sercmd );
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
BytesWritten = Handle->OutBuffer->WriteToFD( Handle->FD );
|
BytesWritten = Handle->OutBuffer->WriteToFD( Handle->FD );
|
||||||
}
|
}
|
||||||
@@ -2163,7 +2189,7 @@ bool CSelectableCore::ProcessInputBuffer( THandle * Handle, bool Force )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if forced processed
|
// Check if forced processed
|
||||||
if (Force || !Handle->InMarkerLen)
|
if (Force || (!Handle->InMarkerLen && !Handle->InTimeout))
|
||||||
{
|
{
|
||||||
// Show Packet
|
// Show Packet
|
||||||
Len = Handle->InBuffer->Peek( &Data );
|
Len = Handle->InBuffer->Peek( &Data );
|
||||||
@@ -2180,7 +2206,7 @@ bool CSelectableCore::ProcessInputBuffer( THandle * Handle, bool Force )
|
|||||||
// Clear processed bytes from buffer
|
// Clear processed bytes from buffer
|
||||||
Handle->InBuffer->Clear( Len );
|
Handle->InBuffer->Clear( Len );
|
||||||
}
|
}
|
||||||
else
|
else if (Handle->InMarkerLen)
|
||||||
{
|
{
|
||||||
// Search for end of packet marker
|
// Search for end of packet marker
|
||||||
while (Handle->InBuffer->FindStr( Handle->InMarker, Handle->InMarkerLen, Pos ))
|
while (Handle->InBuffer->FindStr( Handle->InMarker, Handle->InMarkerLen, Pos ))
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ const char ConnectStateName[][15] = { "None", "OpenRequest", "WaitingToOpen", "O
|
|||||||
#define NO_FLOWCTRL 0
|
#define NO_FLOWCTRL 0
|
||||||
#define HW_FLOWCTRL 1
|
#define HW_FLOWCTRL 1
|
||||||
#define SW_FLOWCTRL 2
|
#define SW_FLOWCTRL 2
|
||||||
|
#define RS485_FLOWCTRL 3
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user