I don't think that closing the connection will force RTS to change its state, but when the ttyS1 goes free some other process can access it and modify, So try to keep the control. Why you want to close the handle??
Anyway you are right that you can use ioctl() for the purpose, here is how to do it. And i don't know about the shell script for the purpose.
Make the binary file and call it from your script
Just kidding
In this code m_hCom is the handle to ttyS1
Code:
//________________________Set_RTS__________________
bool Set_RTS(void)
{
int nRet;
int status;
status = 0;
nRet = ioctl(m_hCom, TIOCMGET,&status);
if(nRet < 0) return FALSE;
status |= TIOCM_RTS;
nRet = ioctl(m_hCom, TIOCMSET, &status);
if(nRet < 0) return FALSE;
return TRUE;
}
//________________________Clr_RTS__________________
bool Clr_RTS(void)
{
int nRet;
int status;
status = 0;
nRet = ioctl(m_hCom, TIOCMGET,&status);
if(nRet < 0) return FALSE;
status &= ~TIOCM_RTS;
nRet = ioctl(m_hCom, TIOCMSET, &status);
if(nRet < 0) return FALSE;
return TRUE;
}