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 07-23-2015, 05:11 AM   #1
GeekyNorm
LQ Newbie
 
Registered: Jul 2015
Posts: 3

Rep: Reputation: Disabled
Thumbs up IOCTL on Linux


Hi Folks,
I'm developing a program in C++ on Linux which interacts with a USB2Serial adapter to fetch some information from the remote terminal. I was able to set the IOCTL_SERIAL_XOFF_COUNTER on windows using the following code:
Code:
#define IOCTL_SERIAL_XOFF_COUNTER       CTL_CODE(FILE_DEVICE_SERIAL_PORT,28,METHOD_BUFFERED,FILE_ANY_ACCESS)

unsigned char xoff_counter[] = {0xd0,0x07,0x00,0x00,0x05,0x00,0x00,0x00,0x13,0x00,0x00,0x00};

        bool result = DeviceIoControl(file,IOCTL_SERIAL_XOFF_COUNTER,
                                        &xoff_counter, sizeof(xoff_counter),
                                        NULL,0,
                                        &junk,
                                        &o);
I tried doing the same on Linux using the following code:
Code:
#define SERIAL_XOFF_COUNTER 28

unsigned char xoff_counter[] = {0xd0,0x07,0x00,0x00,0x05,0x00,0x00,0x00,0x13,0x00,0x00,0x00};

int retVal = ioctl(fd,SERIAL_XOFF_COUNTER,xoff_counter);
            if(retVal < 0){
                cout << "Error while setting ioctl:"<<strerror(errno)<<endl;
            }
This is raising an error when I run the program:
Code:
Error while setting ioctl:Inappropriate ioctl for device
So if any of you have done something similar before, please let me know how I can map the IOCTLs from my windows program to the corresponding calls on Linux.
TIA! Regards,
Nachiketh
 
Old 07-23-2015, 06:52 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
In a userspace program, you cannot invent new ioctls (even if they exist in Windows), only use the existing ones. See manuals of termios(3) and stty(1), also this:
http://tldp.org/HOWTO/Serial-Programming-HOWTO/
 
Old 07-24-2015, 02:21 AM   #3
GeekyNorm
LQ Newbie
 
Registered: Jul 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
In a userspace program, you cannot invent new ioctls (even if they exist in Windows), only use the existing ones. See manuals of termios(3) and stty(1), also this:
http://tldp.org/HOWTO/Serial-Programming-HOWTO/
Hi,
Thanks for the reply.
I did have a look at termios and stty, but I could not find any setting to flags to set the IOCTL_SERIAL_XOFF_COUNTER and also the IOCTL_SERIAL_LSRMST_INSERT control codes in them. Does this mean these cannot be set on Linux? Please let me know.
Thanks & Regards,
Nachiketh
 
Old 07-24-2015, 02:56 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
I think it depends on what are they supposed to do.
 
Old 07-24-2015, 03:03 AM   #5
GeekyNorm
LQ Newbie
 
Registered: Jul 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
I think it depends on what are they supposed to do.
According to the MSDN documentation:

Quote:
IOCTL_SERIAL_LSRMST_INSERT Enables or disables the placement of line status and modem status values into the regular data stream that an application acquires through the ReadFile function.
The value should be set to 255 in my application.

Quote:
The IOCTL_SERIAL_XOFF_COUNTER request sets an XOFF counter. An XOFF counter request supports clients that use software to emulate hardware handshake flow control.
This value needs to be written after writing 5 bytes of data onto the RS232 port, the value for which is the byte array which I have posted in the original question. hope this helps!

Last edited by GeekyNorm; 07-24-2015 at 03:04 AM. Reason: changed the tags
 
Old 07-24-2015, 04:00 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
That's nice, but you have to find out if they actually do something useful, and if they do then exactly what it is, and how can that be emulated in unix.
 
Old 07-28-2015, 09:55 PM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,671
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
It may well be that they cannot.

ioctl() is sort-of the "wild card" in the device-interface world: it lets you pass "a request-code and associated parameters" to the driver, but it really doesn't say what those mean. "That's strictly between you and the driver." (And furthermore, "the driver" might be provided by the vendor of the device in question.)

The operating systems in question basically "just implement the ability to get the job done." Beyond that, it's up to the driver.

Last edited by sundialsvcs; 07-28-2015 at 09:56 PM.
 
  


Reply



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
Linux ioctl help....................... xeroxdefined Linux - Newbie 2 11-17-2010 12:06 AM
How to pass IOCTL arguments from usespace ioctl call devkpict Linux - Kernel 1 12-07-2007 06:45 PM
Linux, closing CD door with ioctl()? ljubak Programming 12 09-05-2006 04:45 AM
I_CONSLOG in linux for ioctl how to dharanikumar Linux - General 0 01-03-2005 03:38 AM

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

All times are GMT -5. The time now is 11:21 AM.

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