Serialport C++

hello;
I have a written program for obstacle detection with kinect camera.
I wanted to send the distance between the camera and the obstacle via Bluetooth or RS232 to a microcontroller .her is the code:

using namespace System;
using namespace System.IO.Ports;
using namespace System:: Threading;





System.IO.Ports namespace;
/ / Using namespace System:: IO:: Ports;
using namespace System.IO.Ports.SerialPort;

SerialPort Serial;

Serial.PortName = "COM4";
Serial.BaudRate = 9600;
Serial.DataBits = 8;
Serial.StopBits.One;
Serial.ReadTimeout = 500;
Serial.WriteTimeout = 500;

Serial.Open ();
if (Serial.IsOpen)
{
Serial.Write ("mm", depthMD (point.x, point.y));
Serial.Close ();


but unfortunately I always get these error messages:

1> main.cpp (98): error C2143: syntax error: missing ';' before '.'
1> main.cpp (98): error C2143: syntax error: missing ';' before '.'
1> main.cpp (105): error C2059: syntax error: '.'
1> main.cpp (107): error C2143: syntax error: missing ';' before '.'
1> main.cpp (107): error C2143: syntax error: missing ';' before '.'
1> main.cpp (109): error C2065: 'SerialPort': undeclared identifier
1> main.cpp (109): error C2146: syntax error: missing ';' before identifier 'Serial'
1> main.cpp (109): error C2065: 'Serial': undeclared identifier
1> main.cpp (111): error C2065: 'Serial': undeclared identifier
1> main.cpp (111): error C2228: left of must have class / struct / union 'portname'.
1> type is''unknown-type''
1> main.cpp (112): error C2065: 'Serial': undeclared identifier
1> main.cpp (112): error C2228: left of must have class / struct / union 'BaudRate.'
1> type is''unknown-type''
1> main.cpp (114): error C2065: 'Serial': undeclared identifier
1> main.cpp (114): error C2228: left of must have class / struct / union 'data bits.'
1> type is''unknown-type''
1> main.cpp (117): error C2065: 'Serial': undeclared identifier
1> main.cpp (117): error C2228: left of must have class / struct / union 'read timeout.'
1> type is''unknown-type''
1> main.cpp (118): error C2065: 'Serial': undeclared identifier
1> main.cpp (118): error C2228: left of must have class / struct / union 'write timeout.'
1> type is''unknown-type''
1> main.cpp (120): error C2065: 'Serial': undeclared identifier
1> main.cpp (120): error C2228: left of must have class / struct / union 'Open.'
1> type is''unknown-type''
1> main.cpp (121): error C2065: 'Serial': undeclared identifier
1> main.cpp (121): error C2228: left of must have class / struct / union 'IsOpen.'
1> type is''unknown-type''
1> main.cpp (123): error C2065: 'Serial': undeclared identifier
1> main.cpp (123): error C2228: left of must have class / struct / union 'Write.'
1> type is''unknown-type''
1> main.cpp (124): error C2065: 'Serial': undeclared identifier
1> main.cpp (124): error C2228: left of must have class / struct / union 'Close.'
1> type is''unknown-type''


I thank you in advance for your help
closed account (236Rko23)
cant really tell what's the problem but it says there
1> main.cpp (98): error C2143: syntax error: missing ';' before '.'

in case u don't understand it, it says there's a missing semicolon before line 98 in main.cpp

try deleting everything and add 1 line at a time to pinponit the cause of the errrors. at simple sight all i can see is an extra space between System:: and Threading
using namespace System:: Threading;
and a missing } at the end

by the way, when inserting code use the [ code] [ /code] tags (without the space and the beggining) so it's more readable
This code (what there is of it - you've missed out a big, big chunk of it, because the error messages start at line 98) looks like some kind of .NET language, possibly C#.

Trying to compile it as C++ will not work.
Last edited on
closed account (236Rko23)
that's true, C# files end with .cs, C++ with .cpp and C ones with .c

if that's the case then that's the cause. But I can't tell if it's VisualC++ o C# i never did c++ in windows, so don't know if it's normal or not. Af far as the sintaxis goes, it seems to be correct C++ sintaxis
using namespace System.IO.Ports.SerialPort;

That's got .NET and C# written all over it :)
Topic archived. No new replies allowed.