Searching \ for '[OT] Programming PC Serial ports' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devprogs.htm?key=programming
Search entire site for: 'Programming PC Serial ports'.

Exact match. Not showing close matches.
PICList Thread
'[OT] Programming PC Serial ports'
1999\02\23@192022 by Dave Johnson

flavicon
face
Sorry this is so off topic, but it seemed a good group to ask:

I need to write a diagnostic program that will "speak" through the serial
port on a PC, this is for testing a piece of hardware during
manufacturing. The people using this program only have PCs, no
Macintoshes, but I'm very much a Mac programmer.

The bulk of the program will be stdio-based C, real standard stuff that
should port with no difficulties. But I don't know squat about PC serial
ports, and I'm hoping there's a library out there somewhere that will let
me set up the parameters (baud rate, parity, etc.) and then just merrily
spit and suck bytes without having to know anything about the details.
Does anyone know if such a thing exists? Any leads would be greatly
appreciated.

Dave Johnson

1999\02\23@204017 by Gerhard Fiedler

picon face
At 16:20 02/23/99 -0800, Dave Johnson wrote:
>The bulk of the program will be stdio-based C, real standard stuff that
>should port with no difficulties. But I don't know squat about PC serial
>ports, and I'm hoping there's a library out there somewhere that will let
>me set up the parameters (baud rate, parity, etc.) and then just merrily
>spit and suck bytes without having to know anything about the details.
>Does anyone know if such a thing exists? Any leads would be greatly
>appreciated.

you'd think that would be part of the windows api, wouldn't you? :)  try
something like "greenleaves" or so (i can't remember the exact name, and
i've never used it myself, but i've heard tons of good comments about it,
and if i needed one, i'd probably get that one :), you probably find it
(and probably others) at http://www.pparadise.com/

ge

1999\02\24@001621 by Eric Oliver

flavicon
face
That was GreenLeaf <g>. I own their library ( an old version ) and although
I never used it much, it seems to work very well. I don't have a web
address handy but here is the phone number 214 248-2561.  I have heard good
things about another lib ... hold on and let me go get a Windows Developers
Journal < soft elevator music on > ............... < soft elevator music
off > Sorry it took so long <g>.  The company is MarshallSoft Computing at
http://www.marshallsoft.com . This is an old magazine but he has two packages. A
Win16 & Win32 lib for $75 + s&h and a DOS & Win16 lib for $75 s&h.  Like I
said, I have no experience with this product but over the years I have read
messages where others have recommended it. Plus, the price is right.  I
believe Greenleaf's lib set me back about $300.

HTH,
Eric

{Original Message removed}

1999\02\24@003539 by Myke Predko

flavicon
face
Hi Dave,

Have you looked at Visual Basic?  It has the "MSComm" control that you can
add very easily and very quickly write interface code.  It is the easiest
way I've found to code up Serial Ports for the PC.

myke

{Original Message removed}

1999\02\24@011343 by Wagner Lipnharski

picon face
Dave, this is quite simply to do in DOS assembler, it can run in a windows dos
partition.If you are interested, take a look at the files "copy2com.exe" and
"com2file.exe", two
dos programs I made to deal directly to and from the serial port and disk
files.
http://www.ustr.net/files/download.htm , and if you still interested in the
possibilities, you
can contact me directly.  I can do it for a small fee. :) for sure 100% Y2K
compliant.
---------------------------------------------------------------------
Wagner Lipnharski - spam_OUTwagnerTakeThisOuTspamustr.net - website: http://www.ustr.net

Dave Johnson wrote:

> Subject: [OT] Programming PC Serial ports
>
> >Sorry this is so off topic, but it seemed a good group to ask:
> >
> >I need to write a diagnostic program that will "speak" through the serial
> >port on a PC, this is for testing a piece of hardware during
> >manufacturing. The people using this program only have PCs, no
> >Macintoshes, but I'm very much a Mac programmer.

1999\02\24@012027 by Gerhard Fiedler

picon face
At 00:33 02/24/99 -0500, Myke Predko wrote:
>Have you looked at Visual Basic?  It has the "MSComm" control that you can
>add very easily and very quickly write interface code.  It is the easiest
>way I've found to code up Serial Ports for the PC.

now that you say it, there are in fact a lot of commercial compiler which
have some kind of control or component which does that. before you buy
anything, check that out :)  and there are probably tons of freeware stuff
around for your particular programming environment, if you don't mind a bit
of tweaking on your own.

ge

1999\02\24@015246 by Jim Lee

picon face
how about the DOS command "copy file.txt com1" ? Won't somthing like that
pump a textfile out the com port on a PC? I -think- I remeber somethnglike
this working back in.. 1985..err..  86?

-jim

1999\02\24@054643 by Tom Handley

picon face
  Dave, if you are just using DOS, here are some simple routines that I
use. It should port to any compiler though you may have to change inp() to
input() and outp() to output():

>From the header file:
---------------------

/* Type Definitions */

typedef   unsigned char   UBYTE;  /* Old habbit...     */
...

/* Serial Port Definitions */

#define   COM1_BASE   0x3F8       /* COM1 Base Address */
#define   COM2_BASE   0x2F8       /* COM2 Base Address */
#define   COM3_BASE   0x3E8       /* COM3 Base Address */
#define   COM4_BASE   0x2E8       /* COM4 Base Address */
#define   COM_BASE    COM2_BASE   /* COM  Base Address */

/* Function Prototypes */

void  InitUSART(void);            /* Initialize USART  */
void  TxData(UBYTE);              /* Transmit Data     */
UBYTE RxData(void);               /* Receive  Data     */
...

>From the application file:
--------------------------
  Note, there are a lot of ways to do this. I use these routines as a
generic package and add sections relating to CTS/RTS and DTR/DSR as needed.
Also, they do not provide a time-out for a port that is not responding nor
do they use interrupts. I've used them up to 115.2K with handshaking
disabled. Works fine with a 20MHz PIC16C76/77 at 115.2K.
(BRGH = 1, SPBRG = 10).

/*
  InitUSART() - Initialize USART to 115200, 8 Data Bits, No Parity, 1 Stop
Bit
*/
void InitUSART(void)
{
 outp(COM_BASE + 1, 0x00);   /* Turn off interrupts                     */
 outp(COM_BASE + 3, 0x83);   /* Access Divisor Latch                    */
 outp(COM_BASE + 0, 0x01);   /* Set 115200 Baud (115200/Divisor)        */
 /*                             Divisor = 115200/Baud rate
                                For 9600 Baud: Divisor = 12 (0x0C)
 */
 outp(COM_BASE + 3, 0x03);   /* Access DFM reg. Configure Data Format   */
 outp(COM_BASE + 4, 0x00);   /* Disable Loop, !OUTx. Disable !RTS, !DTR */
 /*                 0x01 =      Disable Loop, !OUTx, !RTS. Enable !DTR
                    0x02 =      Disable Loop, !OUTx, !DTR. Enable !RTS
                    0x03 =      Disable Loop, !OUTx. Enable !RTS, !DTR
 */
}

/*
  TxData() - Send Data to Serial Port
  Entry:
     data = Data to transmit
*/
void TxData(UBYTE data)
{
 UBYTE x;

 /* Check for Tx Buffer Empty */
 do
 {
   x = inp(COM_BASE + 5);
   x &= 0x20;
 } while(x == 0);

 outp(COM_BASE + 0, data);       /* Send Data */
}

/*
  RxData() - Receive Data from the Serial Port
  Exit:
     data = Rx Data byte
*/
UBYTE RxData(void)
{
 UBYTE x;
 UBYTE data = 0;

 while(TRUE)                     /* Check for Rx Data */
 {
   x = inp(COM_BASE + 5);
   x &= 0x01;
   if(x == 1)
   {
     data = inp(COM_BASE + 0);   /* Get Data          */
     break;
   }

   if(kbhit())                   /* Abort if Keypress */
   {
     getch();
     printf("\n");
     break;
   }
 }
 return(data);
}

  For Handshaking, I use the following:

 /* Wait for !CTS */
 do
 {
   x = inp(COM_BASE + 6);
   x &= 0x10;
 } while(x == 0);

 /* Wait for !DSR */
 do
 {
   x = inp(COM_BASE + 6);
   x &= 0x20;
 } while(x == 0);

 /* Wait for !RI  */
 do
 {
   x = inp(COM_BASE + 6);
   x &= 0x40;
 } while(x == 0);

 /* Wait for !DCD */
 do
 {
   x = inp(COM_BASE + 6);
   x &= 0x80;
 } while(x == 0);

 /* Disable !RTS  */
 x = inp(COM_BASE + 4);
 x &= 0xFD;
 outp(COM_BASE + 4, x);

 /* Enable !RTS  */
 x = inp(COM_BASE + 4);
 x |= 0x02;
 outp(COM_BASE + 4, x);

 /* Disable !DTR */
 x = inp(COM_BASE + 4);
 x &= 0xFE;
 outp(COM_BASE + 4, x);

 /* Enable !DTR  */
 x = inp(COM_BASE + 4);
 x |= 0x01;
 outp(COM_BASE + 4, x);


  - Tom

At 04:20 PM 2/23/99 -0800, Dave Johnson wrote:
{Quote hidden}

1999\02\24@100622 by Wagner Lipnharski

picon face
Not exactly.  The dos command  "copy /b file.txt com1:" will try to dump the
file as a normal DOS function, but it will follow the rules of the simple
redirection, and it will pass the control to the bios that will require the
regular
"ok" state from the device, for example, CTS and DTR lines active at the
interface.  Also, it requires you to previously configure the port, as speed,
number of stop bits, quantity of bits and parity.  Anything a little more
flexible
will require custom programming.
Wagner.

Jim Lee wrote:

> how about the DOS command "copy file.txt com1" ? Won't somthing like that
> pump a textfile out the com port on a PC? I -think- I remeber somethnglike
> this working back in.. 1985..err..  86?
>
> -jim

1999\02\24@114247 by Dave Johnson

flavicon
face
Thanks everyone for your input. I found some Microsoft sample code to do
a simple Win32 terminal, got it compiled and working, and am now
customizing it for my own devious purposes. The Win32 stuff is more or
less greek to me, but I don't need to deal with it much :-) There are
welll encapsulated routines for reading and writing the COM port, and for
writing to the "console" window, and I can use stdio for the file I/O I
need to do (I was hoping to use it for console I/O as well, but this is
almost as good...)

Thanks again!

Dave Johnson

1999\02\24@130752 by Gerhard Fiedler

picon face
At 08:37 02/24/99 -0800, Dave Johnson wrote:
>(I was hoping to use it for console I/O as well, but this is
>almost as good...)

if you really want console i/o, you have to find how you can compile for a
"win32 console application" with your compiler. this gets you rid of the
windows graphics functions and you can use normal console i/o, but still
have all the other (non-GUI) "functionality" :) of windows.

ge

1999\02\24@143549 by goflo

flavicon
face
Wagner Lipnharski wrote:

> http://www.ustr.net/files/download.htm

Lots of interesting stuff, thanks.
FWIW,
The links to the pentium enable/disable
cache routines return "file not found" :(


Regards, Jack

1999\02\24@170145 by John Payson

flavicon
face
|I need to write a diagnostic program that will "speak" through the serial
|port on a PC, this is for testing a piece of hardware during
|manufacturing. The people using this program only have PCs, no
|Macintoshes, but I'm very much a Mac programmer.

If the PC communication isn't speed-critical and you're using DOS,
it may be useful to do everything through polling rather than via
interrupts.  There are many times when that approach is totally
unsuitable, but if you don't use interrupts you can avoid the prob-
lems that can plague them (e.g. COM1-COM3 or COM2-COM4 conflicts).
If the UART is 16C550-based you should be able to get a 16-byte
buffer without interrupts; otherwise you need to ensure that you
can always read a character before the next one finishes arriving.

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...