473,395 Members | 1,383 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Basic messenger via serial port

344 100+
Hello everyone,

What I'm trying to do is a basic messenger (char receiver/ transmitter) via serial port in a console application.
in main function i call setup_configuration function ---- no poroblem
then i use two functions; transmit, receive as follow:

Expand|Select|Wrap|Line Numbers
  1. void transmit (char ch)
  2. {
  3. do{
  4.  int y = inportb(0x3fd);
  5.  y = y & 0x40;
  6. }while (y == 0);
  7. outportb(0x3f8, (int) ch);
  8. }
Expand|Select|Wrap|Line Numbers
  1. char receive ()
  2. {
  3. if( inport (0x3fd) & 1 == 1)
  4. return inport (0x3f8);
  5. return -1;
  6. }
I've no error, but the problem is i check if there is a received char in the register and print it or not, but for transmitting a char i should use cin, or getch, getche.
any function of them i have to wait until the user enter a char, so i stopped from receiving.. i have to execute only one statement at a time.

I use console so there is no events and event handler, i don't want to go to threads to monitor both transmit and receive.

If anyone can help me, I'll be thankful.
Dec 31 '08 #1
6 1808
gpraghuram
1,275 Expert 1GB
You have to use select function call to monitor for input or output and then call your function to read it.


Raghu
Dec 31 '08 #2
Bassem
344 100+
Sorry Raghu, can you explain a little!
Dec 31 '08 #3
gpraghuram
1,275 Expert 1GB
Select is a system call with which you can find whether data is available on the file descriptor.
Read this for more info on select.

Raghu
Dec 31 '08 #4
weaknessforcats
9,208 Expert Mod 8TB
Have you considered placing your tramsmit on one thread and the receive on another thread? That way you can tramsmit and receive independently.
Dec 31 '08 #5
Bassem
344 100+
Thanks Raghu,
but i couldnt understand select function.

it seems noway to use multiple threads as weaknessforcats said, and that was i'm trying to avoid, because i didn't deal with threads in c++.

Thanks all for your help,
Bassem
Jan 1 '09 #6
weaknessforcats
9,208 Expert Mod 8TB
Multuthreading is not that hard.

Each thread is basically a function call and your operating system already API functions to create threads from these functions and to allow you to communicate from one thread to another.

There is also a critical section where one thread can block other threads to gain update access to data shared between the threads without fear of the other thread trying to so the same at the same time.

A simple program like this should go pretty quick.
Jan 1 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: CHANGE username to westes | last post by:
What are the most popular, and well supported, libraries of drivers for bar code scanners that include a Visual Basic and C/C++ API? My requirements are: - Must allow an application to be...
3
by: Jay Patel | last post by:
Hello, I need to write visual basic.net code to interface with a Mettler Toledo Shipping Scale that interfaces with a PC via USB or a serial port. I have seen example code on how to communicate...
2
by: thecamisland | last post by:
I'm trying to communicate with Durant Ambassador counter through serial port. All I have is an old piece of BASIC code. I have managed to convert a portion of this old BASIC code to VB6 and I can...
13
by: Rob | last post by:
Hi all, I am fairly new to python, but not programming and embedded. I am having an issue which I believe is related to the hardware, triggered by the software read I am doing in pySerial. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.