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 4620168
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:31:26+00:00 2026-05-22T02:31:26+00:00

I am working on an embeeded device.and it is connected on COM6 port when

  • 0

I am working on an embeeded device.and it is connected on COM6 port

when i use putty to write to that port it replies me with result.

example is when you say hello,it replies hello.

I wrote a program to write to COM6,i am able to write to the COM6 port but when i am reading i am not getting anything.

my code is…

// HelloWorld.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <windows.h>
int main()
{
    using namespace std;
//  cout << "Hello world!" << endl;



    HANDLE hSerial;

    hSerial = CreateFile("COM6",
    GENERIC_READ | GENERIC_WRITE,
    FILE_SHARE_WRITE | FILE_SHARE_READ,
    0,
    OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL,
    0);

    if(hSerial==INVALID_HANDLE_VALUE)
    {
        if(GetLastError()==ERROR_FILE_NOT_FOUND)
        {
//          TRACE("serial port does not exist for reading\n");
        //serial port does not exist. Inform user.
        }
//          TRACE("some other error,serial port does not exist for reading\n");
        //some other error occurred. Inform user.
    }

    DCB dcbSerialParams = {0};

    dcbSerialParams.DCBlength=sizeof(dcbSerialParams);

    if (!GetCommState(hSerial, &dcbSerialParams)) 
    {
//                  TRACE("error getting state for reading\n");
    //error getting state
    }

    dcbSerialParams.BaudRate=9600;
    dcbSerialParams.ByteSize=8;
    dcbSerialParams.StopBits=ONESTOPBIT;
    dcbSerialParams.Parity=NOPARITY;

    if(!SetCommState(hSerial, &dcbSerialParams))
    {
//                  TRACE("error setting state for reading\n");
    //error setting serial port state
    }
    COMMTIMEOUTS timeouts={0};

    timeouts.ReadIntervalTimeout=50;
    timeouts.ReadTotalTimeoutConstant=50;
    timeouts.ReadTotalTimeoutMultiplier=10;

    timeouts.WriteTotalTimeoutConstant=50;
    timeouts.WriteTotalTimeoutMultiplier=10;

    if(!SetCommTimeouts(hSerial, &timeouts))
    {
//                  TRACE("some error occured for reading\n");
        //error occureed. Inform user
    }       
    int n=100;
    char szBuff[100];
    DWORD dwBytesRead = 0;
    char szBuff1[100]="LIST";

    DWORD dwByteswrote = 0;

    if(!WriteFile(hSerial, szBuff1, n, &dwByteswrote, NULL))
    {
                    cout << "error writing" ;
    }
    cout << dwByteswrote;
    while(1)
    {
        if(!ReadFile(hSerial, szBuff, n, &dwBytesRead, NULL))
        {
            cout << "error reading";
        }
        else
        {
            cout << dwBytesRead;
            if(dwBytesRead>0)
            {
                cout << szBuff;
                break;
            }
        }
    }
}

Can anyone help me in this??
what is the wrong thing i am making??

  • 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-22T02:31:27+00:00Added an answer on May 22, 2026 at 2:31 am

    It might be that you have to send a “line feed” or a “carriage return” after the “LIST” command to actually make the device send data?

    Try sending “LIST\r”, “LIST\n” or “LIST\r\n”.

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

Sidebar

Related Questions

I'm working on an embedded device that does not support unaligned memory accesses. For
I am working on an embedded linux device that requires custom java code to
I am working on some firmware for an embedded device that uses a 16
I am working on an embedded device that uses an SD-Card for storage and
I'm working on an embedded device that connects on local network with RJ45 and
I am working on an embedded Linux device that has only qt. For some
I am new at embedded system programming. I am working on a device that
I am working on embedded device with 266 Mhz processor and 32 Bit bus
I am working on an embedded application where the device is controlled through a
I mostly use SlickEdit and eclipse while working on embedded systems. Once in a

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.