How do i select correct active serial port in linux

0 votes

I am trying to communicate with a microcontroller using java. In windows, I simply use "COM4" and my code works perfectly. In Linux i am trying to use "/dev/ttyUSB0". But gives me an error "Could not find serial port".

I used dmesg | grep to try to see the active serial port. is this the right method?

how can I solve this issue? I am really new to Linux so please explain in simple language

Here is my code:

Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers(); CommPortIdentifier portId = null; while (portIdentifiers.hasMoreElements()) { CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers.nextElement(); if(pid.getPortType() == CommPortIdentifier.PORT_SERIAL && pid.getName().equals("/dev/ttyUSB0")) { portId = pid; break; } } if(portId == null) { System.err.println("Could not find serial port "); // + wantedPortName); System.exit(1); }

Apr 13, 2022 in Linux Administration by Soham
• 9,710 points
565 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Linux Administration

0 votes
2 answers

How do I find all files containing specific text and rename in unix/linux

Hi, @Kal You can use this command below to ...READ MORE

answered Jul 2, 2019 in Linux Administration by Gitika
• 65,770 points

edited Jul 2, 2019 by Gitika 2,724 views
0 votes
0 answers

How do I copy folder with files to another folder in Unix/Linux?

I am having some issues copying a ...READ MORE

Apr 13, 2022 in Linux Administration by Soham
• 9,710 points
380 views
0 votes
0 answers

How do I copy folder with files to another folder in Unix/Linux?

I am having some issues to copy ...READ MORE

Apr 21, 2022 in Linux Administration by Edureka
• 13,690 points
403 views
0 votes
2 answers

How do I find all files containing specific text on Linux?

grep -rnw 'text to find recursively inside ...READ MORE

answered May 20, 2019 in Linux Administration by Ritesh Singh
40,400 views
0 votes
2 answers

How do I use a shell script to SSH in to a remote machine to execute commands?

Sorry in advance for any formatting. Check out ...READ MORE

answered Feb 7, 2021 in Linux Administration by anonymous
17,307 views
0 votes
1 answer

How do i enable universe repository in Ubuntu 18.04?

If you want in one command and ...READ MORE

answered Aug 27, 2019 in Linux Administration by Sirajul
• 59,230 points
7,341 views
0 votes
1 answer
0 votes
1 answer

Serverspec doesn't check package version correctly

Specinfra is escaping the characters in the with_version chain ...READ MORE

answered Aug 2, 2018 in DevOps Tools by Kalgi
• 52,350 points
1,341 views
0 votes
1 answer

How do I set variable if a specific package version is installed in CFEngine?

Here is what you can do.Just use packagesmatching to ...READ MORE

answered Jul 12, 2018 in Other DevOps Questions by Atul
• 10,240 points
1,180 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP