Serial Port Communication By C/C++.

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?
matchzAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

UclTechCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
matchzAuthor Commented:
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
UclTechCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Software

From novice to tech pro — start learning today.