Go to read serial data on ARM

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Recently on the imx6 to use go as a background service program, need to read serial data, want to use c to read the serial port data cgo

Package Main /* #cgo ldflags:lib/testrs232.a#include "Lib/testrs232.h"
int Opendev (char *buf) {int ret = Opendevice (BUF); return ret;}
int Writedev (char *buf,int writesize) { int ret = Writedevice (buf,writesize); return ret;}
int Setpara (enum Ebaud baud, enum Edatabit databit, enum Eparitybit paritybit, enum Estopbit stopbit) { Setparameter (baud,databit,paritybit,stopbit);}
int ReadData (char *buf,int bufsize) { Return Read_port (buf,bufsize);} */
Import "C"
In the above call, the/**/is in C code, followed by the import "C"
For example: Go to use the function above C.opendev (c.cstring ("/dev/ttymxc2"))Successfully compiled under Linux, and can read the value of the serial port, but want to compile to the arm platform on the board, always show errors, later in the Liteide, editing the current environment, will cgo_enabled=1, default cgo_enabled=0, recompile, or error, cannot find the compiler, later set environment variable CC, set as the tool chain of the board CC=ARM-FSL-LINUX-GNUEABI-GCC, compile successfully

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.