JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_setDTRandRTS()

in src/main/c/Posix/SerialPort_Posix.c [1202:1233]


JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_setDTRandRTS(JNIEnv *env, jobject obj, jlong serialPortPointer, jboolean dtr, jboolean rts)
{
	int modemBits = 0;
	serialPort *port = (serialPort*)(intptr_t)serialPortPointer;

	// Read current modem bits
	if (ioctl(port->handle, TIOCMGET, &modemBits))
	{
		port->errorLineNumber = __LINE__ - 2;
		port->errorNumber = errno;
		return JNI_FALSE;
	}

	// Modify bits
	if (dtr)
		modemBits |= TIOCM_DTR;
	else
		modemBits &= ~TIOCM_DTR;
	if (rts)
		modemBits |= TIOCM_RTS;
	else
		modemBits &= ~TIOCM_RTS;

	// Write combined bits
	if (ioctl(port->handle, TIOCMSET, &modemBits))
	{
		port->errorLineNumber = __LINE__ - 2;
		port->errorNumber = errno;
		return JNI_FALSE;
	}
	return JNI_TRUE;
}