Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8879159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:53:24+00:00 2026-06-14T19:53:24+00:00

I am using OpenCV in Visual Studio 2010 to track an object, and I

  • 0

I am using OpenCV in Visual Studio 2010 to track an object, and I am trying to send a value to the Arduino to rotate servos attached to the camera. I am using an Arduino Uno. I have completed the C++ code that tracks the object and determines which direction the camera needs to be rotated, but I am having trouble sending this data to the Arduino. I am currently trying to use an RS-232 cable for this. I am using a Type-B USB cable to program my Arduino and an RS-232 to try to send the data from Visual Studio to the Arduino. Here is my code for the Visual Studio serial communication:

     int portspeed(int centerpix, int xmid)
{HANDLE hDevice = CreateFile(L"COM5",GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,0);
    DCB lpTest;
    GetCommState(hDevice,&lpTest);
    lpTest.BaudRate = CBR_9600;
    lpTest.ByteSize = 8;
    lpTest.Parity = NOPARITY;
    lpTest.StopBits = ONESTOPBIT;
    SetCommState(hDevice,&lpTest);
    DWORD btsIO;

    if (centerpix<xmid)
    {
        char test[] = "2";
        WriteFile(hDevice,test,strlen(test),&btsIO,NULL);
        cout << "Turn right " << test << endl;
    }
    else
    {
        char test[] = "3";
        WriteFile(hDevice,test,strlen(test),&btsIO,NULL);
        cout << "Turn left " << test << endl;
    }

    return 0;
}

On the Arduino code side I have this, which I am using to attempt to light two different LEDS to see if the program is able to correctly communicate which direction it needs to rotate:

int incomingByte = 0;   // For incoming serial data
void setup()
{
    Serial.begin(9600);     // Opens serial port, sets data rate to 9600 bit/s
}

void loop()
{
    // Send data only when you receive data:
    if (Serial.available() > 0)
    {
        incomingByte = Serial.read();
        if (incomingByte==50)   //if =2
            analogWrite(9,100);
        else
            analogWrite(9,0);
        if (incomingByte==51)   //if =3
            analogWrite(10,50);
        else analogWrite(10,0);
            delay(3000);
    }
    else
        analogWrite(9,255);
}

My interpretation is that I need to start the C++ program (which continuously sends the data over the serial communication), and then attach the TX pin from the RS-232 into the RX pin (digital 0) on the Arduino. When I try to upload the program to the Arduino I am given an error,

avrdude: stk500_getsync(): not in sync: resp=0x00

This only occurs when I have a wire going into the RX pin, even if this wire is not connected to anything. I believe that this error occurs because the RX is looking for an input with a baud rate of 9600, but it still gives me this error when the C++ program is running and sending the data with a rate of 9600.

How can I send a value from a Visual Studio project doing real time image processing on a laptop to an Arduino via serial communication?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:53:26+00:00Added an answer on June 14, 2026 at 7:53 pm

    Speaking as someone with limited Win32 experience (more of a .NET guy, really), I think your problem may be in write buffering.

    By default, writes to a file or port are buffered in memory. Perhaps the write is never getting sent to the port as you are never closing the file handle nor calling [FlushFileBuffers][3].

    Try adding this prior to return 0;:

    //After a time, sensitive write
    FlushFileBuffers(hDevice);
    
    //or, more properly for the end of the program.
    CloseHandle(hDevice);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to calibrate a webcam using OpenCV 2.3.1 and Visual Studio 2010 (c++
Im using Opencv 2.3.1 on Visual studio 2010 (vc10) I have configured opencv based
I am using Microsoft Visual Studio 2010 and the OpenCV 2.3.0 libraries to write
I am trying to use Opencv in the environment of Visual Studio 2010. My
I'm using OpenCV 2.2 with visual studio 2010 on a win 7 64 bit
I'm using OpenCV 2.3 with visual studio 2010 ultimate the OpenCV works well with
I'm currently working on Image stitching using OpenCV 2.3.1 on Visual Studio 2010, but
I am using Opencv 2.3.1 with visual studio 2008 on my windows 7 32
I'm working on a project of image stitching using OpenCV 2.3.1 on Visual Studio
I'm going on with my project of OCR using MS Visual Studio 2008, OpenCV,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.