Communicating

Hello!

I am writning a program that will communicate with a server (Linux) using 
RS232 or TCP/IP. The server is using the same protocol for both. The 
protocol is rather 'chatty', so for each command there is a lot of sending 
and receiving.

I have created a test program for the RS232 communication using blocking. 
It works but the program freezes until the communication is done...

So I thinking about using some kind of event driven way. I have looked at 
Mr. Ramon de Klein's serial classes, and they look very good 
http://www.codeproject.com/system/serial.asp

However I need to know in which command I am and how far I have come. 

E.g. The Command "Load Text" consist of 5 steps
1.	Send Header
2.	Receive Ready or Not Ready
3.	Send Text
4.	Receive Text
5.	Send OK or Not OK

Every receive i guess will end up in a callback function and then I need to 
call the next send.

How do I do this best?

If there is a way that works simularly for RS232 and TCP/IP it would be 
even better!


// Anders
-- 
English is not my first, or second, language
so anything strange, or insulting, is due to
the translation.
Please correct me so I may learn better English!
0
andis59 (75)
6/7/2006 4:19:52 AM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
625 Views

Similar Articles

[PageSpeed] 27

Anders Eriksson wrote:
> Hello!
> 
> I am writning a program that will communicate with a server (Linux) using 
> RS232 or TCP/IP. The server is using the same protocol for both. The 
> protocol is rather 'chatty', so for each command there is a lot of sending 
> and receiving.
> 
> I have created a test program for the RS232 communication using blocking. 
> It works but the program freezes until the communication is done...
> 
> So I thinking about using some kind of event driven way. I have looked at 
> Mr. Ramon de Klein's serial classes, and they look very good 
> http://www.codeproject.com/system/serial.asp
> 
> However I need to know in which command I am and how far I have come. 
> 
> E.g. The Command "Load Text" consist of 5 steps
> 1.	Send Header
> 2.	Receive Ready or Not Ready
> 3.	Send Text
> 4.	Receive Text
> 5.	Send OK or Not OK
> 
> Every receive i guess will end up in a callback function and then I need to 
> call the next send.
> 
> How do I do this best?
> 
> If there is a way that works simularly for RS232 and TCP/IP it would be 
> even better!
> 
> 
> // Anders

To do such multi-step operations in an event-driven way it is best to 
maintain a state variable and implement a finite state machine.  Every 
time you send something or receive something change the state variable 
so you will know what is expected next.

enum {Idle, LoadTextSentHdr, LoadTxtRcvRdy, LoadTxtSentTxt, ...} m_comstate;

-- 
Scott McPhillips [VC++ MVP]

0
Scott
6/7/2006 5:35:45 AM
Reply:

Similar Artilces:

How to realize communication problem?
Hello everybody. I am working on a project in which I read/write data via rs-232 from/to my Windows application to/from an microcontroller. Now, my boss wants me to write a library which he can use for different microcontrollers. This library should store any changes of data. So the desired microcontroller should just be able to pick up the data. You can think of it this way: Me, representing the Windows application, put a sheet of information into a drawer. A buddy of mine, (representing a microcontroller) can go to the drawer an pick up the sheet for further treatment. So, my quest...

Slow or no communication at all
Hello all. Since I'm new around here, please let me know if this is the right place to post this. I've been checking these forums for a long time now, but fortunately I always found what I was looking for and never had the need to post. For that, I want to thank you all for the tremendous work (and help) everyone participating here have been given throughout these years. The problem that brings me here today, relates not entirely to the SBS 2003. What happens is that we have several MAC OS machines connecting to several shares in a SBS 2003. Everything was ok untill one o...

How to communicate between threads?
Hi, there I used "AfxBeginThread()" to run a background working thread, while keeping the displaying thread. Because I got many file names in working thread, I want to show them in the displaying thread. How to get those CStringArray pointer from working thread? Thanks Gary On Tue, 13 Apr 2004 09:31:07 -0700, "Gary" <anonymous@discussions.microsoft.com> wrote: >Hi, there, > >I used "AfxBeginThread()" to run a background working thread, while keeping the displaying thread. Because I got many file names in working thread, I want to show them i...

URGENT: Outlook 2003 / Exchange 2003 SP1 communication ports.
Hi, If anyone could help me with this I would be more than grateful. We have moved our Exchange Server to a DMZ with public address space, we are trying to connect Outlook 2003 clients to the server from our private address space. The routing is all set up correctly as we can ping both ways which leads me to believe it's a port problem, i.e. I haven't opened enough up. I've searched TechNet for the relevant documents and have made the needed changes where necessary. I have set a high static port in the registry on the exchange server and our domain controllers for RPC AD re...

Communicating
Hello! I am writning a program that will communicate with a server (Linux) using RS232 or TCP/IP. The server is using the same protocol for both. The protocol is rather 'chatty', so for each command there is a lot of sending and receiving. I have created a test program for the RS232 communication using blocking. It works but the program freezes until the communication is done... So I thinking about using some kind of event driven way. I have looked at Mr. Ramon de Klein's serial classes, and they look very good http://www.codeproject.com/system/serial.asp However I need t...

Firewire communication
Hi guys, I am trying to interact with a camera through firewire. I wrote a code based on the example given in MSDN. When I execute the code it always return the value 1 no matter whether the device is connected or disconnected. Please let me know what went wrong, i couldnt figure out the problem so for. My code is as follows. -------------------------------------- void CFireDlg::OnDeviceNotify() { // TODO: Add your control notification handler code here CString cs; bool bDevInterResult=FALSE; HDEVNOTIFY *hdn=NULL; bDevInterResult = DoRegisterDeviceInterface(GUID_MP1394MI,...

Excel communicating to csharp application
In Excel I need some information that the csharp application holds. What would be the best aproach for this problem. Any help is really appreciated. THANKS ...

communication
My client needs to communicate between two computers. Is there anyway they can share calendars without a server. I think I know the answer and its nuts. The work arounds I have tried do not work efficiently. Can someone steer me in the right direction? I need to share calendars and winfax pro files ? Thanks Take a look here, it may help: http://www.slipstick.com/outlook/share.htm --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal account will be deleted without r...

Entourage communication issue
My entourage quit communicating last week. Worked fine wednesday, thursday not. I can open entourage, but it won't send or retrieve mail. times out and gives a message that it's a server issue. My wife's works fine. tried installing the latest upgrade from microsoft, still no change. Both our macs have the same email configuration. tried the fixes given in the help section - snding myself an email, restarting entourage, etc, nothing. I'm not a computer genius, and need help. By the way, if i go into windstream via the internet, every thing's normal Thanks,Tj On 7/24...

Handling Thread communications
I have 2 threads used for serial communications (receive and transmit). I've wrestled with a couple of issues off and on for long time. 1. I currently use a ring buffer for the receive thread to put data in. When data is received, the thread uses PostMessage() to send a message to the application to process the data. This works for the most part except now I have encountered a problem when I display a MessageBox() while processing received data; I get more messages from the thread that seem to interfere with the process. ie the MessageBox displays twice for some reason. When I chang...

Office Communicator- Can you create Chat Rooms within Communicator
I need to cross boarders with a live Chat room. I need to find out how I can initiate a chat room for a group of 50 or 60 people. Can anyone assist me? Can Communicator do this. ...

Money for Imate and Nokia communicator 9300
I want to know if there exists a version of Money for I-mate and Nokia communicator 9300 ...

RODC Communication
What are the ports required to be opened from RODC to RWDC. While the RODC does only uni-directional replication, the RODC does need to communicate with a RWDC for multiple reaasons, I have seen that ports required to be open from RWDC to RODC are well documented, however havent seen anything in the other direction. My guess is 53, 88, 123,389,3268,3269,445 does it require RPC 135 and 49152-65535 also?? Pls assist Hello Venkat, See here about firewall ports to be opened: http://support.microsoft.com/kb/179442/ Best regards Meinolf Weber Disclaimer: This posti...

Process communication ??????
Hello! I need help to find the best way to accomplish that. First - To establish a communication between my application(MFC) and a process of another application in my machine. Second - To record, in a buffer, the data coming from .exe, after that, to record them in a .dat file. ps: I know the structure of the data coming from the process of the application of which I want to connect. THANK!!!! I communicate between processes via TCP/IP. I simply serialize and de-serialize structures across my 'inter-app communicator' class built on CAsyncSocket. This also allows me to implemen...

Communication error
When HQ client utility contacts HQ server, an error "Specified path not found. Runtime error '-21470 24893 (80070003)" comes in the HQ server utility and the program shuts down. In HQ CLient "<cstate machine not execute state> error '-21470 24893 " error comes. When client contacts HQ Server, store ID 0 is displayed in HQ server. The application runs for several days and suddenly this error comes. So the HQ server utility has been changed to another system (but connected to the same HQ database). In this machine too it worked fine for some days and sud...

Money 2005 Communication Error
I recently linked a Passport account with my Money file and now I can't import my OFX files from my bank anymore. I saw some other posts related to MSN Billpay which I've never used. It looks like this is a known problem. Does anyone know of a fix? I thought the problem was my bank so I went a couple of weeks before investigating this issue; now my backup file is also corrupted. I tried the Money repair function but to no avail. In microsoft.public.money, keanton wrote: >I recently linked a Passport account with my Money file and now I can't >import my OFX files from ...

Active Directory Communication Directions
Hello Everyone, I am trying to discover somthing about desktop client communications with Active Directory. One can imagine that an AD client would initiate communications to an AD server...for authentication say....but once authenticated...does the client maintain a session with the server? Also...does (or can) the server ever initiate (of its own accord) communications to the client..say for policy updates? I am only talking about AD here...not any other MS based services. If someone could provide a reference...that would be very helpful. Thank you all. Brant How...

usb communication
hi everyone i want to access the external device through the usb, i m working in vc++. but the problem i am facing is that,i am unable to connect to the device. > plz can any one guide me how to proceed with the usb communication in vc++. > is there any standard template available and > specifically which tool in vc++ should be used for such a purpose. reply needed asap:) m@dI wrote: > hi everyone > i want to access the external device through the usb, i m working in > vc++. but the problem i am facing is that,i am unable to connect to the > device. > > plz can a...

thread communication
Hello, How can I pass controll data between multiple threads ? For instance a "server" thread can give notice to the "process" thread that it's received data. Links to any good tutorials on this subject would be great. Thanks A few different ways, if the process thread is a GUI thread (even without a window) you can post or send a message that it's message pump can process or when the thread is created, a pointer to some structure or other object, like maybe a memory mapped file handle or something, which the thread would have to poll to see if something needs...

Communication between two dialogs
Hi All, I have a question regarding the communication between the two dialogs. Basically I am having a main dialog in which I am embedding another dialog, say secondary dialog, Much like the Outlook reminder dialog. Main dialog and Secondary dialog are altogether diferent and there is no relation between them except the main dialog is creating the secondary dialog in it OnInitDialog function. Now, main dialog is having some static buttons and I have assigned the keyboard accelerator to them. The child dialog will contain the control on runtime. So, whenever the focus is set on the child dial...

How to communicate with DLL loaded in address space of Internet Explorer ?
Hello All I have wrote one Browser Helper Object in ATL, As you know that BHO is just a DLL which Internet Explorer loads each time when it starts. That means that BHO runs in the address space of Internet Explorer and works with Internet Explorer. Now I want to call one function of the BHO ( e.g.If IDiscovery is my BHO , then I want to call IDisocvery::CallThisFunction() from a third application) I want to start the working of BHO explicitly.It Means that I want to control the BHO which is loaded in address space of Internet Explorer from another application. There might be many ins...

Communication Error
Hello and thanks for any replies in advance. I recently upgraded from Money 2002 to Money 2006. I connected to my bank account without a problem but I'm having tremendous difficulty restoring my backup file. When I restore it everything seems to go ok at first, i put in my email and password, my computer churns and then I get a window that states, "A communication error occurred. Please try your call again. If you continue to have.....etc etc." Basically it tells me to contact my "financial institution" which I did and they told me they can't help. Afte...

A communication error occurred. Please try your call again.
I've noticed there are a number of us experiencing "life altering" difficulties regarding this particularly irritating error. I for one have not discovered an acceptable workaround, have not gotten help, and am still hopelessly faced with the distinct possibility of having lost years of data. The prospect of trying to recover from this "from scratch" will simply not work. I have bills to pay, taxes to prepare, etc., and have relied on MS-Money for years. In a word, "THIS SUCKS BEYOND ALL REASONABLE COMPREHENSION" OK, so that was more than a word, s...

Serial Communication
I'm trying to read and write from a serial port communication using the MSComm Object. I'm having problems reading, and I suspect that I do not write correctly to it. I know that MSComm.SetOutput() requires a VARIANT so... I have this function that creates a VARIANT from an unsigned char array. [CODE] VARIANT* CIFDlg::insertArrayInVariant( unsigned char* data, unsigned int num_bytes ) { SAFEARRAYBOUND rgb[1]; rgb[0].lLbound = 0; rgb[0].cElements = num_bytes; VARIANT* v = new VARIANT; v->vt = VT_ARRAY|VT_UI1; v->parray = SafeArrayCreate( VT_UI1, 1, rgb ); char *regs; SafeArray...

(MFC) How to use messages to communicate between CMDIFrameWnd and CScrollView?
Alright, so I tried to use AfxGetMainWnd() from inside a CScrollView-derived class to access a function inside of a CMDIFrameWnd-derived class. It worked under the "Debug" configuration, but I'm getting a nasty error under the "Release" configuration: Coil error LNK2019: unresolved external symbol "public: void __thiscall CMainFrame::setCurrRef(class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > >)" (?setCurrRef@CMainFrame@@QAEXV?$CStringT@DV?$StrTraitMFC@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z) referenced in function &...