Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

serial port and ppi in windows xp or 2000

Status
Not open for further replies.

mc&fpga

Member level 1
Member level 1
Joined
Jun 2, 2002
Messages
41
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
419
i want to use serial port parallel port in windows 2000 or xp how i can use them with vc++
any idea or experience about those?
 

Hi
One of my friends have posted the an answer to interface Serial port , this if it can work for you.

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
I can show you how to do it here. I've only used it once, and I can't distribute that code though for licensing issues.

Creating the project

Make a simple Dialog workspace in MSVC via the MFC App wizard. The options don't really matter, but make sure you check the 'ActiveX Controls' option in when the Wizard prompts you in step 2.

Adding CMSComm to your project

Open your resource editor so you can change the main dialog. Look on the toolbar, and verify that you don't already have the MSComm control there (someone else may have modified the default workspace). It looks like a little phone.

Add the control to your project. Click the Project >> Add To Project >> Components and Controls command from the menu. This command will take a while as MSVC scans the registry for registered controls. Select 'Registered ActiveX Controls' and click insert. Find the object 'Microsoft Communications Control, version 6.0.' (or another version), select it, then click insert, then Ok. At this point MSVC will prompt you for which parts of the ActiveX control you want to add. There should only be one listed, CMSComm, keep it checked. MSVC will generate a wrapper class for the object so you can use it. You can change the file names and class name if you want, but for this purpose, I'll assume you left them as is.

Close the add components dialog.

Now, look at your dialog toolbar, in it, you should see a new icon for the CMSComm object. Select it, and draw one of these onto your main form. An icon will appear, but don't worry, the control itself is invisible at run time.

Initializing the CMSComm control

All this can be done at run time, but for now, let's just set the properties at design time. Right click on the icon for the comm control in your dialog resource and pull up the properties dialog. Under the Control, Buffers, and Hardware tabs, set the properties you desire, such as buad rate, parity, port number, etc.

Add a member for the control

To use the control, you need to create a class member. Open the Class Wizard, and from the Member Variables tab, select the comm control (by default it will be called IDC_MSCOMM1) then click the 'Add Variable...' button. Create a name, I used m_comm. Double check that the variable is a control variable, and that it's of the right class (CMSComm). You can now use this member variable to communitcate with your com port.

Using the CMSComm control

Here's a quick example of how to use the control. It's important to wait until your OnInitDialog() call (or anytime after) before trying to use it because not everything will be created/initialized before this.

Code:
CMSComm m_comm; // MFC generated member in the .h file

#include "atlbase.h" // CComVariant support
#define COM_MS_TIMEOUT 5000 // COM1 timeout in milliseconds

// Generate an output.
CString sOut;
// Build your output...
sOut = _T("Hello world");
// Generate a variant for the output.
CComVariant vOut(sOut);
// Send the command.
m_comm.SetOutput(vOut);

// Wait for a reply.
// This is NOT a processor efficient way of doing it,
// but it gets the idea across.
DWORD dwNow, dwTimeOut, dwStart;
dwStart = GetTickCount();
dwTimeOut = COM_MS_TIMEOUT;
CString sIn, sInBuffer;
CComVariant vIn;
for (;;)
{
dwNow = GetTickCount();
if (((dwNow - dwStart) > dwTimeOut) // Timeout elapsed
|| (dwNow < dwStart)) // Happens if tick count wraps past 2^32
break;
vIn.Clear();
vIn = m_comm.GetInput();
sIn = vIn.bstrVal;
sInBuffer += sIn;
// Check a for terminating \r character.
// If we find one, break the loop, otherwise,
// more data is coming.
// The hardware you'll be interfacing with may have a
// a different terminator sequence.
if (sIn.Right(1) == _T("\r"))
break;
}

This is the easy way of doing it. If you're not using a dialog at all, it will be trickier creating the object, since it won't be done automatically by your dialog's ActveX handlers.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top