[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Very Urgent 5000 pts: Hyperterminal programming in C++

Posted on 2009-12-18
10
Medium Priority
?
481 Views
Last Modified: 2013-12-21
Hello Experts,

I have one use case to be programmed.

I have one modem device. I connect to it via hyperterminal.


Use case 1:
-----------

If I just sent 'AT' as a command then I get 'OK' as a response.

I have associated this use case with one VC++ Dialog. If I enter AT Command in one text box, I am able to display the output in another text box.

I call this AT command sequence as solicited AT Command request.


Use case 2:
------------

I have one Unsolicited AT Command like 'AT+SIGNALSTRENGTH'

If I enter this command in hyperterminal once then I get unsolicited responses i.e. I get responses from the device randomly whenever state of device is changed. Hyperterminal is capturing these responses and displaying on screen. Whenever signal strength is changed then device will send notification to hyperterminal. I want to program this use case in VC++ MFC i.e. I want to display all the return values. Code returned for use case 1 does not support unsolicited response. How can we capture and print unsolicited responses.

Can anyone point me to mechanism with which I can program this?

If it would have been possible, I would have assigned 5000 points for this question.

Regards,

Y
0
Comment
Question by:yogithite
  • 6
  • 3
10 Comments
 
LVL 19

Expert Comment

by:alb66
ID: 26078917
You should have one thread that continuosly listen on the serial port, even if no command was sent to the modem. You should display every char received

0
 
LVL 19

Expert Comment

by:alb66
ID: 26078924
This is a good tutorial for implement worker thread from an MFC dialog:

"Threads in MFC Part I: Worker Threads" at
http://devhood.com/tutorials/tutorial_details.aspx?tutorial_id=435
0
 

Author Comment

by:yogithite
ID: 26079013
Hi alb66

Thank you for prompt immediate response.

I would implement a worker thread, but I have question still open in my mind - how to make it work like hyperterminal? I mean in hyperterminal, I type one AT command and device starts dumping information on the screen. How to simulate this in VC++ MFC?

Regards,

Y
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:alb66
ID: 26079303
May be I don't understand your question but, if your program continuosly read from the serial line, you should see all the data coming from the modem. May be that acutally your code read from the serial line only after a command is sent to the modem.
0
 

Author Comment

by:yogithite
ID: 26079434
Hi alb66,

Thank you for your response.

See, via Hyperterminal, if I send 'AT' i get OK as response from modem.

If I send command AT+CSQ then modem starts dumping its data whenever modem finds change in signal strength. + CSQ forces my modem to dump its messages randomly despite of hyperterminal sending command only once.

I would like to capture these random messages coming from the modem

Is my question clear or shall I explain more?

Thanks again for helping me out.

Regards,

Y
0
 
LVL 19

Expert Comment

by:alb66
ID: 26079449
OK, it's clear. IMO my first comment is the solution
0
 

Author Comment

by:yogithite
ID: 26079481
So  as per your opinion, solution is:

I have to send AT command from a worker thread and then i have to listen on COM port for all the responses, am I right?
0
 
LVL 19

Expert Comment

by:alb66
ID: 26079651
No, the worker thread have to listen for all the responses. I think you can do that in the main thread otherwise your application can become no responsive.
0
 
LVL 19

Expert Comment

by:alb66
ID: 26079655
Sorry, I wanted to write:
>>>> think you cannot do that in the main thread
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 2000 total points
ID: 26084971
The problem with serial communications is that if you request to read even one byte, and there is nothing in the queue, then your program stalls there, waiting for incoming data.
What I have done in this case is call
   ClearCommError
    http://msdn.microsoft.com/en-us/library/aa363180(VS.85).aspx
which fills a COMSTAT structure with some data, including how many bytes are available to be read.  So just read exactly that many bytes (and don't read at all if there are zero waiting).
All you need to do is periodiclly check the COMSTAT.cbInQue value.  I recommend doing so on a timer (as opposed to using a separate thread).
 
 
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
In this article we have discussed about the OS X EI Capitan and how to fix Wi-Fi issue in OS X El Capitan. We have explained how to delete system level preferences and create a new Wi-Fi location to resolve Wi-Fi issue.
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
Suggested Courses
Course of the Month20 days, 4 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question