Beispiel #1
0
//-----------------------------------------------
void CanPeakSys::init()
{
    std::string sCanDevice;
    if( m_IniFile.GetKeyString( "TypeCan", "DevicePath", &sCanDevice, false) != 0) {
        sCanDevice = "/dev/pcan32";
    } else std::cout << "CAN-device path read from ini-File: " << sCanDevice << std::endl;
    m_handle = LINUX_CAN_Open(sCanDevice.c_str(), O_RDWR);


    if (! m_handle)
    {
        // Fatal error
        std::cout << "Cannot open CAN-dongle on parallel port: " << strerror(errno) << std::endl;
        sleep(3);
        exit(0);
    }


    int ret = CAN_ERR_OK;
    int iBaudrateVal = 0;
    m_IniFile.GetKeyInt( "CanCtrl", "BaudrateVal", &iBaudrateVal, true);

    switch(iBaudrateVal)
    {
    case 0:
        ret = CAN_Init(m_handle, CAN_BAUD_1M, CAN_INIT_TYPE_ST);
        break;
    case 2:
        ret = CAN_Init(m_handle, CAN_BAUD_500K, CAN_INIT_TYPE_ST);
        break;
    case 4:
        ret = CAN_Init(m_handle, CAN_BAUD_250K, CAN_INIT_TYPE_ST);
        break;
    case 6:
        ret = CAN_Init(m_handle, CAN_BAUD_125K, CAN_INIT_TYPE_ST);
        break;
    case 9:
        ret = CAN_Init(m_handle, CAN_BAUD_50K, CAN_INIT_TYPE_ST);
        break;
    case 11:
        ret = CAN_Init(m_handle, CAN_BAUD_20K, CAN_INIT_TYPE_ST);
        break;
    case 13:
        ret = CAN_Init(m_handle, CAN_BAUD_10K, CAN_INIT_TYPE_ST);
        break;
    }

    if(ret)
    {
        std::cout << "CanPeakSys::CanPeakSys(), error in init" << std::endl;
    }
    else
    {
        std::cout << "CanPeakSys::CanpeakSys(), init ok" << std::endl;
        m_bInitialized = true;
    }
}
//-----------------------------------------------
void CANPeakSysUSB::init()
{
	//m_handle = LINUX_CAN_Open("/dev/pcan32", O_RDWR | O_NONBLOCK);
	m_handle = LINUX_CAN_Open("/dev/pcan32", O_RDWR);

	if (! m_handle)
	{
		// Fatal error
		std::cout << "Cannot open CAN on USB: " << strerror(errno) << std::endl;
		sleep(3);
		exit(0);
	}

	int ret = CAN_ERR_OK;
	int iBaudrateVal = 0;
	m_IniFile.GetKeyInt( "CanCtrl", "BaudrateVal", &iBaudrateVal, true);
	
	switch(iBaudrateVal)
	{
	case 0:
		ret = CAN_Init(m_handle, CAN_BAUD_1M, CAN_INIT_TYPE_ST);
		break;
	case 2:
		ret = CAN_Init(m_handle, CAN_BAUD_500K, CAN_INIT_TYPE_ST);
		break;
	case 4:
		ret = CAN_Init(m_handle, CAN_BAUD_250K, CAN_INIT_TYPE_ST);
		break;
	case 6:
		ret = CAN_Init(m_handle, CAN_BAUD_125K, CAN_INIT_TYPE_ST);
		break;
	case 9:
		ret = CAN_Init(m_handle, CAN_BAUD_50K, CAN_INIT_TYPE_ST);
		break;
	case 11:
		ret = CAN_Init(m_handle, CAN_BAUD_20K, CAN_INIT_TYPE_ST);
		break;
	case 13:
		ret = CAN_Init(m_handle, CAN_BAUD_10K, CAN_INIT_TYPE_ST);
		break;
	}

	if(ret)
	{
		std::cout << "CANPeakSysUSB::CANPeakSysUSB(), error in init" << std::endl;
	}
	else
	{
		std::cout << "CANPeakSysUSB::CanpeakSys(), init ok" << std::endl;
		m_bInitialized = true;
	}
}
Beispiel #3
0
//-----------------------------------------------
CANPeakSys2PCI::CANPeakSys2PCI(int iBaudRate, std::string strDeviceName)
{
	m_bInitialized = false;
	m_handle = LINUX_CAN_Open(strDeviceName.c_str(), O_RDWR);

	if (! m_handle)
	{
		LOGERROR("can not open CANPeakSys2PCI device : " << strerror(errno));
		Sleep(3000);
		exit(0);
	}
	init(iBaudRate);
}
Beispiel #4
0
//-----------------------------------------------
CANPeakSysDongle::CANPeakSysDongle(int iBaudRate, std::string strDeviceName)
{
	m_bInitialized = false;
	m_handle = LINUX_CAN_Open(strDeviceName.c_str(), O_RDWR | O_NONBLOCK);
	if (!m_handle)
	{
		// Fatal error
		LOGERROR("can not open CANPeakSysDongle device : "<<strDeviceName<< " " << strerror(errno));
		Sleep(3000);
		exit(0);
	}
OUTPUTINFO("baudrate: %i", iBaudRate);
	init(iBaudRate);
}
//-----------------------------------------------
bool ros_for_can::init_ret()
{
    bool ret = true;

    // init() - part
    m_handle = LINUX_CAN_Open(p_cDevice, O_RDWR);

    if (! m_handle)
    {
        std::cout << "Cannot open CAN on USB: " << strerror(errno) << std::endl;
        ret = false;
    }
    else
    {
        ret = initCAN();
    }

    return ret;
}
// open the CAN port
int open_can(bool bDevNodeGiven,bool bTypeGiven,const char *szDevNode,int nType,__u32 dwPort,__u16 wIrq)
{
  int err = 0;
  if ((bDevNodeGiven) || (!bDevNodeGiven && !bTypeGiven)) 
    h = LINUX_CAN_Open(szDevNode, O_RDWR);
  else 
  {
		// please use what is appropriate
		// HW_DONGLE_SJA
		// HW_DONGLE_SJA_EPP
		// HW_ISA_SJA
		// HW_PCI
		// HW_USB
    h = CAN_Open(nType, dwPort, wIrq);
  }
  if (!h) 
    return 1;
  
  return err;
}
Beispiel #7
0
CAN_HANDLE canOpen_driver(s_BOARD *board)
{
  HANDLE fd0 = NULL;
  char busname[64];
  char* pEnd;
  int baudrate;
  
  if(strtol(board->busname, &pEnd,0) >= 0)
  {
    sprintf(busname,"/dev/pcan%s",board->busname);
    fd0 = LINUX_CAN_Open(busname, O_RDWR);
  }

  if(fd0 && (baudrate = TranslateBaudeRate(board->baudrate)))
  {
   	CAN_Init(fd0, baudrate, CAN_INIT_TYPE_ST);
  }else{
  	fprintf(stderr, "canOpen_driver (Peak_Linux) : error opening %s\n", busname);
  }

   return (CAN_HANDLE)fd0;
}
Beispiel #8
0
/****************************************************************************
 * Name: arm_caninit(void)
 ****************************************************************************/
int arm_caninit(){

  /* Initialization of the CAN hardware is performed by logic external to
   * this test.
   */
    const char *szDeviceNode = DEFAULT_NODE;

    errno = 0;
  /* Open the CAN device for reading */
   // open the CAN port
   // please use what is appropriate
   // HW_DONGLE_SJA
   // HW_DONGLE_SJA_EPP
   // HW_ISA_SJA
   // HW_PCI
   h = LINUX_CAN_Open(szDeviceNode, O_RDWR);
   if (!h)
   {
     errno = nGetLastError();
     perror("bitratetest: CAN_Open()");
     return 0;
   }

   /*set the bitrate*/
    errno = CAN_Init(h,CAN_BAUD_1M,CAN_INIT_TYPE_ST);
    if(errno)
    {
        perror("set can speed error");
        CAN_Close(h);
        return 0;
    }

  /* Now loop the appropriate number of times, performing one loopback test
   * on each pass.
   */
       printf("can init is ok!\n");
   //return 1 is ok;
    return 1;
}
//-----------------------------------------------
void CANPeakSysUSB::init()
{
	std::string sCanDevice; 
	
	if( m_IniFile.GetKeyString( "TypeCan", "DevicePath", &sCanDevice, false) != 0) {
		sCanDevice = "/dev/pcan32";
	} else std::cout << "CAN-device path read from ini-File: " << sCanDevice << std::endl;
	
	//m_handle = LINUX_CAN_Open("/dev/pcan32", O_RDWR | O_NONBLOCK);
	m_handle = LINUX_CAN_Open(sCanDevice.c_str(), O_RDWR);

	if (! m_handle)
	{
		// Fatal error
		std::cout << "Cannot open CAN on USB: " << strerror(errno) << std::endl;
		sleep(3);
		exit(0);
	}

	m_iBaudrateVal = 0;
	m_IniFile.GetKeyInt( "CanCtrl", "BaudrateVal", &m_iBaudrateVal, true);
	
	initCAN();
}
HANDLE initCAN(void)
{
    const char *szDevNode = PCAN_DEVICE;
    uint16_t wBTR0BTR1 = CAN_BAUD_RATE_REG_VAL;
    HANDLE h;

    h = LINUX_CAN_Open(szDevNode, O_RDWR);
    if (!h)
    {
        printf("transmitest: can't open %s\n", szDevNode);
        return NULL;
    }
    // init to a user defined bit rate
    if (wBTR0BTR1)
    {
        errno = CAN_Init(h, wBTR0BTR1, CAN_INIT_TYPE_ST);
        if (errno)
        {
            perror("transmitest: CAN_Init()");
            return NULL;
        }
    }
    return h;
}
Beispiel #11
0
// here all is done
int main(int argc, char *argv[])
{
	char *ptr;
	int i;
	int nType = HW_PCI;
	__u32 dwPort = 0;
	__u16 wIrq = 0;
	__u16 wBTR0BTR1 = 0;
	int nExtended = CAN_INIT_TYPE_ST;
	const char  *szDevNode = DEFAULT_NODE;
	bool bDevNodeGiven = false;
	bool bTypeGiven = false;
	bool bDisplayOn = true;
	char txt[VERSIONSTRING_LEN];

	errno = 0;

	current_release = CURRENT_RELEASE;
	disclaimer("receivetest");

	init();

	// decode command line arguments
	for (i = 1; i < argc; i++) {
		char c;

		ptr = argv[i];

		while (*ptr == '-')
			ptr++;

		c = *ptr;
		ptr++;

		if (*ptr == '=')
			ptr++;

		switch(tolower(c)) {
		case 'f':
			szDevNode = ptr;
			bDevNodeGiven = true;
			break;
		case 'd':
			if (strcmp(ptr, "no") == 0)
				bDisplayOn = false;
			break;
		case 't':
			nType = getTypeOfInterface(ptr);
			if (!nType) {
				errno = EINVAL;
				printf("receivetest: unknown type of interface!\n");
				goto error;
			}
			bTypeGiven = true;
			break;
		case 'p':
			dwPort = strtoul(ptr, NULL, 16);
			break;
		case 'i':
			wIrq = (__u16)strtoul(ptr, NULL, 10);
			break;
		case 'e':
			nExtended = CAN_INIT_TYPE_EX;
			break;
		case '?':
		case 'h':
			hlpMsg();
			goto error;
			break;
		case 'b':
			wBTR0BTR1 = (__u16)strtoul(ptr, NULL, 16);
			break;
		default:
			errno = EINVAL;
			perror("receivetest: unknown command line argument!\n");
			goto error;
			break;
		}
	}

	// simple command input check
	if (bDevNodeGiven && bTypeGiven) {
		errno = EINVAL;
		perror("receivetest: device node and type together is useless");
		goto error;
	}

	// give some information back
	if (!bTypeGiven) {
		printf("receivetest: device node=\"%s\"\n", szDevNode);
	} else {
		printf("receivetest: type=%s", getNameOfInterface(nType));
		switch (nType) {
		case HW_USB:
		case HW_USB_PRO:
		case HW_USB_FD:
		case HW_USB_PRO_FD:
			if (dwPort)
				printf(", %d. device\n", dwPort);
			else
				printf(", standard device\n");
			break;

		default:
			if (dwPort) {
				if (nType == HW_PCI)
					printf(", %d. PCI device", dwPort);
				else
					printf(", port=0x%08x", dwPort);
			} else
				printf(", port=default");

			if ((wIrq) && !(nType == HW_PCI))
				printf(" irq=0x%04x\n", wIrq);
			else
				printf(", irq=default\n");
			break;
		}
	}

	if (nExtended == CAN_INIT_TYPE_EX)
		printf("             Extended frames are accepted");
	else
		printf("             Only standard frames are accepted");
	if (wBTR0BTR1)
		printf(", init with BTR0BTR1=0x%04x\n", wBTR0BTR1);
	else
		printf(", init with 500 kbit/sec.\n");

	/* open CAN port */
	if ((bDevNodeGiven) || (!bDevNodeGiven && !bTypeGiven)) {
		h = LINUX_CAN_Open(szDevNode, O_RDWR);
		if (!h) {
			printf("receivetest: can't open %s\n", szDevNode);
			goto error;
		}
	} else {
		// please use what is appropriate  
		// HW_DONGLE_SJA 
		// HW_DONGLE_SJA_EPP 
		// HW_ISA_SJA 
		// HW_PCI 
		h = CAN_Open(nType, dwPort, wIrq);
		if (!h) {
			printf("receivetest: can't open %s device.\n",
				getNameOfInterface(nType));
			goto error;
		}
	}

	/* clear status */
	//  CAN_Status(h);

	// get version info
	errno = CAN_VersionInfo(h, txt);
	if (!errno)
		printf("receivetest: driver version = %s\n", txt);
	else {
		perror("receivetest: CAN_VersionInfo()");
		goto error;
	}

	// init to a user defined bit rate
	if (wBTR0BTR1) {
		errno = CAN_Init(h, wBTR0BTR1, nExtended);
		if (errno) {
			perror("receivetest: CAN_Init()");
			goto error;
		}
	}
	errno = read_loop(bDisplayOn);
	if (!errno)
		return 0;

error:
	do_exit(errno);
	return errno;
}
 bool openConnection(std::string devName) {
   h = LINUX_CAN_Open(devName.c_str(), O_RDWR);
   if (!h) return false;
   errno = CAN_Init(h, CAN_BAUD_500K, CAN_INIT_TYPE_ST);
   return true;
 }
Beispiel #13
0
// here all is done
int main(int argc, char *argv[])
{
  char *ptr;
  int i;
  const char *szDeviceNode = DEFAULT_NODE;
  
  errno = 0;

  current_release = CURRENT_RELEASE;
  disclaimer("bitratetest");

  // decode command line arguments
  for (i = 1; i < argc; i++)
  {
    char c;

    ptr = argv[i];

    while (*ptr == '-')
      ptr++;
      
    c = *ptr;
    ptr++;

    if (*ptr == '=')
      ptr++;
      
    switch(tolower(c))
    {
    	case 'f':
				szDeviceNode = ptr;
				break;
			case '?':
      case 'h':
        hlpMsg();
	      my_private_exit(0);
	      break;
	      
	    default:
	      errno = EINVAL;
	      perror("bitratetest: unknown command line argument");
	      my_private_exit(errno);
	      break;
	   }
  }
  
  // open the CAN port
  // please use what is appropriate
  // HW_DONGLE_SJA 
  // HW_DONGLE_SJA_EPP
  // HW_ISA_SJA 
  // HW_PCI
  h = LINUX_CAN_Open(szDeviceNode, O_RDWR);

  if (h)
  {
    char txt[VERSIONSTRING_LEN];

    // get version info
    errno = CAN_VersionInfo(h, txt);
    if (!errno)
      printf("bitratetest: driver version = %s\n", txt);
    else
    {
      perror("bitratetest: CAN_VersionInfo()");
      my_private_exit(errno);
    }

    printf("\n");
    
    // calculate BTR0BTR1 from bitrates
    for (i = 1000000; i > 2500; i /= 2)
    {
    	if (i == 62500)
				i = 100000;
			if (i == 6250)
				i = 10000;
				
    	printf("bitratetest: %d bits/sec \t->BTR0BTR1=0x%04x\n", i + 1,  LINUX_CAN_BTR0BTR1(h, i + 1));
    	printf("             %d bits/sec \t->BTR0BTR1=0x%04x\n", i    ,  LINUX_CAN_BTR0BTR1(h, i));
    	printf("             %d bits/sec \t->BTR0BTR1=0x%04x\n", i - 1,  LINUX_CAN_BTR0BTR1(h, i - 1));
    };
    printf("\n");
  }
  else
  {
    errno = nGetLastError();
    perror("bitratetest: CAN_Open()");
  }
    
  my_private_exit(errno);
  
  return errno;
}
Beispiel #14
0
void BVCan::initializeCan(    ){

#ifdef USE_CAN
  
  WORD awBTR0BTR1=0x0014;
 int aCANMsgType=0;


   h = NULL;

  errno = 0;


  device = string("/dev/pcan32");
  //  open the device
  //    //  O_RDWR which request opening the file read/write
  h = LINUX_CAN_Open((char*)(device.c_str()), O_RDWR);
  if (h==0)
  {
      device = string("/dev/pcan0");
      h = LINUX_CAN_Open((char*)(device.c_str()), O_RDWR);
  }
  if(h==0){
      cerr<< "PCan_Device nicht gefunden !!!"<<endl;
      exit(37);
  }
  
  
  
  if(h){
    PCAN_DESCRIPTOR *desc= (PCAN_DESCRIPTOR *)h;
    BV_ASSERT( desc->nFileNo>0 );
    BV_DEBUGINFO4NNL("BVCan::ctor device=[" << desc->szDevicePath << "]");
    BV_DEBUGINFO4C(" fd=[" << desc->nFileNo << "]" << endl);
    setfd(desc->nFileNo);
    CAN_Status(h);
    // -----------------------------------------------------------
    // returns a text string with driver version info
    errno = CAN_VersionInfo(h, info);
    if (!errno){
      string infostr( string(info) );
      BV_DEBUGINFO4("BVCan::ctor driver version=[" << infostr << "]");
    }
    else
      perror("BVCan::ctor CAN_VersionInfo()");

    wBTR0BTR1 = 0x401c; 
    if(LINUX_CAN_BTR0BTR1(h,wBTR0BTR1)==0)
      BV_WARNING("BVCan::ctor 0x" << hex << wBTR0BTR1 << dec << " is not possible" );	 
    else
      BV_DEBUGINFO4("BVCan::ctor baudrate changes to 0x" << hex << wBTR0BTR1 << dec );	      
  } 
  else
    BV_DEBUGINFO4("BVCan::ctor cannot open the can device");	  

  BV_WARNING("BVCan::initializeCan .....................");
  if(h){
    // init to a user defined bit rate
    //nExtended = CAN_INIT_TYPE_ST;
    //wBTR0BTR1 = CAN_BAUD_500K;
    canMsgType = aCANMsgType;
    wBTR0BTR1 = awBTR0BTR1;


    errno = CAN_Init(h, wBTR0BTR1, canMsgType);
    if (errno)
      perror("BVCan::initializeCan CAN_Init failed");
    else
      BV_WARNING("BVCan::initializeCan baudrate=0x" << hex << wBTR0BTR1 << dec << " msgType=" << canMsgType );
  }
  else
    BV_WARNING("BVCan::initializeCan can HANDLE is NULL");

  
  #endif

  
  
}
Beispiel #15
0
  //constructor
  CmdVelToCAN() :
      yaw_(0.0),
      throttle_(2000.0),
      reverse_on(false),
      forward(true),
      reverse(false)
  {
    nh_.param<std::string>("cmd_vel_topic", cmd_vel_topic_, "/cmd_vel");
    nh_.param<std::string>("can_device", can_device_, "/dev/pcanusb0");

    cmd_vel_sub_ = nh_.subscribe(cmd_vel_topic_, 1, &CmdVelToCAN::cmd_vel_callback, this);
    
    errno=0;
    
    char baudrate[7] = "0x0014"; //1 Mbit/s
    //char baudrate[7] = "0x001C"; //500 kbit/s
    //char baudrate[7] = "0x011C"; //250 kbit/s

    std::cout << "here scheppert dat" << std::endl;
    int wBTR0BTR1 = (int)strtoul(baudrate, NULL, 16);
    int nExtended = 0;
    
    std::cout << wBTR0BTR1 << std::endl;
    std::cout << nExtended << std::endl;
    
    h_ = LINUX_CAN_Open(can_device_.c_str(), O_RDWR);
    if (!h_) {
      ROS_ERROR("CMD_VEL_TO_CAN: can't open %s\n", can_device_.c_str());
      return;
    }
    else {
      ROS_INFO("CMD_VEL_TO_CAN: succesfully opened %s\n", can_device_.c_str());
    }
    
    /* clear status */
    CAN_Status(h_);

    errno = CAN_Init(h_, wBTR0BTR1, 0);
    std::cout << "bla bla" << std::endl;

    //prepare reverse / normal throttle msgs
    one_IEEE754 = 1;
    zero_IEEE754 = 0;
    
    reverse_throttle_msg_.ID = 3;
    reverse_throttle_msg_.MSGTYPE = MSGTYPE_STANDARD;
    reverse_throttle_msg_.LEN = 1;
    reverse_throttle_msg_.DATA[0] = one_IEEE754;

    normal_throttle_msg_.ID = 3;
    normal_throttle_msg_.MSGTYPE = MSGTYPE_STANDARD;
    normal_throttle_msg_.LEN = 1;
    normal_throttle_msg_.DATA[0] = zero_IEEE754;

    ros::Rate r(20);

    while(ros::ok()) {
      _publish();
      ros::spinOnce();
      r.sleep();
    }

 }
void pcan_transmit::init(int argc, char **argv)
{
    /*!
				 *\brief The init() function is based on the middle part of the main() function of the transmitest program.
				 *
				 * Compared to the transmitest program a lot of cases have been removed.
				 * Therefore, only the PCAN-USB adapter is, and standard messages are, supported.
				 *
				 * */




	int   nExtended = CAN_INIT_TYPE_ST;
	int nType;
	__u32 dwPort;
	__u16 wIrq;
	char *ptr;
	__u16 wBTR0BTR1 = 0x011C;
	// parameter wBTR0BTR1
	// bitrate codes of BTR0/BTR1 registers
	//#define CAN_BAUD_1M     0x0014  //   1 MBit/s
	//#define CAN_BAUD_500K   0x001C  // 500 kBit/s
    //#define CAN_BAUD_250K   0x011C  // 250 kBit/s
	//#define CAN_BAUD_125K   0x031C  // 125 kBit/s
	//#define CAN_BAUD_100K   0x432F  // 100 kBit/s
	//#define CAN_BAUD_50K    0x472F  //  50 kBit/s
	//#define CAN_BAUD_20K    0x532F  //  20 kBit/s
	//#define CAN_BAUD_10K    0x672F  //  10 kBit/s
	//#define CAN_BAUD_5K     0x7F7F  //   5 kBit/s
	const char  *szDevNode = DEFAULT_NODE;
	bool bDevNodeGiven = false;
	bool bTypeGiven = false;
	char txt[VERSIONSTRING_LEN];




   /* QApplication a(argc, argv);
    QWidget *mainWindow=new QWidget;
    mainWindow->setWindowTitle("Change the Data Value");
    QSlider *slider= new QSlider(Qt::Horizontal);
    QSpinBox *spinner= new QSpinBox;

    slider->setRange(0,100);
    spinner->setRange(0,100);

    connect(ui->slider, SIGNAL(valueChanged(double)), SLOT(onSliderValueChanged(double)));


double slidValue= ui->Slider->value();



    //string msg[]= "ID, LEN, ss";*/


    
    
    
    // decode command line arguments
		for (int i = 1; i < argc; i++)
		{
		    char c;

		    ptr = argv[i];

		    while (*ptr == '-')
		      ptr++;

		    c = *ptr;
		    ptr++;

		    if (*ptr == '=')
		      ptr++;

		    switch(tolower(c))
		    {
		      case '?':
		      case 'h':
		    	hlpMsg();
		    	do_exit(errno, h);
		        break;
		      case 'f':
		        szDevNode = ptr;
		        bDevNodeGiven = true;
		        break;
		      case 'b':
		        wBTR0BTR1 = (__u16)strtoul(ptr, NULL, 16);
		        break;
		      default:
		         errno = EINVAL;
		         do_exit(errno, h);;
		        break;
		    }
		}




		  /* open CAN port */
		   if ((bDevNodeGiven) || (!bDevNodeGiven && !bTypeGiven))
		   {
		     h = LINUX_CAN_Open(szDevNode, O_RDWR);
		     if (!h)
		     {
		       printf("pcan_transmit: can't open %s\n", szDevNode);
		       do_exit(errno, h);;
		     }
		   }
		   else {
		     // please use what is appropriate
		     // HW_DONGLE_SJA
		     // HW_DONGLE_SJA_EPP
		     // HW_ISA_SJA
		     // HW_PCI
		     h = CAN_Open(nType, dwPort, wIrq);
		     if (!h)
		     {
		       printf("pcan_transmit: can't open %s device.\n", getNameOfInterface(nType));
		       do_exit(errno, h);;
		     }
		   }
		   /* clear status */
		     CAN_Status(h);
		     // get version info
		     errno = CAN_VersionInfo(h, txt);
		     if (!errno)
		       printf("pcan_transmit: driver version = %s\n", txt);
		     else {
		       perror("pcan_transmit: CAN_VersionInfo()");
		       do_exit(errno, h);;
		     }
		     // init to a user defined bit rate
		     if (wBTR0BTR1)
		     {
		       errno = CAN_Init(h, wBTR0BTR1, nExtended);
		       if (errno)
		       {
		         perror("pcan_transmit: CAN_Init()");
		         do_exit(errno, h);;
		       }
		     }

}
int main(int argc, char *argv[])
{
  char *ptr;
  int i;
  int nType = HW_PCI;
  __u32 dwPort = 0;
  __u16 wIrq = 0;
  __u16 wBTR0BTR1 = 0;
  __u32 dwMaxTimeInterval = 0, dwMaxLoop = 0;
  char *filename = NULL;
  const char *szDevNode = DEFAULT_NODE;
  bool bDevNodeGiven = false;
  bool bTypeGiven = false;
  parser MyParser;
  char txt[VERSIONSTRING_LEN];

  errno = 0;

  current_release = CURRENT_RELEASE;
  disclaimer("transmitest");

  init();

  // decode command line arguments
  for (i = 1; i < argc; i++) 
  {
    char c;

    ptr = argv[i];

    if (*ptr == '-') 
    {
      while (*ptr == '-')
        ptr++;

      c = *ptr;
      ptr++;

      if (*ptr == '=')
      ptr++;

      switch(tolower(c)) 
      {
        case 'f':
          szDevNode = ptr;
          bDevNodeGiven = true;
          break;
        case 't':
          nType = getTypeOfInterface(ptr);
          if (!nType) 
          {
            errno = EINVAL;
            printf("transmitest: unknown type of interface\n");
            goto error;
          }
          bTypeGiven = true;
          break;
        case 'p':
          dwPort = strtoul(ptr, NULL, 16);
          break;
        case 'i':
          wIrq   = (__u16)strtoul(ptr, NULL, 10);
          break;
        case 'e':
          nExtended = CAN_INIT_TYPE_EX;
          break;
        case '?': 
        case 'h':
          hlpMsg();
          goto error;
          break;
        case 'b':
          wBTR0BTR1 = (__u16)strtoul(ptr, NULL, 16);
          break;
        case 'r':
          dwMaxTimeInterval = strtoul(ptr, NULL, 10);
          break;
        case 'n':
          dwMaxLoop = strtoul(ptr, NULL, 10);
          break;
        default:
          errno = EINVAL;
          printf("transmitest: unknown command line argument\n");
          goto error;
          break;
      }
    }
    else
      filename = ptr;
  }

  // test for filename
  if (filename == NULL) 
  {
    errno = EINVAL;
    perror("transmitest: no filename given");
    goto error;
  }

  // test device node and type
  if (bDevNodeGiven && bTypeGiven) 
  {
    errno = EINVAL;
    perror("transmitest: device node and type together is useless");
    goto error;
  }

  // give the filename to my parser
  MyParser.setFileName(filename);

  // tell some information to the user
  if (!bTypeGiven) 
  {
    printf("transmitest: device node=\"%s\"\n", szDevNode);
  }
  else {
    printf("transmitest: type=%s", getNameOfInterface(nType));
    if (nType == HW_USB) 
      printf(", Serial Number=default, Device Number=%d\n", dwPort); 
    else {
      if (dwPort) 
      {
        if (nType == HW_PCI)
          printf(", %d. PCI device", dwPort);
        else
          printf(", port=0x%08x", dwPort);
      }
      else
        printf(", port=default");
      
      if ((wIrq) && !(nType == HW_PCI))
        printf(" irq=0x%04x\n", wIrq);
      else
        printf(", irq=default\n");
    }
  }

  if (nExtended == CAN_INIT_TYPE_EX)
    printf("             Extended frames are sent");
  else
    printf("             Only standard frames are sent");
  
  if (wBTR0BTR1)
    printf(", init with BTR0BTR1=0x%04x\n", wBTR0BTR1);
  else
    printf(", init with 500 kbit/sec.\n");
    printf("             Data will be read from \"%s\".\n", filename);

  if (dwMaxTimeInterval)
    printf("             Messages are send in random time intervalls with a max. gap time of %d msec.\n", dwMaxTimeInterval);
  
  /* get the list of data from parser */
  List = MyParser.Messages();
  if (!List)
  {
    errno = MyParser.nGetLastError();
    perror("transmitest: error at file read");
    goto error;
  }
  
  /* open CAN port */
  if ((bDevNodeGiven) || (!bDevNodeGiven && !bTypeGiven)) 
  {
    h = LINUX_CAN_Open(szDevNode, O_RDWR);
    if (!h)
    {
      printf("transmitest: can't open %s\n", szDevNode);
      goto error;
    }
  }
  else {
    // please use what is appropriate  
    // HW_DONGLE_SJA 
    // HW_DONGLE_SJA_EPP 
    // HW_ISA_SJA 
    // HW_PCI 
    h = CAN_Open(nType, dwPort, wIrq);
    if (!h)
    {
      printf("transmitest: can't open %s device.\n", getNameOfInterface(nType));
      goto error;
    }
  }

  /* clear status */
  CAN_Status(h);
  
  // get version info
  errno = CAN_VersionInfo(h, txt);
  if (!errno)
    printf("transmitest: driver version = %s\n", txt);
  else {
    perror("transmitest: CAN_VersionInfo()");
    goto error;
  }
  
  // init to a user defined bit rate
  if (wBTR0BTR1) 
  {
    errno = CAN_Init(h, wBTR0BTR1, nExtended);
    if (errno) 
    {
      perror("transmitest: CAN_Init()");
      goto error;
    }
  }
  // enter in the write loop
  errno = write_loop(dwMaxTimeInterval, dwMaxLoop);
  if (!errno)
    return 0;

  error:
    do_exit(errno);
    return errno;
}