Re: Serial programming

From: bernie (bernard.acquier_at_free.fr)
Date: 08/27/04


Date: Fri, 27 Aug 2004 21:08:59 +0200

Ok, Thanks, I look at this program.
For your question: I have no Hyperterminal-like on my pocket PC!
(Zmodem, but I don't consider it like a Hyperterminal-like ..... I seek one)
Do you know a good one ?
Thanks
Bye

5thWheel wrote:

> Ehsan Sadeghi's source code works on my two platforms (two tiny
> modifications required to make it compile). Can't you try that on your
> platform? I don't have an SDK for whatever you're running, and I don't
> right now have ARM processor support as a part of my compiler.
>
> Dumb question: if you run a hyperterminal-like program on your CE.Net
> platform, and run another on a laptop, then presumably they can talk to
> each other ok?
>
> FYI this is how I open my comport: (see Winbase.h for CBR_900
> definitions etc)
> (The AcuCatch and AcuThrow are exception handling macros, I guess you
> can replace them all with "return;" or afxmessagebox or something).
> CHardwareCommsRS232::CHardwareCommsRS232(CSarahString const &
> Port, //_T("COM1:")
> DWORD const
> TimeoutPerChar, //500
> DWORD const Baud,
> //CBR_9600
> BYTE const Bits,
> //8
> BYTE const Stop,
> //ONESTOPBIT
> BYTE const
> Parity, //NOPARITY
> DWORD const
> dwFlagsAndAttributes) : //0
> m_hPort (NULL)
> {
> try
> {
> m_hPort = CreateFile(
>
> Port.c_str(),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,dwFlagsAndAttributes,NULL);
>
>
> if (m_hPort == INVALID_HANDLE_VALUE)
> AcuThrowLastError(_T(" CreateFile(") << Port << _T("...)"));
>
> DCB dcb;
> FillMemory(&dcb, sizeof(dcb), 0);
>
> int err = GetCommState(m_hPort, &dcb);
> if (err == 0)
> AcuThrowLastError(_T("GetCommState()"));
>
> dcb.BaudRate = Baud;
> dcb.ByteSize = Bits;
> dcb.Parity = Parity;
> dcb.StopBits = Stop;
> dcb.fParity = TRUE;
> dcb.fOutxDsrFlow = FALSE;
> dcb.fOutxCtsFlow = FALSE;
> dcb.fDtrControl = DTR_CONTROL_ENABLE;
> dcb.fDsrSensitivity = FALSE;
> dcb.fInX = FALSE;
> dcb.fOutX = FALSE;
> dcb.fAbortOnError = FALSE;
> dcb.fRtsControl = RTS_CONTROL_ENABLE;
> err = SetCommState(m_hPort, &dcb);
> if (err == 0)
> AcuThrowLastError(_T("SetCommState(") << Baud << _T(",") <<
> (unsigned long) Bits <<
> _T(",") << (unsigned long) Stop << _T(",") << (unsigned
> long) Parity << _T(")"));
>
> COMMTIMEOUTS cto;
> FillMemory(&cto, sizeof(cto), 0);
>
> err = GetCommTimeouts(m_hPort, &cto);
> if (err == 0)
> AcuThrowLastError(_T("GetCommTimeouts()"));
>
> cto.ReadIntervalTimeout = TimeoutPerChar;
> cto.ReadTotalTimeoutMultiplier = TimeoutPerChar;
> cto.ReadTotalTimeoutConstant = 0;
> cto.WriteTotalTimeoutMultiplier = TimeoutPerChar;
> cto.WriteTotalTimeoutConstant = 0;
> err = SetCommTimeouts(m_hPort, &cto);
> if (err == 0)
> AcuThrowLastError(_T(" SetCommTimeouts(") << TimeoutPerChar
> << _T("...)"));
>
> DWORD Error;
> COMSTAT CommStat;
> err = ClearCommError(m_hPort, &Error, &CommStat);
> if (err == 0)
> AcuThrowLastError(_T("ClearCommError()"));
>
> if (!SetupComm(m_hPort, 32768, 32768)) //Heavy boots, that'll
> stop the bouncing ###new!!!
> AcuThrowLastError(_T("SetupComm)"));
> }
> AcuCatchLogAndRethrow (_T("CHardwareCommsRS232::CHardwareCommsRS232"));
> }
> //--------------------------------------------------------------------------------------------------
>
>
>
> unsigned long CHardwareCommsRS232::ReadString(char * pBuf,
> unsigned long const Length,
> bool const
> ThrowExceptionIfItTimesOut)
> {
> unsigned long CharsRead = 0;
> try
> {
> if (Length == 0)
> return 0;
>
> //We're not going to null-terminate the string, since they might
> have passed us an
> //std::string; it says we're not going to in the header
> if (!ReadFile(m_hPort, pBuf, Length, &CharsRead, NULL))
> AcuThrowLastError(_T("ReadFile(") << Length << _T(")"));
>
> if ((CharsRead!=Length) && (ThrowExceptionIfItTimesOut))
> AcuThrowLastError(_T("ReadFile(") << Length << _T(")"));
> }
> AcuCatchLogAndRethrow(_T("Failed to read ") << Length << _T("
> characters, got '") <<
> CharsRead << _T("'."));
> return CharsRead;
> }
> //--------------------------------------------------------------------------------------------------
>
>
> I guess if you all get really stuck I can post my entire set of serial
> comms classes, but tbh I'd prefer not to.
> Tell you what, I'll post it all if someone can fix my PCMCIA/ATADISK
> problem ;p
>
>
> bernie wrote:
>
>> Hi,
>> Now, I don't use WainCommEvent() call, just readFile() in a
>> thread..... but it still doesn't work with my pocket PC in reception !!!!
>> No bytes readed!
>> for the timeout I use:
>> COMMTIMEOUTS ct;
>> ct.ReadIntervalTimeout = MAXDWORD;
>> ct.ReadTotalTimeoutMultiplier = 0;
>> ct.ReadTotalTimeoutConstant = 0;
>> ct.WriteTotalTimeoutMultiplier = 10;
>> ct.WriteTotalTimeoutConstant = 1000;
>> if(!SetCommTimeouts(hCommPort, &ct)).........
>>
>> I use "Hyperterminal" on a PC and my pocket PC (IPAQ 3950) with only a
>> 3 wires cable (I use the sync cable with an home made adaptation, only
>> with 3 wires : pin2,3 and 5 on a subd 9 pins).... I send well with TXD.
>>
>> If your software run correctly, can you send me a small program (ARM
>> processor) with send and receive text box, please. And I'll see really
>> if it works (but I doubt).
>> Thanks.
>> Bye
>>
>>
>>
>>
>>
>>
>> JustLooking wrote:
>>
>>> My code is pretty similiar to Ehsan. In fact, it was taken out of the
>>> Windows CE 2 For Dummies book. I ran my application using the
>>> emulator talking to a real device via the com port, and using a Dell
>>> AxiM X5 connecting to the same device using the sync cable. In both
>>> cases, the read thread just struck on the WainCommEvent() call.
>>>
>>> So instead of using this command, I just simply uses the readFile(),
>>> depending on the timeout values as set in the SetCommTimeouts(). This
>>> work out pretty well on the emulator, but occassionally data trasnfer
>>> just stop pending data from the device. Using the emulator does not
>>> cause such behaviour.
>>>
>>> 5thWheel wrote:
>>>
>>>> I had no problems getting the code Ehsan Sadeghi posted to run on
>>>> both of my ce.net platforms (one x86, the other mipsii) (although I
>>>> have not extensively tested it), so I don't think it can be a
>>>> problem with WaitCommEvent or the driver.
>>>> I've used WaitCommEvent in many projects, and have soak tested them
>>>> for weeks without encountering a problem (although I guess maybe I'm
>>>> using different handshaky things to you guys in the projects I've
>>>> had on soak?). Do either of you have any luck running the code
>>>> Ehsan Sadeghi on your platforms?
>>>> Note that like I said, I had no joy running using the emulator, but
>>>> I've never quite figured out if it successfully routes data in and
>>>> out of my laptop's serial port properly.
>>>>
>>>> JustLooking wrote:
>>>>
>>>>> Add me to the list of the people having problem on the
>>>>> WaitCommEvent() call, it will never return. I am using the evc++
>>>>> 4.0, using the emulator and the Dell Axim x5, both using PPC 2003.
>>>>> I truly believe there is some issues with the serial driver.
>>>>> Eventually I have to get rid of the waitCommEvent and just use the
>>>>> ReadFile. Still, there are other problems, like data transfer stops.
>>>>>
>>>
>>>
>>
> Ehsan Sadeghi's source code works on my two platforms (two tiny
> modifications required to make it compile). Can't you try that on your
> platform? I don't have an SDK for whatever you're running, and I don't
> right now have ARM processor support as a part of my compiler.
>
> Dumb question: if you run a hyperterminal-like program on your CE.Net
> platform, and run another on a laptop, then presumably they can talk to
> each other ok?
>
> FYI this is how I open my comport: (see Winbase.h for CBR_900
> definitions etc)
> (The AcuCatch and AcuThrow are exception handling macros, I guess you
> can replace them all with "return;" or afxmessagebox or something).
> CHardwareCommsRS232::CHardwareCommsRS232(CSarahString const &
> Port, //_T("COM1:")
> DWORD const
> TimeoutPerChar, //500
> DWORD const Baud,
> //CBR_9600
> BYTE const Bits,
> //8
> BYTE const Stop,
> //ONESTOPBIT
> BYTE const
> Parity, //NOPARITY
> DWORD const
> dwFlagsAndAttributes) : //0
> m_hPort (NULL)
> {
> try
> {
> m_hPort = CreateFile(
>
> Port.c_str(),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,dwFlagsAndAttributes,NULL);
>
>
> if (m_hPort == INVALID_HANDLE_VALUE)
> AcuThrowLastError(_T(" CreateFile(") << Port << _T("...)"));
>
> DCB dcb;
> FillMemory(&dcb, sizeof(dcb), 0);
>
> int err = GetCommState(m_hPort, &dcb);
> if (err == 0)
> AcuThrowLastError(_T("GetCommState()"));
>
> dcb.BaudRate = Baud;
> dcb.ByteSize = Bits;
> dcb.Parity = Parity;
> dcb.StopBits = Stop;
> dcb.fParity = TRUE;
> dcb.fOutxDsrFlow = FALSE;
> dcb.fOutxCtsFlow = FALSE;
> dcb.fDtrControl = DTR_CONTROL_ENABLE;
> dcb.fDsrSensitivity = FALSE;
> dcb.fInX = FALSE;
> dcb.fOutX = FALSE;
> dcb.fAbortOnError = FALSE;
> dcb.fRtsControl = RTS_CONTROL_ENABLE;
> err = SetCommState(m_hPort, &dcb);
> if (err == 0)
> AcuThrowLastError(_T("SetCommState(") << Baud << _T(",") <<
> (unsigned long) Bits <<
> _T(",") << (unsigned long) Stop << _T(",") << (unsigned
> long) Parity << _T(")"));
>
> COMMTIMEOUTS cto;
> FillMemory(&cto, sizeof(cto), 0);
>
> err = GetCommTimeouts(m_hPort, &cto);
> if (err == 0)
> AcuThrowLastError(_T("GetCommTimeouts()"));
>
> cto.ReadIntervalTimeout = TimeoutPerChar;
> cto.ReadTotalTimeoutMultiplier = TimeoutPerChar;
> cto.ReadTotalTimeoutConstant = 0;
> cto.WriteTotalTimeoutMultiplier = TimeoutPerChar;
> cto.WriteTotalTimeoutConstant = 0;
> err = SetCommTimeouts(m_hPort, &cto);
> if (err == 0)
> AcuThrowLastError(_T(" SetCommTimeouts(") << TimeoutPerChar
> << _T("...)"));
>
> DWORD Error;
> COMSTAT CommStat;
> err = ClearCommError(m_hPort, &Error, &CommStat);
> if (err == 0)
> AcuThrowLastError(_T("ClearCommError()"));
>
> if (!SetupComm(m_hPort, 32768, 32768)) //Heavy boots, that'll
> stop the bouncing ###new!!!
> AcuThrowLastError(_T("SetupComm)"));
> }
> AcuCatchLogAndRethrow (_T("CHardwareCommsRS232::CHardwareCommsRS232"));
> }
> //--------------------------------------------------------------------------------------------------
>
>
>
> unsigned long CHardwareCommsRS232::ReadString(char * pBuf,
> unsigned long const Length,
> bool const
> ThrowExceptionIfItTimesOut)
> {
> unsigned long CharsRead = 0;
> try
> {
> if (Length == 0)
> return 0;
>
> //We're not going to null-terminate the string, since they might
> have passed us an
> //std::string; it says we're not going to in the header
> if (!ReadFile(m_hPort, pBuf, Length, &CharsRead, NULL))
> AcuThrowLastError(_T("ReadFile(") << Length << _T(")"));
>
> if ((CharsRead!=Length) && (ThrowExceptionIfItTimesOut))
> AcuThrowLastError(_T("ReadFile(") << Length << _T(")"));
> }
> AcuCatchLogAndRethrow(_T("Failed to read ") << Length << _T("
> characters, got '") <<
> CharsRead << _T("'."));
> return CharsRead;
> }
> //--------------------------------------------------------------------------------------------------
>
>
> I guess if you all get really stuck I can post my entire set of serial
> comms classes, but tbh I'd prefer not to.
> Tell you what, I'll post it all if someone can fix my PCMCIA/ATADISK
> problem ;p
>
>
> bernie wrote:
>
>> Hi,
>> Now, I don't use WainCommEvent() call, just readFile() in a
>> thread..... but it still doesn't work with my pocket PC in reception !!!!
>> No bytes readed!
>> for the timeout I use:
>> COMMTIMEOUTS ct;
>> ct.ReadIntervalTimeout = MAXDWORD;
>> ct.ReadTotalTimeoutMultiplier = 0;
>> ct.ReadTotalTimeoutConstant = 0;
>> ct.WriteTotalTimeoutMultiplier = 10;
>> ct.WriteTotalTimeoutConstant = 1000;
>> if(!SetCommTimeouts(hCommPort, &ct)).........
>>
>> I use "Hyperterminal" on a PC and my pocket PC (IPAQ 3950) with only a
>> 3 wires cable (I use the sync cable with an home made adaptation, only
>> with 3 wires : pin2,3 and 5 on a subd 9 pins).... I send well with TXD.
>>
>> If your software run correctly, can you send me a small program (ARM
>> processor) with send and receive text box, please. And I'll see really
>> if it works (but I doubt).
>> Thanks.
>> Bye
>>
>>
>>
>>
>>
>>
>> JustLooking wrote:
>>
>>> My code is pretty similiar to Ehsan. In fact, it was taken out of the
>>> Windows CE 2 For Dummies book. I ran my application using the
>>> emulator talking to a real device via the com port, and using a Dell
>>> AxiM X5 connecting to the same device using the sync cable. In both
>>> cases, the read thread just struck on the WainCommEvent() call.
>>>
>>> So instead of using this command, I just simply uses the readFile(),
>>> depending on the timeout values as set in the SetCommTimeouts(). This
>>> work out pretty well on the emulator, but occassionally data trasnfer
>>> just stop pending data from the device. Using the emulator does not
>>> cause such behaviour.
>>>
>>> 5thWheel wrote:
>>>
>>>> I had no problems getting the code Ehsan Sadeghi posted to run on
>>>> both of my ce.net platforms (one x86, the other mipsii) (although I
>>>> have not extensively tested it), so I don't think it can be a
>>>> problem with WaitCommEvent or the driver.
>>>> I've used WaitCommEvent in many projects, and have soak tested them
>>>> for weeks without encountering a problem (although I guess maybe I'm
>>>> using different handshaky things to you guys in the projects I've
>>>> had on soak?). Do either of you have any luck running the code
>>>> Ehsan Sadeghi on your platforms?
>>>> Note that like I said, I had no joy running using the emulator, but
>>>> I've never quite figured out if it successfully routes data in and
>>>> out of my laptop's serial port properly.
>>>>
>>>> JustLooking wrote:
>>>>
>>>>> Add me to the list of the people having problem on the
>>>>> WaitCommEvent() call, it will never return. I am using the evc++
>>>>> 4.0, using the emulator and the Dell Axim x5, both using PPC 2003.
>>>>> I truly believe there is some issues with the serial driver.
>>>>> Eventually I have to get rid of the waitCommEvent and just use the
>>>>> ReadFile. Still, there are other problems, like data transfer stops.
>>>>>
>>>
>>>
>>



Relevant Pages

  • Re: Problem Cloning PUBLIC directory
    ... you must remove the feature from your platform and ... rebuild, otherwise, the binaries from the old PUBLIC atadisk driver still ... >I fixed the SOURCES file and now everything compiles correctly. ... >>> PlatformBuilder 5.0 and having some problems getting it to compile. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: how to detect the compile is 32 bits or 64 bits?
    ... determined by whether you have a 32- or 64-bit platform. ... Suppose I have an algorithm, such as a cryptography algorithm, that ... but the chunk size differs for the two cases. ... available at compile time increases compiler optimization opportunities ...
    (comp.lang.c)
  • Re: I got SPDRP_ADDRESS error
    ... You can download the latest PSDK even if you aren't using it in VS6. ... so your code will compile with either PSDK in any compiler. ... it will work with any platform that implements this code value. ...
    (microsoft.public.vc.mfc)

Loading