Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RS232 AND USB C++ PROGRAMMING

Status
Not open for further replies.

JOANNA1202

Technical User
Feb 15, 2006
1
PL
Hi there,
I will be happy to get links to good coding of serial communication from PC com port to external devices like Barcode printers and laser hand-held scanners, with suggestions on the simplest Operating System (like DOS or LINUX). Can Windows 98 or XP do it in a simple way? I am using MS Visual C++ Compiler (want to change to any simpler - suggestions appreciated).
Thanks for help,
GK
 
Trying something sililar

snip><

#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>


#define PORT1 0x3F8 /* Defines Serial Port Base Address (COM1 */


int cscan();
int compare();
int check_id();
int vend();
char id[20];
char ref_id[] = "5030906900027450\n";
int vend();
int i;
int sercomm();

//int inport(int portid);
unsigned char inportb(int portid);
//void outport(int portid, int value);
void outportb(int portid, unsigned char value);


/*using namespace std*/
main()
{
unsigned char c = 0;
unsigned char chrctr = 0;
/*int exit = 1; */

outportb(PORT1 + 1, 0x00); /* Turn off interrupts */

/* PORT1 Communication Settings */

outportb(PORT1 + 3, 0x80); /* Set DLAB ON */
outportb(PORT1 + 0, 0x0C); /* Set the baud rate to 9600 */

outportb(PORT1 + 1, 0x00); /* Set Baud - Divisor latch HIGH */
outportb(PORT1 + 3, 0x03); /* 8 bits, no parity, 1 stop */
outportb(PORT1 + 2, 0xC7); /* FIFO Control Register */
outportb(PORT1 + 4, 0x0B); /* Turn on DTR, RTS, and OUT2) */



endsnip

gives me
[linker error] undefined reference to 'outputb(int, unsigned char)'
if I change the 0x00 in this line to just 0, it's ok
outportb(PORT1 + 1, 0x00); /* Turn off interrupts */

can anyone "straighten me out" ?
nothing usefull came of my earlier request !
 
Normally 32 bit Windows does not allow direct port access, CreateFile("COM1",...) should be used:
But many time ago I succeeded in using of inport()/outport() and even interrupts under Windows98 - I suppose it is emulated for 16-bit or DOS applications. Try some ancient compiler like Borland C++ 3.0 or something.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top