Quantcast
Channel: Intel Communities: Message List
Viewing all articles
Browse latest Browse all 18599

How to read binary data via Serial1?

$
0
0

I'm using a sensor that outputs binary data on UART.

I connected it to Edison's Serial1 port and tried to read data, but faced several problems.

 

1)Until LF(0x0A) is sent, Serial1 doesn't work.

My sensor doesn't send LF(0x0A) at the end of message.

When I try to read data (by "read(int fd,char *readbuf,int size);" function), it stops there until 0x0A happens to be sent.

Is there any way to force read before LF(0x0A) is sent ?

 

2)Can't read following bytes:

0x03

0x04

0x0A

0x0B

0x0C

0x0D

0x0E

0x0F

0x11

0x12

0x13

0x15

0x16

0x17

0x1C

0x7F

I suspect these might work as ASCII control code, but I want to prevent it and read as data.

 

3)Loop back

How to stop loop back of Serial1?

It is not required for most sensors.

 

I switched pin mode by this

stty -F /dev/ttyMFD1 115200
echo -n "214" > /sys/class/gpio/export
echo -n "130" > /sys/class/gpio/export
echo -n "248" > /sys/class/gpio/export
echo -n "216" > /sys/class/gpio/export
echo -n "131" > /sys/class/gpio/export
echo -n "249" > /sys/class/gpio/export
echo -n "217" > /sys/class/gpio/export
echo low > /sys/class/gpio/gpio214/direction
echo low > /sys/class/gpio/gpio248/direction
echo in > /sys/class/gpio/gpio216/direction
echo mode1 > /sys/kernel/debug/gpio_debug/gpio130/current_pinmux
echo in > /sys/class/gpio/gpio130/direction
echo high > /sys/class/gpio/gpio249/direction
echo in > /sys/class/gpio/gpio217/direction
echo mode1 > /sys/kernel/debug/gpio_debug/gpio131/current_pinmux
echo out > /sys/class/gpio/gpio131/direction
echo high > /sys/class/gpio/gpio214/direction

 

and tried to read data as followed:

 

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

void PrintHex(char *test,int size){
  int i;  for(i = 0; i < size; i++){  printf("0x%02X ", test[i] & 0x000000FF);  }    printf("\n");
}

int main(void) {
  printf("Serial1 test program starts\n");  int fd;  unsigned int readsize;  char data[4] = { 0x41, 0x47, 0x42, 0x0A };  if((fd = open("/dev/ttyMFD1",O_RDWR)) < 0){  printf("Device File Open Error\n");  exit(1);  }  printf("Device File Opened\n");  write(fd,data,4);  printf("Tx via /dev/ttyMFD1\n");  while(1){       char readbuf[1024]={0};       readsize = read(fd,readbuf,1024);       printf("Rx via /dev/ttyMFD1\n");       PrintHex(readbuf,1024);  }  close(fd);  return 0;
}

It works fine for charactor data (a,b,c...), but not for binary data.


Viewing all articles
Browse latest Browse all 18599

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>