Solved

Serial Port Communication By C/C++.

Posted on 1997-06-28
3
746 Views
Last Modified: 2013-11-15
I am writing a programs to control the modem through the serial ports. I
am using the functions bioscom to try to send and receive from modem
(serial ports). I am successfully send data to the modem but fail to
receive. Some bytes have lost when try to receive data from modem.
=> any methods to solve the problems? Or
=> and other better method to communicate to the serial port?
0
Comment
Question by:matchz
  • 2
3 Comments
 

Accepted Solution

by:
UclTech earned 120 total points
ID: 1251807
Writing serial port communications is a very tricky thing.  The best way to accomplish this is to re-write the UART handler and map it to your own routine to set and handle all outbound and inbound communications.  This should be written as an interrupt service routine.

If you do not have the resources now to rewrite the routine you may just want to get a commercial package.  There are several good ones on the market.  If all you need to do is capture data for 1 sessions you might take a look at the looping code that you are using making sure that you have enough of an array to hold all of the data coming at you.  Remembering that DOS was never really designed to go over 9600.

To solve the problem take a good look at your loop routine again where you are checking the result code from _bios_serialcom.  Make sure that the Parity and Stopbits are set correctly.  The best way to track all data is to use a serial analyzer.  If you cannot get one, write a routine that will do somthing like this :

FILE *FPzdataout;
FPzdataout=fopen("modem.txt","a+");
while(getting_data_from_port)
 {
  get_data_to_buffer(lpzbuffer):
  fprintf(FPzdataout,"%s",lpzbuffer);
 }
fclose(FPzdataout);

This way you will have a "text" log of the data to and from the modem.  The best way, breaking apart your communication into the individual MAC layers is to write out the control blocks as data tags.

ACK -> " [ACK]"  to the text file in the ACK MAC layer and so forth.

0
 

Author Comment

by:matchz
ID: 1251808
Thanks you for your answer.
i have tried to use interrupt to check the com-port status and i can receive data successfuly.
however, after i have completed, the system anaylse told me that the method i am using is not allowed because the program will run on OS/2.
i also have tried to using file i/o
FILE* COM;
COM = fopen("COM2","a");
char* ATcom = "ATDT12345678";
for (int i = 0; i < strlen(ATcom; i++)
{
  fputc(*(ATcom+i),COM);  // fputc OS/2 is allowed
}

and my modem is successfully dial to the destination 12345678.
however, i cannot use the same method (fgetc)to get the data from port in the file.
how to i solve the problem again?
0
 

Expert Comment

by:UclTech
ID: 1251809
first of all stop using fopen("COM2").  That method uses the DOS MODE.COM parameters and therefore IS limited to 9600 baud.  It's even worse in OS/2 compatability windows.  Go back to using _bios_serialcom to setup the ports and use that to loop the data to and from the communication port.

(Please note I am in no way associated with this product I just think it's the best one out there).

The communications package we use here are the office is the Greenleaf ComLib ( 5.2 ) serial I/O routines.  They are fabulous.
Basic comm sessions are like this :

PORT *myport;
myport=GreenLeafOpenPort(COM2,9600L,'N',8,1,1000,1000);

Then later on.

if(RecieveBuffer(myport)>1) // data in buffer
   RecieveBuffer(myport,80,-2);

It's that simple.  The 1000,1000 is the size of the buffer in memory to create for capturing data.  The product set's up it's own internal overwrite of the UART and provides this buffering support.  It also has built in functions for dialing hayes modems, and a completly built zmodem and xmodem download routine.

Hope this helps furthur.

P.S.  Are you making the dialing and downloading a seperate thread in OS/2?  If not it's the best way to do it.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
This video demonstrates how to use each tool, their shortcuts, where and when to use them, and how to use the keyboard to improve workflow.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question