Solved

Serial Port Communication By C/C++.

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

920 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