Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Commondialog & Com ports

This topic is 6037 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have 2 questions for a program i am writing. First of all, how do i get the commondialog(especially the openfiledialog) in my program so that i can select files. I know there is a sample program in the msdn, but i can''t make it work. Does someone know a quick and simple way to open such a dialog and retreive the filenam and path?? The other question is how do i open my com port in C++. Do i have to use winsock or are there other ways to do that. And if i have to use winsock does someone have an example how to do that of does someone know where there are some good tutorials on the net. Thanx in advance

Share this post

Link to post
Share on other sites
The socket API isn''t exactly the write thing to use with comports - though files, sockets, and comports all share the read&write API calls.

I never found a *good* tutorial on programming comports under Win32. The examples in MSDN are buggy, and the class that I wrote has a dead-lock issue in it (I''ve realized where the bug is, but I haven''t bothered to fix it yet).

Once you have the com port open, you can read & write to it like a file (sockets can work this way too).

You even use CreateFile to open the comport
CreateFile("Com1", ...)

But you also need to call SetCommState to set your baud rate, parity bit, etc... May want to call Get/SetCommTimeouts as well.
There''s also SetCommMask which you can use to receive notifications about comm events, and then use WaitCommEvent instead of WaitForxxxxObject.

You can skip that stuff if you use read & write to them syncronously - though your app won''t respond during reads & writes, it is the simplest way.

Search MSDN for comport, there was a couple of articles there about a year ago (should still be languishing around).

One thing that I did wrong, and seems to be a common mistake, is when I received a ''data at the port'' notification, I only issued one read request. You have to keep reading the port until there''s no data. This is because the com routines use an event instead of a semaphore for notification; and more data can come in while you''re reading the last chunk. When this happens the event is already signaled, so data stays queued in the driver, and you don''t read it until yet more data comes in. (A semaphore maintains a count, so it would have avoided this issue.)

Magmai Kai Holmlor

"Oh, like you''ve never written buggy code" - Lee

[Look for information | GDNet Start Here | GDNet Search Tool | GDNet FAQ | MSDN RTF[L] | SGI STL Docs | STFW | Asking Smart Questions ]

[Free C++ Libraries | Boost | ACE | Loki | MTL | Blitz++ | wxWindows]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!