bioscom(1,'s',COM3)

This is a discussion on bioscom(1,'s',COM3) within the C Programming forums, part of the General Programming Boards category; Hi all, I m doing one c program for serial communication.In that i want to send request to one hardware ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    2

    bioscom(1,'s',COM3)

    Hi all,
    I m doing one c program for serial communication.In that i want to send request to one hardware module, after receiving my request that h/w send me one frame with predefined format.

    CPP / C++ / C Code:
    Code:
    /*
    Program SERIALCOMMUNICATION.C is used for PC to PC or PC to Hardware
    Communication.
    
    */
    #include<bios.h>
    #include<stdio.h>
    #include<string.h>
    #include<conio.h>
    #include<time.h>
    
    #define COM3       2
    #define DATA_READY 0x100
    #define SETTINGS ( 0xE0   |   0x03      |   0x00     | 0x00)
    			  //baud 9600 | 8 data bits |  no parity | 1 stop bit
    void main()
    {
    	int status;
    	unsigned char out,in;
    	char another,option;
    	FILE *rfile,*wfile;
    	int DONE=0,i=0,p=0,k=0;
    	int Count=0;
       unsigned	char rcvdata[80];
       char sendrequest[21]="Start,SendRequest,End";
       time_t timer;
       struct tm *tblock;
    	timer = time(NULL);
    	 printf("\n");
    	clrscr();
    	bioscom(0, SETTINGS, COM3);
    	printf("\n\n*********************************************************\n\n");
    	printf("\t1. Send Request For Current Time Frame\n");
    	printf("\t2. Escape");
    	printf("\n\n**********************************************************\n\n");
    	printf("Your Choice If you want,Otherwise wait for next Frame? :\n");
    
    
    	rfile=fopen("RECEIVE.TXT","a");
    	wfile=fopen("SEND.TXT","a");
    	while (!DONE)
    	{
    		 status = bioscom(3, 0, COM3);
    
    		if(status & DATA_READY)
    		{
    			if((out =(unsigned char)bioscom(2, 0, COM3)) != 0)// input message byte.
    			{
    				if((int)out==8 && Count>0)
    				{
    					Count=Count-1;
    				}
    				else
    				{
    					rcvdata[Count]=out; //Store char in buffer
    					Count++;
    				}
    			}
    			if(out==13)
    			{
    				fprintf(rfile,"\n");
    				for(i=0;i<Count-1;i++)
    					fprintf(rfile,"%c",rcvdata[i]);
    				for(p=0;p<Count-1;p++)
    					printf("%c",rcvdata[p]);
    				printf("\n");
    				Count=0;
    			}
    	   }
    	   if (kbhit())   //character entered
    	   {
    			option=getche();
    
    			switch(option)
    				{
    					case '1' :
    						printf("\nSend Request:");
    						 /* converts date/time to a structure */
    						   tblock = localtime(&timer);
    						  fprintf(wfile,"\nRequest sent at:%s:", asctime(tblock));
    						for(k=0;k<21;k++)
    						{
    							bioscom(1,sendrequest[k],COM3);
    							printf("%c",sendrequest[k]);
    							fprintf(wfile,"%c",sendrequest[k]);
    						}
    						printf("\n");
    						fprintf(wfile,"\n");
    						break;
    					case '2' :
    					case 27 :
    						DONE=1;
    						break;
    					default :
    						printf("\nPress Correct option i.e. either 1 or 2\n");
    
    				}
    			}
    
    	   }
    	fclose(rfile);
    	fclose(wfile);
    }
    Now after compiling it gives zero errors.
    When I execute this program, it receives all things (hardware sent) but send nothing,not a single char.
    Please tell me if anything wrong in my code

    Thanks in advance

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Supposedly, this function should return a result, where bit 7 indicates whether there is an error (1) or not (0). Use the status function to check what the error code was (in the upper 8 bits of the status.
    Code:
    bioscom(1,sendrequest[k],COM3);
    Curious as to why you need two loops here (and why you feel a need to use two different variables - that in itself is completely needless, even if there was a good reason to have two loops):
    Code:
    			if(out==13)
    			{
    				fprintf(rfile,"\n");
    				for(i=0;i<Count-1;i++)
    					fprintf(rfile,"%c",rcvdata[i]);
    				for(p=0;p<Count-1;p++)
    					printf("%c",rcvdata[p]);
    				printf("\n");
    				Count=0;
    			}
    And the data sent to the file has newline first, the screen output has the newline after - again why?

    Of course, you probably should be using something a little bit more modern if you are intending to use serial ports for real - like giving up Turbo C and using for example Visual Studio, with the serial port functionality in Windows, instead of relying on the old fashioned INT 14 functionality.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21