This code for barcode reader is working just fine,but i don't know how to put,and where to put code that can only read 2 barcodes whit IF.Becouse i have to send signal to interface. Please help. - #include <conio.h>
-
#include <stdio.h>
-
#include <windows.h>
-
-
-
-
HANDLE hCom;
-
-
HANDLE rs_initialise (int io_port, const long int BaudRate, const char parity, const char data)
-
{
-
BOOL bPortReady;
-
DCB dcb;
-
char ComPortName[]="COM1";
-
ComPortName[3]='0'+io_port;
-
hCom =CreateFile(ComPortName, GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
-
-
-
if ((int)hCom <= 0)
-
{
-
printf("serial port COM%d connect fail %s error %d\n\r", io_port, ComPortName, GetLastError());
-
return 0;
-
}
-
//else printf(" serial port COM%d connect OK \n\r", io_port);
-
-
bPortReady = SetupComm(hCom, 2, 128); // set buffer sizes
-
if (!bPortReady )
-
{
-
printf("serial port COM%d SetupComm fail %d\n\r", io_port, GetLastError());
-
return 0;
-
}
-
//else printf(" serial port COM%d connect OK \n\r", io_port);
-
-
bPortReady = GetCommState(hCom, &dcb);
-
if (!bPortReady )
-
{
-
printf("serial port COM%d GetCommState fail %d\n\r", io_port, GetLastError());
-
return 0;
-
}
-
// else printf(" serial port COM%d connect OK \n\r", io_port);
-
dcb.BaudRate = BaudRate;
-
if( data == '7') dcb.ByteSize = 7;
-
else dcb.ByteSize = 8;
-
if( parity == 'E') dcb.Parity = EVENPARITY;
-
if( parity == 'O') dcb.Parity = ODDPARITY;
-
else dcb.Parity = NOPARITY;
-
dcb.StopBits = ONESTOPBIT;
-
dcb.fAbortOnError = TRUE;
-
-
// set XON/XOFF
-
dcb.fOutX = FALSE; // XON/XOFF off for transmit
-
dcb.fInX = FALSE; // XON/XOFF off for receive
-
// set RTSCTS
-
dcb.fOutxCtsFlow = FALSE; // turn off CTS flow control
-
dcb.fRtsControl = FALSE; // RTS_CONTROL_HANDSHAKE; //
-
// set DSRDTR
-
dcb.fOutxDsrFlow = FALSE; // turn off DSR flow control
-
//dcb.fDtrControl = DTR_CONTROL_ENABLE; // DTR handshake
-
dcb.fDtrControl = DTR_CONTROL_DISABLE; //
-
// dcb.fDtrControl = DTR_CONTROL_HANDSHAKE; //
-
-
bPortReady = SetCommState(hCom, &dcb);
-
if (!bPortReady )
-
{
-
printf("serial port COM%d SetCommState fail %d\n\r", io_port, GetLastError());
-
return 0;
-
}
-
-
// Communication timeouts
-
COMMTIMEOUTS CommTimeouts;
-
bPortReady = GetCommTimeouts (hCom, &CommTimeouts);
-
CommTimeouts.ReadIntervalTimeout = 5 ;
-
CommTimeouts.ReadTotalTimeoutConstant = 5 ;
-
CommTimeouts.ReadTotalTimeoutMultiplier = 1 ;
-
CommTimeouts.WriteTotalTimeoutConstant = 5 ;
-
CommTimeouts.WriteTotalTimeoutMultiplier = 1 ;
-
bPortReady = SetCommTimeouts (hCom, &CommTimeouts);
-
if (!bPortReady )
-
{
-
printf("serial port COM%d SetCommTimeouts fail %d\n\r", io_port, GetLastError());
-
return 0;
-
}
-
else printf(" serial port COM%d connect OK \n\r", io_port);
-
return hCom;
-
}
-
-
-
/*----------------------------------------------------------------------------*
-
* Serial port: terminate io_port, sets DTR and RTS to low */
-
void rs_terminate(const int io_port)
-
{
-
// Close(hCom);
-
}
-
-
-
-
/*----------------------------------------------------------------------------*
-
* Serial port: read character from io_port (ignored in this version) */
-
char rs_getch(const int io_port)
-
{
-
char rxchar;
-
BOOL bReadRC;
-
static DWORD iBytesRead;
-
bReadRC = ReadFile(hCom, &rxchar, 1, &iBytesRead, NULL);
-
if (iBytesRead) return rxchar;
-
else return 0; // return 0 if no character read
-
}
-
-
-
/*----------------------------------------------------------------------------*
-
* Serial port: transmit character to io_port */
-
void rs_putch(const int io_port, const int txchar)
-
{
-
BOOL bWriteRC;
-
static DWORD iBytesWritten;
-
bWriteRC = WriteFile(hCom, &txchar, 1, &iBytesWritten,NULL);
-
return;
-
}
-
-
-
void rs_putstring(const int io_port, const char *string)
-
{
-
while (*string != '\0')
-
rs_putch(io_port, *string++);
-
}
-
-
//#include <conio.h>
-
-
int main()
-
{
-
-
int port = 1;
-
-
if(!rs_initialise(port ,57600, '8', 'N'))
-
{
-
getch();
-
exit(1);
-
}
-
char letter;
-
while(1)
-
{
-
if (kbhit()) rs_putch(port, getche());
-
if((letter=rs_getch(port))>0)
-
{
-
putchar(letter);
-
if(letter) putchar("\n");
-
-
}
-
}
-
getch();
-
return 0;
-
-
-
-
}
-
0 1002 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Piotr Nowak |
last post by:
Hi
i need a script that will auto-submit a form when someone enters 11
characters into one of textfields..
any ideas?
Thanks ;-)
Peter
|
by: Serdar C. |
last post by:
hello everyone, i have a question about retrieving data from a bar code
reader plugged in keyboard port (ps/2)
i really dont know how to retrieve data from keyboard, i tried some methods
but all i...
|
by: neilphan |
last post by:
Hi all,
I have an application that uses input from a barcode reader via a USB
port. My application works fine only if the application HAS FOCUS.
If the user opens up another application (not...
|
by: Samuel Shulman |
last post by:
I would like to add barcode functionality to my POS program
How does one attach barcode reader is it usually USB port
How can the program get the data read by the device
Thank you,
Samuel
|
by: hojjatnikan |
last post by:
please help me
this code 62EH&5gx0wiqoQFw is this name ( Belux) but i dont know how convert it i dont know the algorithm of this code plead help me
|
by: Joe |
last post by:
is there any free barcode reader in vb8 for code-128 ??
|
by: manikandan |
last post by:
dont miss it just open
dont miss it just open
dont miss it just open
#############################
|
by: syed asghar abbas |
last post by:
I am Student of the BS(Cs) and i am student of the Final Term and my Final Project on the Barcode Reader that "How to Connect the Barcode Reader Device Scanner With Sql Database in C# 2005 "
|
by: likun12 |
last post by:
i develope a barcode program from that barcode is generated.but i just dont know how to insert data into sqlserver from the barcode reader.
|
by: risk32 |
last post by:
Hi all. I have a really confusing problem. I'm using Swing and I'm trying to do a confirmation box :
int reply;
String message = "Do you want to input another number?";
String title = "Input...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| | |