Across USB with UART

More
02 Dec 2014 16:22 #53595 by t1m0n
Across USB with UART was created by t1m0n
Hi, I have a crazy problem.
Across USB, I communicate with an arduino via UART.
I develope a special HAL component for this way.

The crazy problem is, that before I can use my component I have to start PuTTY.
If I start linux with my component at first, no communication will be established.
But if I have established the communication via PuTTY at first, I can start the communication without any problems.

I use linuxcnc 2.5.4 with rtai.
I have installed the system from the livecd.

The hole source code is realy big, I post only the serial communication setup:
			int fd0 = serial_setup();
			if(fd0==0)
			{
				fd = open(DEVICE, O_RDWR | O_NOCTTY | O_NDELAY);
				cfsetispeed(&toptions, BAUDRATE); // sets the input baud rate
				cfsetospeed(&toptions, BAUDRATE); // sets the output baud rate
				tcflush(fd, TCIOFLUSH); // flush data received but not read, and data written but not transmitted
			}
int serial_setup()
{
	static char* USER;
	static char CONFIG_FILE[100];
	USER = getenv("USERNAME");;
	if(USER == NULL)  
	{
		return -1;
	}

	strcpy(CONFIG_FILE, "/home/");
	strcat(CONFIG_FILE, USER);
	strcat(CONFIG_FILE, "/linuxcnc/nc_files/programme+/halcomps/arduinocontroller_device");

	FILE* fdConfig = fopen(CONFIG_FILE, "r");
	if(fdConfig == NULL)  
	{
		return -1;
	}
	fgets(DEVICE, sizeof(DEVICE), fdConfig);
	DEVICE[strlen(DEVICE)-1] = '\0';
	fscanf(fdConfig, "%i", &BAUDRATE);
	fclose(fdConfig);
	return 0;
}
Does someone know this problem?

Please Log in or Create an account to join the conversation.

More
02 Dec 2014 17:29 #53598 by ArcEye
Replied by ArcEye on topic Across USB with UART
Hi

The only thing I can think of is that you are only setting the baudrate and none of the toptions
I don't know what putty does to connect and if this causes any to be set.

If you try the setup code as per my serialcon.comp here, that may assist.
www.linuxcnc.org/index.php/english/forum...pendant-for-linuxcnc

I know that it works for serial over USB with an Arduino and connects on its own without needing a prior connection.

regards

Please Log in or Create an account to join the conversation.

Time to create page: 0.070 seconds
Powered by Kunena Forum