![]() ![]() Read_Status = WaitCommEvent(hComm, &dwEventMask, NULL) //Wait for the character to be received Printf( " \n\n Waiting for Data Reception") Printf( " \n\n Setting CommMask successfull") Printf( " \n\n Error! in Setting CommMask") ![]() Read_Status = SetCommMask(hComm, EV_RXCHAR) //Configure Windows to Monitor the serial device for Character Reception Printf( " \n\n Error %d in Writing to Serial Port", GetLastError()) Printf( " \n\n %s - Written to %s", lp, pcCommPort) Printf( " Error writing text to %s\n", pcCommPort) If (!WriteFile(hComm, lp, dNoOFBytestoWrite, * - Writing a Character to Serial Port-*/ char lp = " RDGFIELD? \r\n" // lpBuffer should be char or byte array, otherwise write wil failĭWORD dNoOFBytestoWrite // No of bytes to write into the portĭWORD dNoOfBytesWritten = 0 // No of bytes written to the portĭNoOFBytestoWrite = sizeof(lp) // Calculating the no of bytes to write into the port If (SetCommTimeouts(hComm, &timeouts) = 0) Timeouts.WriteTotalTimeoutMultiplier = 10 ![]() Timeouts.ReadTotalTimeoutMultiplier = 10 Printf( " \n Parity = %d", dcbSerialParams.Parity) Printf( " \n StopBits = %d", dcbSerialParams.StopBits) Printf( " \n ByteSize = %d", dcbSerialParams.ByteSize) Printf( " \n Baudrate = %d", dcbSerialParams.BaudRate) Printf( " \n Setting DCB Structure Successful\n") Printf( " \n Error! in Setting DCB Structure") Write_Status = SetCommState(hComm, &dcbSerialParams) //Configuring the port according to settings in DCB ![]() Write_Status = GetCommState(hComm, &dcbSerialParams) //retreives the current settingsĭcbSerialParams.BaudRate = CBR_57600 // Setting BaudRate = 9600ĭcbSerialParams.ByteSize = 8 // Setting ByteSize = 8ĭcbSerialParams.StopBits = ONESTOPBIT // Setting StopBits = 1ĭcbSerialParams.Parity = ODDPARITY // Setting Parity = None Printf( " opening serial port successful") ĭcbSerialParams.DCBlength = sizeof(dcbSerialParams) If (GetLastError() = ERROR_FILE_NOT_FOUND) NULL // hTemplate must be NULL for comm devices Printf( " \n +=+\n") Ġ, // must be opened with exclusive-access Printf( " \n | Serial Transmission (Win32 API) |") #include #include #include #define BUFFERLENGTH 256ĭCB dcbSerialParams // Initializing DCB structureīOOL Read_Status // Status of the various operationsĭWORD dwEventMask // Event mask to triggerĬhar TempChar = " " // Temperory CharacterĬhar *SerialBuffer // Buffer Containing Rxed DataĭWORD NoBytesRead // Bytes read by ReadFile() ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |