Solved

Serial Port Communication By C/C++.

Posted on 1997-06-28
3
738 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Ticketing System/ Asset Tag tracking. 4 42
Team Foundation Server 8 44
Line meaning 9 76
Denali Software 2 15
Today companies are subjected to more-and-more data, and it won't stop any time soon.  But there are obvious opportunities for reducing data, particularly data duplicated among companies.
A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
Viewers will learn how to use the Hootsuite Dashboard.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now