473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Barcode reader,i don't know how to put code to just recognize 2 bar codes

1
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.

Expand|Select|Wrap|Line Numbers
  1. #include <conio.h>
  2. #include <stdio.h>
  3. #include <windows.h>
  4.  
  5.  
  6.  
  7. HANDLE hCom;
  8.  
  9. HANDLE rs_initialise (int io_port, const long int BaudRate, const char parity, const char data)
  10. {   
  11.     BOOL bPortReady;
  12.     DCB dcb;
  13.     char ComPortName[]="COM1";
  14.     ComPortName[3]='0'+io_port;
  15.     hCom =CreateFile(ComPortName, GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
  16.  
  17.  
  18.     if ((int)hCom <= 0)
  19.     {
  20.         printf("serial port COM%d connect fail %s error %d\n\r", io_port, ComPortName, GetLastError());
  21.         return 0;
  22.     }
  23.     //else                printf(" serial port COM%d connect OK \n\r", io_port);
  24.  
  25.     bPortReady = SetupComm(hCom, 2, 128); // set buffer sizes
  26.     if (!bPortReady )
  27.     {
  28.         printf("serial port COM%d SetupComm fail  %d\n\r", io_port,  GetLastError());
  29.         return 0;
  30.     }
  31.     //else                printf(" serial port COM%d connect OK \n\r", io_port);
  32.  
  33.     bPortReady = GetCommState(hCom, &dcb);
  34.     if (!bPortReady )
  35.     {
  36.         printf("serial port COM%d  GetCommState fail  %d\n\r", io_port,  GetLastError());
  37.         return 0;
  38.     }
  39.     //  else                printf(" serial port COM%d connect OK \n\r", io_port);
  40.     dcb.BaudRate = BaudRate;
  41.     if( data == '7') dcb.ByteSize = 7;
  42.     else             dcb.ByteSize = 8;
  43.     if( parity == 'E') dcb.Parity = EVENPARITY;
  44.     if( parity == 'O') dcb.Parity = ODDPARITY;
  45.     else               dcb.Parity = NOPARITY;
  46.     dcb.StopBits = ONESTOPBIT;
  47.     dcb.fAbortOnError = TRUE;
  48.  
  49.     // set XON/XOFF
  50.     dcb.fOutX = FALSE;                       // XON/XOFF off for transmit
  51.     dcb.fInX = FALSE;                        // XON/XOFF off for receive
  52.     // set RTSCTS
  53.     dcb.fOutxCtsFlow = FALSE;               // turn off CTS flow control
  54.     dcb.fRtsControl = FALSE;                // RTS_CONTROL_HANDSHAKE; //
  55.     // set DSRDTR
  56.     dcb.fOutxDsrFlow = FALSE;               // turn off DSR flow control
  57.     //dcb.fDtrControl = DTR_CONTROL_ENABLE; // DTR handshake
  58.     dcb.fDtrControl = DTR_CONTROL_DISABLE;  //
  59.     // dcb.fDtrControl = DTR_CONTROL_HANDSHAKE; //
  60.  
  61.     bPortReady = SetCommState(hCom, &dcb);
  62.     if (!bPortReady )
  63.     {
  64.         printf("serial port COM%d  SetCommState fail  %d\n\r", io_port,  GetLastError());
  65.         return 0;
  66.     }
  67.  
  68.     // Communication timeouts
  69.     COMMTIMEOUTS CommTimeouts;
  70.     bPortReady = GetCommTimeouts (hCom, &CommTimeouts);
  71.     CommTimeouts.ReadIntervalTimeout = 5 ;
  72.     CommTimeouts.ReadTotalTimeoutConstant = 5 ;
  73.     CommTimeouts.ReadTotalTimeoutMultiplier = 1 ;
  74.     CommTimeouts.WriteTotalTimeoutConstant = 5 ;
  75.     CommTimeouts.WriteTotalTimeoutMultiplier = 1 ;
  76.     bPortReady = SetCommTimeouts (hCom, &CommTimeouts);
  77.     if (!bPortReady )
  78.     {
  79.         printf("serial port COM%d SetCommTimeouts fail  %d\n\r", io_port,  GetLastError());
  80.         return 0;
  81.     }
  82.     else                printf(" serial port COM%d connect OK \n\r", io_port);
  83.     return hCom;
  84. }
  85.  
  86.  
  87. /*----------------------------------------------------------------------------*
  88.  * Serial port: terminate io_port, sets DTR and RTS to low                     */
  89. void rs_terminate(const int io_port)
  90. {
  91.     // Close(hCom);
  92. }
  93.  
  94.  
  95.  
  96. /*----------------------------------------------------------------------------*
  97.  * Serial port: read character from io_port (ignored in this version)         */
  98. char rs_getch(const int io_port)
  99. {
  100.     char rxchar;
  101.     BOOL bReadRC;
  102.     static DWORD iBytesRead;
  103.     bReadRC = ReadFile(hCom, &rxchar, 1, &iBytesRead, NULL);
  104.     if (iBytesRead) return rxchar;
  105.     else return 0;         // return 0 if no character read
  106. }
  107.  
  108.  
  109. /*----------------------------------------------------------------------------*
  110.  * Serial port: transmit character to io_port                                 */
  111. void rs_putch(const int io_port, const int txchar)
  112. {
  113.     BOOL bWriteRC;
  114.     static DWORD iBytesWritten;
  115.     bWriteRC = WriteFile(hCom, &txchar, 1, &iBytesWritten,NULL);
  116.     return;
  117. }
  118.  
  119.  
  120. void rs_putstring(const int io_port, const char *string)
  121. {
  122.     while (*string != '\0')
  123.         rs_putch(io_port, *string++);
  124. }
  125.  
  126. //#include <conio.h>
  127.  
  128. int main()
  129. {
  130.  
  131.     int port = 1;
  132.  
  133.     if(!rs_initialise(port ,57600, '8', 'N'))
  134.     {
  135.         getch();
  136.         exit(1);
  137.     }
  138.     char letter;
  139.     while(1)
  140.     {
  141.         if (kbhit())  rs_putch(port, getche());
  142.         if((letter=rs_getch(port))>0)
  143.         {
  144.             putchar(letter);
  145.             if(letter) putchar("\n");
  146.  
  147.         }
  148.     }
  149.     getch();
  150.     return 0;
  151.  
  152.  
  153.  
  154. }
  155.  
Feb 28 '14 #1
0 1002

Sign in to post your reply or Sign up for a free account.

Similar topics

9
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
5
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...
5
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...
6
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
2
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
4
by: Joe | last post by:
is there any free barcode reader in vb8 for code-128 ??
0
by: manikandan | last post by:
dont miss it just open dont miss it just open dont miss it just open #############################
1
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 "
1
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.
8
risk32
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...
0
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,...
0
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$) { } ...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.