I can't read serial port data. 
Author Message
 I can't read serial port data.

I need some your help.
Below code is sample.
Why don't I read data?
I don't receive correct data.

class MyClass
{
   HANDLE Port;
   static DWORD WINAPI ReadThread(LPVOID lpParam);
   int InitPort();
....

Quote:
}

int MyClass::InitPort()
{
   Port = CreateFile(_T("COM:1"),
        GENERIC_READ|GENERIC_WRITE,
        NULL,NULL,OPEN_EXISTING,
        NULL,NULL);
   SetCommMask(Port,EV_RXCHAR);
   SetupComm(Port,......);
   PurgeComm(Port,......);

   COMMTIMEOUTS to;
   ..COMMTIMEOUTS Setup.....

   DCB dcb;
   ..DCB Setup........

  SetCommStatue(Port,&dcb);

  hThread = CreateThread(0,0,ReadThread,this,0,&dwThreadId);
  return 0;

Quote:
}

DWORD WINAPI MyClass::ReadThread(LPVOID lpParam)
{
   MyClass *This = (MyClass *) lpParam;
   char ReadBuffer[MAX_CHAR];
   char ReadData;
   BYTE Byte;
   DWORD dwCount,dwStatus;
   SetCommMask(This->Port,EV_RXCHAR);
   while (This->Port != INVALID_HANDLE_VALUE)
   {
        WaitCommEvent(This->Port,&dwStatus,0);
        SetCommMask(This->Port,EV_RXCHAR);
        if (dwStatus & EV_RXCHAR)
        {
           do {
                ReadFile(This->Port,&ReadData,1,&dwCount,0);
                Store_My_Funcion(ReadBuff);
           } while (dwCount == 1);
   }
   return 0;
Quote:
}



Tue, 17 May 2005 00:36:07 GMT  
 I can't read serial port data.
Well, let's see:

1. The port name is "COM1:", not "COM:1".

2. There is no function SetCommStatue(), although it seems like I should
have a funny come-back for it.

To summarize: maybe you should attach the code for the class.  Obviously,
reading around your typographical errors isn't going to allow us to figure
out the problem.  Are you sure you set the baud rate, character size, etc.,
correctly?

Paul T.


Quote:
> I need some your help.
> Below code is sample.
> Why don't I read data?
> I don't receive correct data.

> class MyClass
> {
>    HANDLE Port;
>    static DWORD WINAPI ReadThread(LPVOID lpParam);
>    int InitPort();
> ....
> }
> int MyClass::InitPort()
> {
>    Port = CreateFile(_T("COM:1"),
> GENERIC_READ|GENERIC_WRITE,
> NULL,NULL,OPEN_EXISTING,
> NULL,NULL);
>    SetCommMask(Port,EV_RXCHAR);
>    SetupComm(Port,......);
>    PurgeComm(Port,......);

>    COMMTIMEOUTS to;
>    ..COMMTIMEOUTS Setup.....

>    DCB dcb;
>    ..DCB Setup........

>   SetCommStatue(Port,&dcb);

>   hThread = CreateThread(0,0,ReadThread,this,0,&dwThreadId);
>   return 0;
> }
> DWORD WINAPI MyClass::ReadThread(LPVOID lpParam)
> {
>    MyClass *This = (MyClass *) lpParam;
>    char ReadBuffer[MAX_CHAR];
>    char ReadData;
>    BYTE Byte;
>    DWORD dwCount,dwStatus;
>    SetCommMask(This->Port,EV_RXCHAR);
>    while (This->Port != INVALID_HANDLE_VALUE)
>    {
> WaitCommEvent(This->Port,&dwStatus,0);
> SetCommMask(This->Port,EV_RXCHAR);
> if (dwStatus & EV_RXCHAR)
> {
>    do {
> ReadFile(This->Port,&ReadData,1,&dwCount,0);
> Store_My_Funcion(ReadBuff);
>    } while (dwCount == 1);
>    }
>    return 0;
> }



Sat, 21 May 2005 00:16:03 GMT  
 I can't read serial port data.

Quote:
> Well, let's see:

> 1. The port name is "COM1:", not "COM:1".

> 2. There is no function SetCommStatue(), although it seems like I should
> have a funny come-back for it.

> To summarize: maybe you should attach the code for the class.  Obviously,
> reading around your typographical errors isn't going to allow us to figure
> out the problem.  Are you sure you set the baud rate, character size, etc.,
> correctly?

> Paul T.



> > I need some your help.
> > Below code is sample.
> > Why don't I read data?
> > I don't receive correct data.

> > class MyClass
> > {
> >    HANDLE Port;
> >    static DWORD WINAPI ReadThread(LPVOID lpParam);
> >    int InitPort();
> > ....
> > }
> > int MyClass::InitPort()
> > {
> >    Port = CreateFile(_T("COM:1"),
> > GENERIC_READ|GENERIC_WRITE,
> > NULL,NULL,OPEN_EXISTING,
> > NULL,NULL);
> >    SetCommMask(Port,EV_RXCHAR);
> >    SetupComm(Port,......);
> >    PurgeComm(Port,......);

> >    COMMTIMEOUTS to;
> >    ..COMMTIMEOUTS Setup.....

> >    DCB dcb;
> >    ..DCB Setup........

> >   SetCommStatue(Port,&dcb);

> >   hThread = CreateThread(0,0,ReadThread,this,0,&dwThreadId);
> >   return 0;
> > }
> > DWORD WINAPI MyClass::ReadThread(LPVOID lpParam)
> > {
> >    MyClass *This = (MyClass *) lpParam;
> >    char ReadBuffer[MAX_CHAR];
> >    char ReadData;
> >    BYTE Byte;
> >    DWORD dwCount,dwStatus;
> >    SetCommMask(This->Port,EV_RXCHAR);
> >    while (This->Port != INVALID_HANDLE_VALUE)
> >    {
> > WaitCommEvent(This->Port,&dwStatus,0);
> > SetCommMask(This->Port,EV_RXCHAR);
> > if (dwStatus & EV_RXCHAR)
> > {
> >    do {
> > ReadFile(This->Port,&ReadData,1,&dwCount,0);
> > Store_My_Funcion(ReadBuff);
> >    } while (dwCount == 1);
> >    }
>  return 0;
> > }

Oh,.uhm..

It's just miss typing.
correctly work. thanks



Sat, 21 May 2005 15:34:10 GMT  
 I can't read serial port data.
Hi Jeonghan

 > I need some your help.
 > Below code is sample.
 > Why don't I read data?
 > I don't receive correct data.
 >
.. skip ..
 >           ReadFile(This->Port,&ReadData,1,&dwCount,0);
                                     ^^^^^^^^^^        
 >           Store_My_Funcion(ReadBuff);
                                  ^^^^^^^^^
..skip..
In addition,It seems to me you should use the same variable in the
current context.

Regards,
Georgiy



Mon, 06 Jun 2005 23:47:54 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How can ia read serial port data

2. how can i read serial port data

3. reading data from serial/parallel port(s)

4. Read data on serial port from C program

5. reading data from a serial port

6. How to read data from serial port?

7. Read data from the serial port???

8. How to read data from serial port?

9. Has anybody read data from a serial port?

10. Question: Reading data from serial or parallel port

11. How to read data from serial port?

12. Serial Port code won't read past 00 value byte

 

 
Powered by phpBB® Forum Software