LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-15-2018, 02:58 PM   #1
emp1952
LQ Newbie
 
Registered: Feb 2016
Posts: 6

Rep: Reputation: Disabled
Which tty designator points to my PC's only serial port?


on Fedora 19. Coding in c++
my /dev directory there are many tty designators listed. How do I know which one will use the serial port on my PC.

For my code I chose tty50.

fd = open("/dev/tty50", O_RDWR | O_NOCTTY | O_NDELAY);
It opens successfully, at least the open returns a non-negative, non-zero number, usually a 9.

cfsetispeed(&attribs, B38400);
cfsetospeed(&attribs, B38400);
When configuring the input baud and output baud there are no errors thrown.

char bytestosend[] = "hello\n";
nbytes = TEMP_FAILURE_RETRY (write (fd, bytestosend, 6));
When I go to write I get errno 11 "Resource temporarily unavailable"

Is there something else I need to do?
Can the physical serial port be left "unattached" (nothing plugged into it) just to run through this code

Thanks for any help

emp1952
 
Old 01-15-2018, 03:06 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,874
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
I'd try ttyS0 instead of tty50.
 
1 members found this post helpful.
Old 01-15-2018, 04:05 PM   #3
emp1952
LQ Newbie
 
Registered: Feb 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
Which tty port?

I have been changing to su root to chmod the ttyXX designators in /dev

I tried ttyS0 (hopefully that's a zero not a capital 'O')

I tried tty5.

same results no errors thrown for the open and baud rate assignments but for write "Resource temporarily unavailable"

Do I have to do something in the system to assign the port?

I know in Windows I had to do something like that.

Thanks

emp1952
 
Old 01-15-2018, 04:44 PM   #4
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
You have to use ioctl to control tty

see: man tty_ioctl, short example in C at the end of page
 
2 members found this post helpful.
Old 01-16-2018, 02:54 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,874
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
Also dmesg(1) might be useful:
Code:
$ dmesg | grep tty
[    0.000000] console [tty0] enabled
[    0.387384] 00:06: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
 
1 members found this post helpful.
Old 01-16-2018, 09:10 AM   #6
emp1952
LQ Newbie
 
Registered: Feb 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
Serial port c++

I am porting a Visual Basic 6 test equipment application over to Linux.
I am using Qt 4.8 and QtCreator on Fedora 19.
Qt decided not to include serial port support in version 4.8. And the version of gcc included with the Fedora installation was the wrong version for QtCreator.
I could not get the QSerialPort add on to install and work so I'm going this route with primitive serial port controls using termios.
I tried upgrading Qt to version 5+ but it corrupted my system badly. I actually had to start over from scratch.
I formatted the HD, installed a later version of Fedora and a 5+ version of Qt.
Nothing worked right, QtCreator said it couldn't work with a 5+ version of Qt. (Creator was part of the Qt 5+ install package)
I wasted 2 weeks trying to make it all work together. Finally I just reformatted again, and reinstalled Fedora 19 and Qt 4.8. Now all
is working again. I also have another computer with Red Hat 5 on it and cannot get the QSerialPort add on to install or work with that.

Thank you for your advice

emp1952
 
Old 01-16-2018, 02:56 PM   #7
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
I am using qextserialport with Qt 4.8.0: https://github.com/qextserialport/qextserialport
 
2 members found this post helpful.
Old 01-17-2018, 07:23 AM   #8
emp1952
LQ Newbie
 
Registered: Feb 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
Serial port c++

Is there a loop back capability with the serial port like there is with an internal socket?
 
Old 01-17-2018, 07:48 AM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,874
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
It requires a piece of hardware called loopback adapter.
Eg: https://support.microfocus.com/techdocs/1368.html

Last edited by NevemTeve; 01-17-2018 at 08:00 AM.
 
1 members found this post helpful.
Old 01-17-2018, 08:15 AM   #10
emp1952
LQ Newbie
 
Registered: Feb 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
Serial port c++

I can make that with what I've got here, thanks a bunch
 
  


Reply

Tags
c++, serial port



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
serial port without tty? alirezan1 Linux - Newbie 2 10-29-2013 04:04 PM
Is a USBtty (USB serial port) treated the same as tty (normal serial port) in C? spudgunner Programming 1 11-12-2010 01:19 PM
Help: tty console to serial port Rostfrei Linux - General 1 11-03-2010 04:05 AM
Porting Linux, the Serial Port, and TTY Interloper Linux - Software 2 06-25-2009 03:53 AM
TTy driver how to use underlying serial port vicky_driver Linux - Hardware 0 12-26-2008 05:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration