Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RS232 with the MSCOMM.ocx

Status
Not open for further replies.

Supersnow

Programmer
Jan 17, 2002
1
GB
Hi,

I am trying to write two different sets of characters to an external Microprocessor which supports RS232. I need to send commands such as "GO;" and "STOP;".

The external processor works fine with HyperTerminal. I thought I could use the MSComm active X control but it does not seem to work? Here is teh code im using

CString strOutput;

strOutput = ("GO;");

m_Serial.SetCommPort(1);
m_Serial.SetSettings("9600,n,8,1");
m_Serial.SetPortOpen(TRUE);
m_Serial.SetOutput(COleVariant(strOutput));
m_Serial.SetPortOpen(FALSE);

Any help would be very welcome
 
I think your problem is that you are trying to caste a CString object as a variant. This won't work. Instead you might try the following.

CString strOutput; strOutput = ("GO;"); // No change here
VARIANT vtData; vtData.vt=VT_BSTR; /* Create a variant data structure and initialise it as type BSTRING*/
vtData.bstrVal=strOutput.AllocSysString(); /* Copy the
Cstring to the VARIANT data structure*/

m_Serial.SetCommPort(1);
m_Serial.SetSettings("9600,n,8,1");
m_Serial.SetPortOpen(TRUE);
m_Serial.SetOutput(vtData);
m_Serial.SetPortOpen(FALSE);

Can you help me with my problem? -There is a C function that allows C to call another executeable as if from a command line prompt eg.

system("c:\type c:\autoexec.bat");

In C++ this will open a Dos window and type the autoexec. Note however that this doesn't work for windows .exe files.

Question? how can I get C++ to call another windows application in the same way as if I click on an icon or go to the Start menu click on run and type in Excel. (which in this instance will start up Excel) - You can contact me at Andrew.Carmichael@polkadotuk.demon.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top