Index: trunk/CanGateway/CanGateway.cpp
===================================================================
--- trunk/CanGateway/CanGateway.cpp	(revision 91)
+++ trunk/CanGateway/CanGateway.cpp	(revision 116)
@@ -59,41 +59,54 @@
   
 	// set the exhange parameters for incoming CAN frames
-	canIf_.setExchangeBuffer(incomingCanFrames_, INCOMINGCANFRAMES_SIZE);
-	canIf_.setSignalSempahore(&semaphore_);
-	if (source_ == "shMem")
-		canIf_.setSource(Win32CanInterface::SharedMemory);
+	canIfRead_.setExchangeBuffer(incomingCanFrames_, INCOMINGCANFRAMES_SIZE);
+	canIfRead_.setSignalSempahore(&semaphore_);
+
+	if (source_ == "shMem") {
+		sameCanIf = true;
+		canIfRead_.setSource(Win32CanInterface::SharedMemory);
+	}
 	else if (source_ == "vector")
 	{
-		canIf_.setSource(Win32CanInterface::VectorCard);
+		sameCanIf = true;
+		canIfRead_.setSource(Win32CanInterface::VectorCard);
 		// open the interface
-		if (!canIf_.openInterface(channel_, speed_))
+		if (!canIfRead_.openInterface(channel_, speed_))
 			qFatal("Failed to open the CAN interface num %d at speed %d",channel_,speed_);
 	}
 	else if (source_ == "vectorXL")
 	{
-		canIf_.setSource(Win32CanInterface::XLVectorCard);
+		sameCanIf = true;
+		canIfRead_.setSource(Win32CanInterface::XLVectorCard);
 		// open the interface
-		if (!canIf_.openInterface(channel_, speed_))
+		if (!canIfRead_.openInterface(channel_, speed_))
 			qFatal("Failed to open the CAN interface num %d at speed %d",channel_,speed_);
 	}
 	else if (source_ == "peak")
 	{
-		canIf_.setSource(Win32CanInterface::PeakCard);
-		// open interface
-		if (canIf_.openInterface(port_, accessMode_)==0)
+		sameCanIf = true;
+		canIfRead_.setSource(Win32CanInterface::PeakCard);
+		// open interface
+		if (canIfRead_.openInterface(port_, accessMode_)==0)
 			qFatal("Failed to open the CAN interface port %s in %s mode",port_, accessMode_);
 	}
 	else if (source_ == "igep")
 	{
-		canIf_.setSource(Win32CanInterface::igepCard);
-		// open interface
-		if (canIf_.openInterface(port_, accessMode_)==0)
+		sameCanIf = true;
+		canIfRead_.setSource(Win32CanInterface::igepCard);
+		// open interface
+		if (canIfRead_.openInterface(port_, accessMode_)==0)
 			qFatal("Failed to open the CAN interface port %s in %s mode",port_, accessMode_);
 	}
 	else if (source_ == "kvaser")
 	{
-		canIf_.setSource(Win32CanInterface::KvaserCard);
-		// open interface
-		if (canIf_.openInterface(channel_,speed_)==0)
+		sameCanIf = false;
+		canIfRead_.setSource(Win32CanInterface::KvaserCard);
+		// open interface
+		if (canIfRead_.openInterface(channel_,speed_)==0)
+			qFatal("Failed to open the CAN interface num %d at speed %d",channel_,speed_);
+
+		canIfWrite_.setSource(Win32CanInterface::KvaserCard);
+		// open interface
+		if (canIfWrite_.openInterface(channel_,speed_)==0)
 			qFatal("Failed to open the CAN interface num %d at speed %d",channel_,speed_);
 	}
@@ -105,5 +118,6 @@
 
 	// start the 2 threads: reception thread and decoding thread
-	canIf_.start();
+	canIfRead_.start();
+
 	start();
 }
@@ -117,10 +131,14 @@
 {
 	counter_ = 0;
-	canIf_.stop();
-
-	if ((source_ == "vector")||(source_=="peak")||(source_=="vectorXL")||(source_=="igep")||(source_=="kvaser"))
-		canIf_.closeInterface(channel_);
+
+	canIfRead_.stop();
+
+	if ((source_ == "vector")||(source_=="peak")||(source_=="vectorXL")||(source_=="igep")||(source_=="kvaser")) {
+		canIfRead_.closeInterface(channel_);
+		if(!sameCanIf)
+			canIfWrite_.closeInterface(channel_);
+	}
 	
-	canIf_.wait();
+	canIfRead_.wait();
 
 	// we stop the decoding thread
@@ -167,12 +185,27 @@
 bool CanGateway::sendFrame(const CanFrame frame)
 {
-	if (canIf_.canDriver_ == NULL)
-		return false;
+	if(sameCanIf) 
+	{
+		if (canIfRead_.canDriver_ == NULL)
+			return false;
+		else
+		{
+			if (canIfWrite_.canDriver_->sendFrame(frame))
+				return true;
+			else
+				return false;
+		}
+	} 
 	else
 	{
-		if (canIf_.canDriver_->sendFrame(frame))
-			return true;
+		if (canIfWrite_.canDriver_ == NULL)
+			return false;
 		else
-			return false;
+		{
+			if (canIfWrite_.canDriver_->sendFrame(frame))
+				return true;
+			else
+				return false;
+		}
 	}
 }
