Go Down

Topic: Using C++ for USB interfacing (Read 3769 times) previous topic - next topic

PaulS

Try using the fully qualified name:
System.IO.Ports.SerialPort ^mySerialPort = gcnew System.IO.Ports.SerialPort(...)

meepokman

Hmm, I've changed it to the full name

Code: [Select]
void CzebraDlg::OnBnClickedButton5()
{
           //SerialPort *mySerialPort = gcnew SerialPort("COM4");
     System.IO.Ports.SerialPort ^mySerialPort = gcnew System.IO.Ports.SerialPort("COM4");
      try
                 {
                       
                 
                 if (mySerialPort->IsOpen)
                       {
                             mySerialPort->Close();
                       }
                 //mySerialPort->PortName = "COM4"// + IDC_EDIT2->Text;
                 mySerialPort->Open();
                 }
           catch (Exception ^ex)
                 {
                 CerrorDlg  cid;  //*** Create an instance of our dialog
                 cid.DoModal(); //Display Dialog box
                 }      
}


But now the errors are different,

[glow]1>.\zebraDlg.cpp(1693) : error C2882: 'System' : illegal use of namespace identifier in expression
1>.\zebraDlg.cpp(1693) : error C2228: left of '.IO' must have class/struct/union
1>.\zebraDlg.cpp(1693) : error C2228: left of '.Ports' must have class/struct/union
1>.\zebraDlg.cpp(1693) : error C2228: left of '.SerialPort' must have class/struct/union
1>.\zebraDlg.cpp(1693) : error C2065: 'mySerialPort' : undeclared identifier
1>.\zebraDlg.cpp(1693) : error C2061: syntax error : identifier 'System'[/glow]
1>.\zebraDlg.cpp(1698) : error C2227: left of '->IsOpen' must point to class/struct/union/generic type
1>        type is ''unknown-type''
1>.\zebraDlg.cpp(1700) : error C2227: left of '->Close' must point to class/struct/union/generic type
1>        type is ''unknown-type''
1>.\zebraDlg.cpp(1703) : error C2227: left of '->Open' must point to class/struct/union/generic type
1>        type is ''unknown-type''

Maybe I missed using a namespace? Here are the ones I'm using

Code: [Select]
#using <System.dll>
#include "stdafx.h"
#include "zebra.h"
#include "zebraDlg.h"
#include <string>
#include <fstream>
#include "windows.h"
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include "usb.h"
#include <setupapi.h>
#include <hidsdi.h>
using namespace System;
using namespace System::IO;
using namespace System::Threading;

PaulS

Are you using Visual Studio to create/edit this application? If so, which version? If not, what are you using?

meepokman

Yup, its Visual Studio, its the 2005 version

PaulS

PM me, and send me your code, please (zip up the whole solution directory). I'll see if I can figure out why your getting these errors.

Go Up