How to read hex values with read function on UART

2014-02-20T22:55:41

I need some help with the serial port (UART) read function. I need to read in and display the hex value, but currently I'm reading in the ASCII values.

to send the hex over the UART I use

char data [] = {0xFF};
write(fd, data, sizeof(data));

which does the work well. But I have a problem with the reading in. I want to be able to read hex values and use the read values later.

Currently I'm reading with this function

read(fd, buffer, sizeof(buffer));

But as a result it displays me the ASCII values, I know I need to make some kind of conversion, but I have searched and was unsuccessful of finding how to do it.

Thanks in advance.

Copyright License:
Author:「Anders」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/21911401/how-to-read-hex-values-with-read-function-on-uart

About “How to read hex values with read function on UART” questions

I need some help with the serial port (UART) read function. I need to read in and display the hex value, but currently I'm reading in the ASCII values. to send the hex over the UART I use char d...
I'm using QStringList to read hunderts/thousends of lines from config-file. I want convert 4 Strings from every row to 4 hex-values, concatenate this values to one hex-value and send it via UART to (
I know questions have been asked a lot on this function, but after searching for hours on here I cannot find an answer that helps me figure this out. Here is the function to read in a string throu...
I'm new to C/C++ and I'm trying to make communication by uart using HEX values. Device port: /dev/ttyS2. Baudrate: 38400 I'm using redis to subscribe the messages. And for testing I'm using "Te...
I have a problem with my uart read (on raspberry pi). It works ok but it stops in a loop and waits on data... I made an option O_NDELAY but is stops even so. I use two terminal windows: one is u...
I want read and send thousand of rows from PC to STM32 mikrocontroller using UART interface. Rows looks like: 1089,1089,1089,1089 1089,1089,1089,1089 1101,1101,1101,1101 1126,1126,1126,1126 1259,...
This is my first project on Android App Development. I was trying to communicate with a custom device which reads some counts. I was able to tweak the BluetoothLEGatt and able to read the character...
I am working on Some embedded project[PIC MCU] where I will receive the data over UART..The data will contain some ascii values which I have to convert into HEX and those converted HEX value will be
I am unable to read the serial pins in the NodeMCU Lua environment. I have only been able to read the USB serial port. I have connected a serial adapter to the rx, tx, and g pins. I have tried this
I am currently attempting to read in Hex values from a text file. There can be multiple lines of Hex's and each line can be as long as needed: f53d6d0568c7c7ce 1307a7a1c84058 b41af04b24f3...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.