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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:59:24+00:00 2026-05-23T10:59:24+00:00

I have got a task of sending hexadecimal data to my COMPORT in linux.

  • 0

I have got a task of sending hexadecimal data to my COMPORT in linux. I have written this simple C code, but it sends only a decimal number. Can anyone help me in sending an hexadecimal bit.

Here is the code I have written

#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */

int number,n;
void main(void){
open_port(); 
}

  int open_port(void)
{
  int fd; /* File descriptor for the port */


  fd = open("/dev/ttyACM0", O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1)
  {

perror("open_port: Unable to open /dev/ttyACM0 - ");
  }
  else{
     printf("Port Opened successfully\n");
     number = 1;
     while(number!=55){
     scanf("%d",&number);
      n = write(fd, "ATZ\r", number);
     if (n < 0)
     fputs("write() of 4 bytes failed!\n", stderr);
     }


}

  return (fd);
}

Please help

Thanks in advance 🙂 🙂

  • 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-23T10:59:24+00:00Added an answer on May 23, 2026 at 10:59 am

    write is defined as:

     ssize_t write(int fd, const void *buf, size_t count);
    

    That is, it sends count bytes to fd from buf. In your case, the data is always the string “AZTR\r”, plus undefined data after that (if count is > 5). Your program sends neither hexadecimal nor decimal data.

    Do you want to send binary data or a string of hexadecimal characters?

    For option one, you can use: write(fd, somebuffer, len);, where some buffer is a pointer to any set of bytes (including ints, etc).

    For option two, first convert your data to a hexadecimal string using sprintf with %02X as the format string, then proceed to write that data to the port.

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

Sidebar

Related Questions

This is just a simple async task but I have always got strange compiler
I have got this code: XDocument xdoc = XDocument.Load(URI); XElement root = xdoc.Element(forecast); //get
I have got this read file code from microsoft @C:\Users\computing\Documents\mikec\assignment2\task_2.txt That works fine when
I am new in Java and have got as a task to find out,
I have got a Wavecom Supreme GSM modem. I wrote a simple application that
I have got a field that has been setup to allow for Null, but
Lately i have got a task to import a 3D model which is created
I believe task I am trying to accomplish is fairly easy, but I have
i have got 3 tables: Event, task, task_handler. EVENT: event_id|name TASK_HANDLER: event_id|task_seq|handler TASK: event_id|task_seq|script
I have got a multi-threaded app that process a very large data file. Works

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.