home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / protocol / tcpip / ibmpc / 4920 < prev    next >
Encoding:
Text File  |  1992-08-26  |  2.1 KB  |  82 lines

  1. Path: sparky!uunet!olivea!hal.com!decwrl!mips!munnari.oz.au!uniwa!cujo!cc.curtin.edu.au!sbakerjr
  2. From: sbakerjr@cc.curtin.edu.au
  3. Newsgroups: comp.protocols.tcp-ip.ibmpc
  4. Subject: HELP! Turbo C serial comms problems
  5. Message-ID: <1992Aug27.193502.1@cc.curtin.edu.au>
  6. Date: 27 Aug 92 10:35:02 GMT
  7. Sender: news@cujo.curtin.edu.au (News Manager)
  8. Organization: Curtin University of Technology
  9. Lines: 71
  10.  
  11. I am writing a "simple" data collection routine for a PC to 
  12. read data off one of the serial ports and put the data into 
  13. a file for insertion into an SQL database (after processing...)
  14.  
  15. I am using Turbo C V2.0 to read the ports, check the status, etc,
  16. but the bioscom() function that TC uses is not always reliable.  
  17.  
  18. The bioscom(3,0,port) function should return the current status of the 
  19. port . I want to poll the data ready bit (bit 8) of the 16 bit return
  20. value.
  21.  
  22. I have written this loop to keep reading the port until a byte is ready
  23. to read, then read the byte into a variable, ch and from there into an 
  24. array where the file processing can take place...
  25.  
  26. --------------------------------------------------
  27. #include <bios.h>
  28. #include <stdio.h>
  29. #define DATA_READY 0x100
  30. #define CR 0xD
  31. #define SETTINGS 0xE3 /* 9600,n,8,1 */ 
  32.  
  33. main()
  34. {
  35.     int setup(int);
  36.     int read(int);
  37.     int status(int);
  38.  
  39.     int ch = 0;
  40.     int i=0,buffer[100];
  41.     int port=0; /* COM1: */
  42.  
  43.     while (ch != CR)
  44.     {
  45.          if (status(port) & DATA_READY)
  46.          {
  47.               buffer[i] = read(port);
  48.               putchar(buffer[i]);
  49.               i++;
  50.          } 
  51.     }
  52. }
  53.  
  54. int setup(port)
  55. {
  56.     return(bioscom(0,SETTINGS,port);
  57. }
  58.  
  59. int read(port)
  60. {
  61.     return(bioscom(2,0,port));
  62. }
  63.  
  64. int status(port)
  65. {
  66.     return(bioscom(3,0,port));
  67. }
  68.  
  69. --------------------------------------
  70. I ran this program but the data ready bit does not
  71. seem to be being set correctly, or the code does 
  72. not read it correctly.
  73.  
  74. Is my algorithm flawed ?
  75. Have you had any similar problems ?
  76.  
  77. The system will eventually be running on an OS/2 based machine
  78. so I do not wish to rely on UART interrupts, rather I would prefer 
  79. to poll the data ready bit and copy bytes into the buffer as they arrive.
  80.  
  81. Thanks for reading this...
  82.