473,545 Members | 2,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

use of serial and parrallel port using C

Hi All,

What kind of commands can I use to control the serial and parallel port of
my pc. I want to use my laptop instead of microcontroller s and write my
software in ANSI C to be used for control purposes of sensors and other
electronic devices.

I haven't done any C for a while now so I would assume my knowledge is that
of a beginner now.

A thousand thanks for any help offered or intended.

Naveed
Nov 14 '05 #1
21 2960
"The Man With The Harmonica" <co************ ****@yahoo.co.u k> wrote in
news:cf******** **@rdel.co.uk:
Hi All,

What kind of commands can I use to control the serial and parallel port
of my pc.


None. ISO C doesn't have any commands nor does it know anything about
serial or parrallel ports. You'll need to ask this in a newsgroup that
programs for the platform you are using, e.g. DOS, Linux, Win32, etc.

--
- Mark ->
--
Nov 14 '05 #2
The Man With The Harmonica wrote:
Hi All,

What kind of commands can I use to control the serial and parallel port of
my pc. I want to use my laptop instead of microcontroller s and write my
software in ANSI C to be used for control purposes of sensors and other
electronic devices.

I haven't done any C for a while now so I would assume my knowledge is that
of a beginner now.

A thousand thanks for any help offered or intended.

Naveed


news:comp.arch. embedded

One can use ANSI C to access serial ports and parallel ports
as well as other devices as long as those devices are memory
mapped. Whether the operating system, if there is one, allows
this is a different issue.

However, this code would be platform specific and not portable
to platforms that do not have the same memory mapping.

The technique is to access the hardware devices by dereferencing
pointers. For example, one would assign a pointer to an integer
with the value of the device's address:
volatile unsigned char * Serial_Receive_ Register =
(volatile unsigned char *) 0x40000;

unsigned char Read_Serial_Por t(void)
{
return * Serial_Receive_ Register;
}

Before reading the receive register, one should check that
the status first and also have a design to handle when
nothing has been received.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 14 '05 #3
# What kind of commands can I use to control the serial and parallel port of
# my pc. I want to use my laptop instead of microcontroller s and write my
# software in ANSI C to be used for control purposes of sensors and other
# electronic devices.

Depends in part on whether the operating system provides file names for
those devices that you can fopen. For example on unices, you can open
serial ports with file names like "/dev/ttyS0".

--
SM Ryan http://www.rawbw.com/~wyrmwif/
The whole world's against us.
Nov 14 '05 #4
In <6i************ *****@newssvr17 .news.prodigy.c om> Thomas Matthews <Th************ *************** *@sbcglobal.net > writes:
The Man With The Harmonica wrote:
Hi All,

What kind of commands can I use to control the serial and parallel port of ^^ my pc. I want to use my laptop instead of microcontroller s and write my ^^^^^ ^^^^^^^^^
software in ANSI C to be used for control purposes of sensors and other
electronic devices.

I haven't done any C for a while now so I would assume my knowledge is that
of a beginner now.
news:comp.arch .embedded


Since when do PC's count as embedded control systems?
One can use ANSI C to access serial ports and parallel ports
as well as other devices as long as those devices are memory
mapped.
Chapter and verse, please.
Whether the operating system, if there is one, allows
this is a different issue.
If ANSI C supported the feature, the OS would be irrelevant.
However, this code would be platform specific and not portable
to platforms that do not have the same memory mapping.
Then, it wouldn't be code blessed by ANSI C.
The technique is to access the hardware devices by dereferencing
pointers. For example, one would assign a pointer to an integer
with the value of the device's address:
volatile unsigned char * Serial_Receive_ Register =
(volatile unsigned char *) 0x40000;


According to ANSI C, any attempt to use this pointer value results in
undefined behaviour.

The *right* thing is to use the OS interface to the serial port. The
kind of code you're showing belongs exclusively to device drivers and
is highly unlikely to work in userland programs. Imagine what happens
when two programs attempt to access the same port directly, at the same
time (assuming that it would be possible): complete chaos.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #5
"Mark A. Odell" <od*******@hotm ail.com> wrote in message
news:Xn******** *************** *********@130.1 33.1.4...
"The Man With The Harmonica" <co************ ****@yahoo.co.u k> wrote in
news:cf******** **@rdel.co.uk:
Hi All,

What kind of commands can I use to control the serial and parallel port
of my pc.


None. ISO C doesn't have any commands nor does it know anything about
serial or parrallel ports. You'll need to ask this in a newsgroup that
programs for the platform you are using, e.g. DOS, Linux, Win32, etc.

--
- Mark ->
--


Hi Mark,

I'm using an old Toshiba laptop with win95. I want to use the parallel port
to control some circuits and to read the state of some control lines.
Basically its going to be controlling a four wheeled buggy and I want to do
this using C and through the parallel port.

thanks

Naveed
Nov 14 '05 #6
On Thu, 19 Aug 2004 16:51:06 +0100
"The Man With The Harmonica" <co************ ****@yahoo.co.u k> wrote:
"Mark A. Odell" <od*******@hotm ail.com> wrote in message
news:Xn******** *************** *********@130.1 33.1.4...
"The Man With The Harmonica" <co************ ****@yahoo.co.u k> wrote
in news:cf******** **@rdel.co.uk:
What kind of commands can I use to control the serial and parallel
port of my pc.


None. ISO C doesn't have any commands nor does it know anything
about serial or parrallel ports. You'll need to ask this in a
newsgroup that programs for the platform you are using, e.g. DOS,
Linux, Win32, etc.


I'm using an old Toshiba laptop with win95. I want to use the
parallel port to control some circuits and to read the state of some
control lines. Basically its going to be controlling a four wheeled
buggy and I want to do this using C and through the parallel port.


So go and ask on a a group for you platform as Mark suggested. Standard
C does not provide you with any way to to what you want and this group
talks about standard C.
--
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.
Nov 14 '05 #7
# So go and ask on a a group for you platform as Mark suggested. Standard
# C does not provide you with any way to to what you want and this group
# talks about standard C.

Still shooting from the hip and blowing off your own toes. Depending on
the operating system, it may be possible to fopen a device name and
then use stdio to read/write the port.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Why are we here?
whrp
Nov 14 '05 #8
SM Ryan wrote:

# So go and ask on a a group for you platform as Mark suggested. Standard
# C does not provide you with any way to to what you want and this group
# talks about standard C.

Still shooting from the hip and blowing off your own toes. Depending on
the operating system, it may be possible to fopen a device name and
then use stdio to read/write the port.

Exactly how stupid are you? There is no standard way to do that. There
are only platform-specific ways, and so the person seeking the
information should go ask on a newsgroup dedicated to the specific
platform.

Since you first graced our newsgroup, you've been a fount of bad
information and bad attitude, as well as continuing to use those
non-standard reply delimiters.

Brian Rodenborn
Nov 14 '05 #9
On Thu, 19 Aug 2004 21:33:23 -0000
SM Ryan <wy*****@tang o-sierra-oscar-foxtrot-tango.fake.org> wrote:
# So go and ask on a a group for you platform as Mark suggested.
Standard# C does not provide you with any way to to what you want and
this group# talks about standard C.

Still shooting from the hip and blowing off your own toes. Depending ^^^^^^^^^ on the operating system, it may be possible to fopen a device name and ^^^^^^^^^^^^^^^ ^^^^^^^^ then use stdio to read/write the port.


You said it yourself, it DEPENDS ON THE OPERATING SYSTEM. Therefor it
needs to be asked in a group dealing with the operating system. If the
OP find it can be done using fopen and friends, then questions can be
asked about the things which can be done in standard C. However, if the
OP knew that was possible then the question would not have been asked.
--
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4575
by: rusttree | last post by:
Many moons ago, I took a class in embedded control at school. The course focused on a micro-controller mounted on a small electric car that was programmed using simple C code. The micro-controller chip had several pins, some of which were for output and some were for input. The crux of the project was to make the program set the ouput pins...
3
5029
by: collinm | last post by:
hi i send a command to a led display, the led display is suppose to return me some character i write a string on a serial port void ledDisplayExist() { char msg={'\0', '\0', '\0', '\0', '\0', '\1', 'Z', '0', '0',
4
11164
by: joe bloggs | last post by:
I am writing a mobile application to interface with a legacy system and I am planning to use web services to communicate with this system. The legacy system receives data through a serial port. What I would like to do is make the serial port accessible via a web service. The web service and the legacy application would be running on the...
4
17787
by: Frank | last post by:
Hello, how to get information about all serial ports in the PC? I use the following code, but i got only the data of the FIRST serial port. All other serial port information are not available with this code sample: ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * from WIN32_SerialPort");
5
2317
by: Franklin M. Gauer III | last post by:
Hi All, I've written an ASP.NET application (webservice) that does simple serial communications via the .NET 2.0 SerialComm object. The application runs fine on my development machine. The problem is when we try to deploy it to another machine we receive: ACCESS IS DENIED TO COM1 PORT. We have tried unsuccessfully to get this to work....
7
5370
by: davetelling | last post by:
I'm a newbie that is still struggling with OOP concepts & how to make things work they way I want. Using Visual C# Express, I have a form in which I added a user control to display a graph, based upon data received via the serial port. If I run the serial port in the main form code, I can get data and, using public properties of the user...
4
11683
by: rowan | last post by:
I'm writing a driver in Python for an old fashioned piece of serial equipment. Currently I'm using the USPP serial module. From what I can see all the serial modules seem to set the timeout when you open a serial port. This is not what I want to do. I need to change the timeout each time I do a "read" on the serial port, depending on which...
3
11553
by: naveen.sabapathy | last post by:
Hi, I am trying to use virtual serial ports to develop/test my serial communication program. Running in to trouble... I am using com0com to create the virtual ports. The virtual ports seem to be working fine when I test it with Hyperterminal . I am using the example program that comes with pyserial, as below. --------------- import...
6
6635
by: terry | last post by:
Hi, I am trying to send a character to '/dev/ttyS0' and expect the same character and upon receipt I want to send another character. I tired with Pyserial but in vain. Test Set up: 1. Send '%' to serial port and make sure it reached the serial port. 2. Once confirmed, send another character.
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7423
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7757
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4945
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1884
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
704
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.