Very Urgent 5000 pts: Hyperterminal programming in C++

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
yogithiteAsked:
Who is Participating?
 
DanRollinsCommented:
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
 
alb66Commented:
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
 
alb66Commented:
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
How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

 
yogithiteAuthor Commented:
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
 
alb66Commented:
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
 
yogithiteAuthor Commented:
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
 
alb66Commented:
OK, it's clear. IMO my first comment is the solution
0
 
yogithiteAuthor Commented:
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
 
alb66Commented:
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
 
alb66Commented:
Sorry, I wanted to write:
>>>> think you cannot do that in the main thread
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.