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

  • SEARCH
  • Home
  • 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 6571851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:55:59+00:00 2026-05-25T14:55:59+00:00

I tried the Serial.cpp code from Arduino’s website . I just made a couple

  • 0

I tried the Serial.cpp code from Arduino’s website.

I just made a couple of changes and got the code working properly. However, the issue is, the C++ code serially sends in ASCII values and not integers. For example, if I send in “5” I receive 53 at the receiver side.

I tried changing the buffer type to an int instead of a char, but it returned an error saying:

error C2664: ‘ReadFile’ : cannot convert parameter 2 from ‘int’ to ‘LPVOID’

Is there a way to send integers instead of ASCII values serially?

Below is a snippet of the code.

bool Serial::WriteData(char *buffer, unsigned int nbChar)
{
    DWORD bytesSend;

    //Try to write the buffer on the Serial port
    if (!WriteFile(this->hSerial, (void *)buffer, nbChar, &bytesSend, 0))
    {
        //In case it don't work get comm error and return false
        ClearCommError(this->hSerial, &this->errors, &this->status);

        return false;
    }
    else
        return true;
}


int main() {
    // Convert from char* to wchar*

    char *name_ser="COM7";
    cout << name_ser << "(char*)" << endl;
    size_t origsize=strlen(name_ser)+1;
    const size_t newsize=100;
    size_t convertedChars=0;
    wchar_t wcstring[newsize];
    mbstowcs_s(&convertedChars, wcstring, origsize, name_ser, _TRUNCATE);
    wcscat_s(wcstring, L"(wchar_t*)");
    wcout<<wcstring<<endl;

    Serial serial(wcstring);

    if (serial.IsConnected()){
        while (1){
            char *chr0 = "5";
            serial.WriteData(chr0,1);
            cout<<chr0<<endl;
        }
    }
    system("pause");
    return 0;
}
  • 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-05-25T14:56:00+00:00Added an answer on May 25, 2026 at 2:56 pm

    You’ll probably need to change the method signature. Try something like this:

    bool Serial::WriteData(int * buffer, unsigned int length)
    {
        DWORD bytesSend;
        if(!WriteFile(this->hSerial, (void *)buffer, length*sizeof(int), &bytesSend, 0))
        {
            ClearCommError(this->hSerial, &this->errors, &this->status);
            return false;
        }
        else
            return true;
    }
    

    You’ll need to reconstitute the integers on the Arduino: ints are typically 4 bytes, and I expect the Arduino receive routines are expecting ASCII by default.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We've got some old serial code which checks whether a serial port is available
I've run the simple serial program on my Arduino Uno , which just echos
I've tried out a couple different ways of loading the spinner from SQLite database,
I want to read messages sent from an Arduino via the FTDI (serial) interface
Tried to map it from Preferences -> Settings -> Keyboard, but the key combo
Tried examples from 'php.net' but don't understand what's the problem. Any suggestions? <?php $_SESSION['test']
I want to extract a USB storage device serial number from inside a minifilter
I have some serial code like this that computes word concordances i.e. counting collocated
I've got three tables: CREATE TABLE credential_types ( id serial PRIMARY KEY, name varchar(32)
I have my code that reads and writes to a serial port written in

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.