Using C++ for USB interfacing

Hi guys, I'm trying to link a Micro-controller board to my C++ program to control the relays on it. The vendor provided a test software in VB that involved entering the COM port number (4 in my case) and clicking a button to sync up with it, the full software and info on the board is here: [http://www.oceancontrols.com.au/KTA-223.html] under the link 'VB6 test software' link. I've tried converting the code to C++ along with using namespaces, etc, but I seem to have hit some problems. The code is pretty long so I'll post the relevant things and the errors.

namespaces being used
1
2
3
4
5
using namespace System;
using namespace System::ComponentModel::Container;
using namespace System::ComponentModel;
using namespace System::Windows;
using namespace System::Windows::Forms;


Component Initialisation from VB changed to C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public ref class zebra
{
	public:
		void InitializeComponent()
			{
		int components = gcnew System.ComponentModel.Container();
		System.ComponentModel.ComponentResourceManager ^resources = gcnew System.ComponentModel.ComponentResourceManager(CzebraDlg.typeid);
		int SerialPort1 = gcnew System.IO.Ports.SerialPort(this->components);
			}
}

internal:
	{
array<System.IO.Ports.SerialPort^> ^SerialPort1 = gcnew array<System.IO.Ports.SerialPort^>(this->components + 1);
	};


For this part, I keep getting errors like
'error C2882: 'System' : illegal use of namespace identifier in expression'
and
'error C2228: left of '.ComponentModel' must have class/struct/union along with others.
I suspect I may gave failed to include something or that my syntax symbols and function calls are in error.

Lastly, the button that reads the COM port number from a text box to sync with the device (code below).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void CzebraDlg::OnBnClickedButton5()
{
	 try
 {
			if (SerialPort1::IsOpen)
			{
				SerialPort1->Close();
			}
			SerialPort1->PortName = "COM" + IDC_EDIT2->Text;
			SerialPort1->Open();
		}
		catch (Exception ^ex)
		{
			CerrorDlg  cid;  //*** Create an instance of our dialog
			cid.DoModal(); //Display Dialog box
		}
	
}


For the button control, I get errors like
error C2227: left of '->Close' must point to class/struct/union/generic type
error C2227: left of '->PortName' must point to class/struct/union/generic type
and others all dealing with the '->' symbols.

I'm not really sure what the compiler is telling me but I suspect it is just a few lines I may not have. Can anyone help? The VB code I derived it from is from the link above. Thanks a lot in advance!! I'm using MFC to build the GUI.
Here's my guess: You don't know C++.

public ref class zebra

int components = gcnew System.ComponentModel.Container();

System.ComponentModel.ComponentResourceManager ^resources = gcnew System.ComponentModel.ComponentResourceManager(CzebraDlg.typeid);

int SerialPort1 = gcnew System.IO.Ports.SerialPort(this->components);

1
2
3
4
internal:
	{
array<System.IO.Ports.SerialPort^> ^SerialPort1 = gcnew array<System.IO.Ports.SerialPort^>(this->components + 1);
	};

And:
catch (Exception ^ex)

None of the above conform to the current C++ standard. What's with gcnew? What with the incorrect use of the ^ operator? I don't even know what that first piece of quoted code could possibly be.
Last edited on
NGen wrote:
Here's my guess: You don't know C++.

What with the incorrect use of the ^ operator?
I think he knows C++, and ^ is if I remember correctly is called tracking handle in C++/CLI (.NET Frameworks)
Ngen wrote:
None of the above conform to the current C++ standard. What's with gcnew? What with the incorrect use of the ^ operator? I don't even know what that first piece of quoted code could possibly be.


Here is the MSDN information about gcnew. I've seen it used before when crossing hardware over to Visual Studios. I'm sure there are other uses for it as well.

http://msdn.microsoft.com/en-us/library/te3ecsc8(VS.80).aspx
Topic archived. No new replies allowed.