Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am new comer to linux programing.I need to run a multithreaded application which will read and write data to 7 UART ports.
for each UART port there will be 2 deidcated threads (i.e. read and write threads).I have a c++ code which creates thread to read and write data to any particualr UART port.But i want to run all the 7 ports parallel.Plese help me to know how i need to modify the below code so that it can create 7 write and read threads for 7 UART ports and could simultaneoulsy read/write from/to all the ports.
Thank u so much in advance.
int m_fd = -1;
struct termios m_tio;
int trun = 1;
int rrun = 1;
pthread_t p_Uartsend, p_Uartread;
char test_str[] = "All questions asked by five watch experts amazed the judge.The quick brown fox jumps over the lazy dog.The five boxing wizards jump quickly.\r\n";
int main(int argc, char *argv[])
{
if (argc < 2)
{
printf("Insufficient arguments, exiting\n");
exit(EXIT_FAILURE);
}
// setup serial port
Serial_setupData_t port;
port.uart_dev_name[0] = '\0'; // No name for default
port.uart_dev_name[MAX_UART_NAME_LEN - 1] = '\0'; // Null terminate
Please use [code][/code]] tags to enclose your code. There are instructions in the LQ FAQ as well as instructions in one of my signature links. Or just observe the advanced edit mode tools to see how to do that.
I'm not sure you need threads, I do a lot of multiple serial receive and transmit with either multiple processes or just one process and the needed file descriptors per serial interface.
How fast are the serial connections?
Is the data coming in continuously, or not?
What do you need to do with the data when received? Plot? Save? Retransmit? Decode and act upon?
When you next post code I recommend that you do the following:
Post complete code sections which compile. The code you've posted has far too many errors, undefined values, unresolved definitions
Separate the chunks. You have one section that is your main and then your intended receive and transmit functions. For me it's clearly more helpful to see the code, but also be informed that a particular section has been tested, debugged, and is not considered to be your problem.
You can consider viewing my blog entries on select(), and one on a USB serial receive parser. These illustrate how to do things like manage UART transmit and receive, decode of frames, and check multiple file descriptors for data.
Just saying you need to do the following sounds more like an assignment versus that you've envisioned an architecture like this for a particular reason.
You've posted code. Please explain where this code falls short and also what it does do at this point.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.