ForSa punya logo baru!! Ada komen?
0 Anggota dan 1 Pengunjung sedang melihat topik ini.
// terminal.c - simple terminal program for Dev-C++ and Cygwin // // only works for one port at moment // #include <conio.h> #include <stdio.h> // Uncomment the following directive for use with Cygwin: // #include <windows.h> HANDLE hCom; //handle for serial port I/O /*----------------------------------------------------------------------------* * Serial port: initialise io_port, set baud rate, set data bits, one stop bit*/ HANDLE rs_initialise (int io_port, const long int BaudRate, const char parity, const char data) { BOOL bPortReady; DCB dcb; char ComPortName[]="COM1"; // set up COM port number in COM? ComPortName[3]='0'+io_port; hCom = CreateFile(ComPortName, GENERIC_READ | GENERIC_WRITE, 0, // exclusive access NULL, // no security OPEN_EXISTING, 0, // no overlapped I/O NULL); // null template 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; } /*----------------------------------------------------------------------------* * Serial port: transmit a string of characters to io_port */ 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 keyboard hit read character and transmit it if((letter=rs_getch(port))>0) { putchar(letter); if(letter=='\r') putchar('\n'); } // if character received display it } getch(); return 0; }
bang, saya compile di windows pake dev-c++ kok banyak yang eror ya, banyak yang undeclared
bang, kalau boleh tahu pemasangan/setting barcode reader dan alat yang digunakan untuk mengambil sidik jari digital (apa ya namanya?) itu sama ya?
owh, berarti hasil dari barcode reader itu seperti penulisan dalam keyboard ya?maksud saya adalah program apa yang dibuka disana, dia akan menulis hasil dari barcodenya?untuk programnya, saya mau nanya nih, caranya memasukkan hasil barcode kedalam inputan program bagaimana?apakah perlu koneksi khusus dari barcode reader ke program?
saya pikir gak perlu di koneksiin barcode readernya dengan program...toh barcode reader udah mengeluarkan out dari pembacaan barcodenya...contoh anda buka notepad..trus coba read sebuah barcode pake barcode readernya..nanti hasilnya udah tertulis di notepad kok..yang penting justru membuat program untuk ngeprint barcodenya..kecuali program anda masih pake consol alias tidak visual, aq belum pernah mencoba...sy sih dulu pake C# visual studio..kalo mau tanya lebih jauh silahkan aja...kebetulan aku ada pengalaman di barcode ini..hehehehe..