473,480 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

reception serial frame

24 New Member
I'm using serial line connection to send or receive data.
my problem is that the data reception does not work (no error when debugging)but the function GetLastError returns the error 998.
Expand|Select|Wrap|Line Numbers
  1. int CCommunicationSérie::OpenCom(DWORD bauderate,CString portcom)
  2. {
  3.     m_hCom = CreateFile((LPCSTR)portcom,
  4.         GENERIC_READ | GENERIC_WRITE,
  5.         0,
  6.         NULL,
  7.         OPEN_EXISTING,
  8.         0,                      
  9.         NULL);               
  10.     if(m_hCom==INVALID_HANDLE_VALUE)
  11.         return 1;
  12.     if ((m_bPortReady=GetCommState(m_hCom,&m_dcb))==0)
  13.     {
  14.         CloseHandle(m_hCom);
  15.         return 2;
  16.     }
  17.  
  18.     m_dcb.fBinary=1;
  19.     m_dcb.fParity=0;
  20.     m_dcb.fNull = 0; 
  21.     m_dcb.fDsrSensitivity=1;          
  22.     m_dcb.fOutX=0;
  23.     m_dcb.fInX=0;    
  24.     //m_dcb.XonLim =0x02;
  25.     // m_dcb.XoffLim =0x01;
  26.     //m_dcb.EofChar = '$';//
  27.     m_dcb.fAbortOnError=0;
  28.     m_dcb.fErrorChar = 0;
  29.     m_dcb.fOutxDsrFlow=1;
  30.     m_dcb.fOutxCtsFlow=1;
  31.     m_dcb.fDtrControl=DTR_CONTROL_ENABLE;
  32.     m_dcb.fRtsControl=RTS_CONTROL_ENABLE;
  33.  
  34.     m_dcb.DCBlength = sizeof(DCB);
  35.  
  36.     m_dcb.BaudRate =bauderate;
  37.     m_dcb.ByteSize = 8;
  38.     m_dcb.Parity =NOPARITY;
  39.     m_dcb.StopBits =ONESTOPBIT;
  40.  
  41.     m_bPortReady=SetCommState(m_hCom, &m_dcb); 
  42.     if(m_bPortReady==0) { CloseHandle(m_hCom);return 3;}
  43.  
  44.     //vider les tampons
  45.    PurgeComm(m_hCom,PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR); 
  46.  
  47.    return 0;
  48. }
  49.  
  50.  
data reception
Expand|Select|Wrap|Line Numbers
  1. bool CCommunicationSérie::ReadCom()
  2. {
  3.   //char* read_buffer=new char[4];    
  4.   DWORD nNumberOfBytesToRead=2;
  5.   DWORD NumberOfBytesRead=0;
  6.   LPVOID ReadBuffer=NULL;
  7.   int erreur=0;
  8.   //DWORD size=2;
  9.  
  10.    //DWORD dwErrorMask ;
  11.    //COMSTAT cs; // structure
  12.  
  13.   // ClearCommError(m_hCom, &dwErrorMask , &cs); 
  14.  
  15.       int nBytes = 0;
  16.       if (nBytes=ReadFile (m_hCom,ReadBuffer,nNumberOfBytesToRead,&NumberOfBytesRead,NULL)==1)
  17.       {
  18.        //read_buffer=(char*)ReadBuffer;
  19.          return false;
  20.  
  21.       }
  22.    erreur=GetLastError();          
  23.    return true;
  24.  
  25.  
  26. }
  27.  
  28.  
Thanks for help
Apr 5 '11 #1
0 980

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

Similar topics

4
9058
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the...
0
2180
by: Polerio Babao Jr.II | last post by:
file fbus3.py resource shared by Chris Liechti <cliechti@gmx.net> during the conversation last september 2002. I made it available so that other user would benefit from it. I've used with...
4
11103
by: Tom Van Ginneken | last post by:
Hi, I need to write binary data to a serial port. I am using this function: #include <unistd.h> ssize_t write(int fd, const void *buf, size_t count); I am able to write a alpha-numeric...
0
1210
by: sandeepa | last post by:
Hello all I am using the serial port to receive data(7 bytes per second) from the microcontroller,receiving the data as a string and then splitting the string in two,to display 2 different...
8
2450
by: vicky | last post by:
Hello,I met a question when I wrote the program.I want the program can transmit the data frame continuosly through the RS232 when the communication has been interrupted.But I don't know how to...
1
1838
by: ganesah | last post by:
hi im still new in VB, I have a doubt here, is it possible to display received data(continous data reception) from serial com port on a window ....can all this process be done using VB..if yes does...
2
4289
by: pauland80 | last post by:
Hello, My soft passively listen to a device sending +- 300 bytes of data each second. After several hours of work, the soft abruptly stops receiving data without any error, (while the device...
4
4784
by: max_mont | last post by:
Hi all, I'm a newbie in .NET technology. I've already developed Serial communication applications in C++ (WIN32). And I wanted to migrate to .NET technology. There is a serial component in...
9
8353
by: ipkiss | last post by:
I am writing a program that reads the data from the serial port on Linux. The data are sent by another device in the following frame format: ...
3
2466
by: ikbel borcheni | last post by:
Hi,I use serial line communication(RS232) to send/receive data using 2 PC. The port COM is opened succesfully but the problem is that read(reception) and write(sending) functions do not work(there is...
0
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3000
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.