|
27.2.2014, 15:17 | #1 |
Novi član
Član od: 26.2.2014.
Poruke: 1
Zahvalnice: 0
Zahvaljeno 0 puta na 0 poruka
|
Pomoc C
#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; } U ovom kodu trebam da ubacim samo dva bar koda koja ce da ocitava bar kod ako neko zna molim za pomoc |
28.2.2014, 23:42 | #2 |
Banned
|
Re: Pomoc C
Rado bi ti pomogao, al' prvo si mi dao 100 linija koda da desifrujem sta je sta, bez komentara, a pored toga nisi kod cak ni stavio u [code] tag kako bi bio pregledniji. Ajde izvuci deo koda koji ti pravi problem, pa da probamo da resimo to
|
Bookmarks sajtovi |
Alatke vezane za temu | |
Vrste prikaza | |
|
|
Slične teme | ||||
tema | temu započeo | forum | Odgovora | Poslednja poruka |
Procena računara | alien | Šta da kupim? | 6942 | 17.12.2023 10:28 |
Gledanje filmova putem Android telefona? Pomoc hitno | Kobilic | Aparati i oprema | 34 | 13.8.2015 11:24 |
Pomoc oko odabira konfiguracije i komponenti | LieSerj | ŠDK - Konfiguracije | 10 | 15.12.2013 21:58 |
Pomoc oko izbora plottera | braca86 | Grafički softver i radovi | 0 | 30.3.2009 17:51 |
Potrebna pomoc oko High End konfiguracije - Xtreme Gaming - | Mandrak | ŠDK - Osnovne komponente | 2 | 27.8.2008 9:30 |