Example #1
0
int dxl_hal_open(int deviceIndex, float baudrate)
{
	struct termios newtio;
	//struct serial_struct serinfo;
	char dev_name[100] = {0, };

	sprintf(dev_name, "/dev/ttyACM%d", deviceIndex); // USB2AX is ttyACM

	strcpy(gDeviceName, dev_name);
	memset(&newtio, 0, sizeof(newtio));
	dxl_hal_close();
	
	if((gSocket_fd = open(gDeviceName, O_RDWR|O_NOCTTY|O_NONBLOCK)) < 0) {
		fprintf(stderr, "device open error: %s\n", dev_name);
		goto DXL_HAL_OPEN_ERROR;
	}

	newtio.c_cflag		= B1000000|CS8|CLOCAL|CREAD;
	newtio.c_iflag		= IGNPAR;
	newtio.c_oflag		= 0;
	newtio.c_lflag		= 0;
	newtio.c_cc[VTIME]	= 0;	// time-out 값 (TIME * 0.1초) 0 : disable
	newtio.c_cc[VMIN]	= 0;	// MIN 은 read 가 return 되기 위한 최소 문자 개수

	tcflush(gSocket_fd, TCIFLUSH);
	tcsetattr(gSocket_fd, TCSANOW, &newtio);
	
	if(gSocket_fd == -1)
		return 0;

	dxl_hal_close();
	
	gfByteTransTime = (float)((1000.0f / baudrate) * 12.0f);
	
	strcpy(gDeviceName, dev_name);
	memset(&newtio, 0, sizeof(newtio));
	dxl_hal_close();
	
	if((gSocket_fd = open(gDeviceName, O_RDWR|O_NOCTTY|O_NONBLOCK)) < 0) {
		fprintf(stderr, "device open error: %s\n", dev_name);
		goto DXL_HAL_OPEN_ERROR;
	}

	newtio.c_cflag		= B1000000|CS8|CLOCAL|CREAD;
	newtio.c_iflag		= IGNPAR;
	newtio.c_oflag		= 0;
	newtio.c_lflag		= 0;
	newtio.c_cc[VTIME]	= 0;	// time-out 값 (TIME * 0.1초) 0 : disable
	newtio.c_cc[VMIN]	= 0;	// MIN 은 read 가 return 되기 위한 최소 문자 개수

	tcflush(gSocket_fd, TCIFLUSH);
	tcsetattr(gSocket_fd, TCSANOW, &newtio);
	
	return 1;

DXL_HAL_OPEN_ERROR:
	dxl_hal_close();
	return 0;
}
int dxl_hal_open()
{
	FT_STATUS ft_status;

	dxl_hal_close();

	ft_status = FT_Open( 1, &ghFt_Handle );
	if( ft_status != FT_OK )
		goto DXL_HAL_OPEN_ERROR;

	ft_status = FT_ResetDevice( ghFt_Handle );
	if( ft_status != FT_OK )
		goto DXL_HAL_OPEN_ERROR;

	ft_status = FT_SetDataCharacteristics( ghFt_Handle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE );
	if( ft_status != FT_OK )
		goto DXL_HAL_OPEN_ERROR;

	ft_status = FT_SetFlowControl( ghFt_Handle, FT_FLOW_NONE, (UCHAR)0, (UCHAR)0 );
	if( ft_status != FT_OK )
		goto DXL_HAL_OPEN_ERROR;

	ft_status = FT_SetLatencyTimer( ghFt_Handle, LATENCY_TIME );
	if( ft_status != FT_OK )
		goto DXL_HAL_OPEN_ERROR;

	ft_status = FT_SetUSBParameters( ghFt_Handle, IN_TRASFER_SIZE, 0 );
	if( ft_status != FT_OK )
		goto DXL_HAL_OPEN_ERROR;

	ft_status = FT_SetTimeouts( ghFt_Handle, 0, 0 );
	if( ft_status != FT_OK )
		goto DXL_HAL_OPEN_ERROR;

	ft_status = FT_Purge( ghFt_Handle, FT_PURGE_RX|FT_PURGE_TX );
	if( ft_status != FT_OK )
		goto DXL_HAL_OPEN_ERROR;

	return 1;

DXL_HAL_OPEN_ERROR:
	dxl_hal_close();
	return 0;
}
void dxl_terminate()
{
	dxl_hal_close();
}
Example #4
0
void TerminateDXL(void) {
  dxl_hal_close();
}
Example #5
0
void dxl_terminate()
{
	gbIsDynmixelUsed = 0; //[ROBOTIS]2012-12-13 to notify end of using dynamixel SDK to uart.c
	dxl_hal_close();
}
Example #6
0
int CDXL_hal::dxl_hal_open(int deviceIndex, float baudrate)
{
	struct termios newtio;
	struct serial_struct serinfo;
	char dev_name[100] = {0, };

	sprintf(dev_name, "/dev/ttyUSB%d", deviceIndex);

	strcpy(gDeviceName, dev_name);
	memset(&newtio, 0, sizeof(newtio));
	dxl_hal_close();

	if((gSocket_fd = open(gDeviceName, O_RDWR|O_NOCTTY|O_NONBLOCK)) < 0) {
		fprintf(stderr, "device open error: %s\n", dev_name);
		goto DXL_HAL_OPEN_ERROR;
	}

	newtio.c_cflag		= B38400|CS8|CLOCAL|CREAD;
	newtio.c_iflag		= IGNPAR;
	newtio.c_oflag		= 0;
	newtio.c_lflag		= 0;
	newtio.c_cc[VTIME]	= 0;	// time-out 값 (TIME * 0.1초) 0 : disable
	newtio.c_cc[VMIN]	= 0;	// MIN 은 read 가 return 되기 위한 최소 문자 개수

	tcflush(gSocket_fd, TCIFLUSH);
	tcsetattr(gSocket_fd, TCSANOW, &newtio);

	if(gSocket_fd == -1)
		return 0;

	if(ioctl(gSocket_fd, TIOCGSERIAL, &serinfo) < 0) {
		fprintf(stderr, "Cannot get serial info\n");
		return 0;
	}

	serinfo.flags &= ~ASYNC_SPD_MASK;
	serinfo.flags |= ASYNC_SPD_CUST;
	serinfo.custom_divisor = serinfo.baud_base / baudrate;

	if(ioctl(gSocket_fd, TIOCSSERIAL, &serinfo) < 0) {
		fprintf(stderr, "Cannot set serial info\n");
		return 0;
	}

	dxl_hal_close();

	gfByteTransTime = (float)((1000.0f / baudrate) * 12.0f);

	strcpy(gDeviceName, dev_name);
	memset(&newtio, 0, sizeof(newtio));
	dxl_hal_close();

	if((gSocket_fd = open(gDeviceName, O_RDWR|O_NOCTTY|O_NONBLOCK)) < 0) {
		fprintf(stderr, "device open error: %s\n", dev_name);
		goto DXL_HAL_OPEN_ERROR;
	}

	newtio.c_cflag		= B38400|CS8|CLOCAL|CREAD;
	newtio.c_iflag		= IGNPAR;
	newtio.c_oflag		= 0;
	newtio.c_lflag		= 0;
	newtio.c_cc[VTIME]	= 0;	// time-out 값 (TIME * 0.1초) 0 : disable
	newtio.c_cc[VMIN]	= 0;	// MIN 은 read 가 return 되기 위한 최소 문자 개수

	tcflush(gSocket_fd, TCIFLUSH);
	tcsetattr(gSocket_fd, TCSANOW, &newtio);

	return 1;

DXL_HAL_OPEN_ERROR:
	dxl_hal_close();
	return 0;
}
Example #7
0
int dxl_hal_open( int devIndex, float baudrate )
{
	// Opening device
	// devIndex: Device index
	// baudrate: Real baudrate (ex> 115200, 57600, 38400...)
	// Return: 0(Failed), 1(Succeed)

	DCB Dcb;
	COMMTIMEOUTS Timeouts;
	DWORD dwError;
	char PortName[15];

	dxl_hal_close();

	// Make real port name
	sprintf(PortName, "\\\\.\\COM%d", devIndex);
	// Open serial device
	ghSerial_Handle = CreateFile( PortName, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
	if( ghSerial_Handle == INVALID_HANDLE_VALUE )
		return 0;

	// Setting communication property
	Dcb.DCBlength = sizeof(DCB);
	if( GetCommState( ghSerial_Handle, &Dcb ) == FALSE )
		goto DXL_HAL_OPEN_ERROR;
	
	// Set baudrate
	gfByteTransTime = 1000.0f / baudrate * 10.0f; // 1000/baudrate(bit per msec) * 10(start bit + data bit + stop bit)
	Dcb.BaudRate			= (DWORD)baudrate;	
	Dcb.ByteSize			= 8;					// Data bit = 8bit
	Dcb.Parity				= NOPARITY;				// No parity
	Dcb.StopBits			= ONESTOPBIT;			// Stop bit = 1
	Dcb.fParity				= NOPARITY;				// No Parity check
	Dcb.fBinary				= 1;					// Binary mode
	Dcb.fNull				= 0;					// Get Null byte
	Dcb.fAbortOnError		= 1;
	Dcb.fErrorChar			= 0;
	// Not using XOn/XOff
	Dcb.fOutX				= 0;
	Dcb.fInX				= 0;
	// Not using H/W flow control
	Dcb.fDtrControl			= DTR_CONTROL_DISABLE;
	Dcb.fRtsControl			= RTS_CONTROL_DISABLE;
	Dcb.fDsrSensitivity		= 0;
	Dcb.fOutxDsrFlow		= 0;
	Dcb.fOutxCtsFlow		= 0;
	if( SetCommState( ghSerial_Handle, &Dcb ) == FALSE )
		goto DXL_HAL_OPEN_ERROR;

	if( SetCommMask( ghSerial_Handle, 0 ) == FALSE ) // Not using Comm event
		goto DXL_HAL_OPEN_ERROR;
	if( SetupComm( ghSerial_Handle, 4096, 4096 ) == FALSE ) // Buffer size (Rx,Tx)
		goto DXL_HAL_OPEN_ERROR;
	if( PurgeComm( ghSerial_Handle, PURGE_TXABORT|PURGE_TXCLEAR|PURGE_RXABORT|PURGE_RXCLEAR ) == FALSE ) // Clear buffer
		goto DXL_HAL_OPEN_ERROR;
	if( ClearCommError( ghSerial_Handle, &dwError, NULL ) == FALSE )
		goto DXL_HAL_OPEN_ERROR;
	
	if( GetCommTimeouts( ghSerial_Handle, &Timeouts ) == FALSE )
		goto DXL_HAL_OPEN_ERROR;
	// Timeout (Not using timeout)
	// Immediatly return
	Timeouts.ReadIntervalTimeout = 0;
	Timeouts.ReadTotalTimeoutMultiplier = 0;
	Timeouts.ReadTotalTimeoutConstant = 1; // must not be zero.
	Timeouts.WriteTotalTimeoutMultiplier = 0;
	Timeouts.WriteTotalTimeoutConstant = 0;
	if( SetCommTimeouts( ghSerial_Handle, &Timeouts ) == FALSE )
		goto DXL_HAL_OPEN_ERROR;
	
	return 1;

DXL_HAL_OPEN_ERROR:
	dxl_hal_close();
	return 0;
}