Linux下C语言怎么向串口写一个带回车换行的字符串

Linux下C语言如何向串口写一个带回车换行的字符串?
说明:
串口已经读写方式打开,并且可以正常读取数据;这个过程没问题。
用write(fd,str_cmd_buf, strlen(str_cmd_buf));返回值0,表示正确; 

但是就是串口那边没反应。(就像 命令没生效一样)。
尝试过strcpy(str_cmd_buf,"\r\n")  也尝试过在串尾追加str_cmd_buf[?]=0x0d和0x0a。也不行。

若用 echo  "str_cmd_buf" >> 串口  ;立即成功,串口有回应; 
又用system调用echo命令,也能成功,有回应。

就是write不行。何故?


------解决思路----------------------
用write(fd,str_cmd_buf, strlen(str_cmd_buf));返回值0,表示正确;
====
返回值不正确啊,
WRITE(2)                   Linux Programmer’s Manual                  WRITE(2)

NAME
       write - write to a file descriptor

SYNOPSIS
       #include <unistd.h>

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

DESCRIPTION
       write() writes up to count bytes from the buffer pointed buf to the file referred to by the file descriptor fd.

       The number of bytes written may be less than count if, for example, there is insufficient space on the underly-
       ing  physical  medium,  or  the  RLIMIT_FSIZE resource limit is encountered (see setrlimit(2)), or the call was
       interrupted by a signal handler after having written less than count bytes.  (See also pipe(7).)

       For a seekable file (i.e., one to which lseek(2) may be applied, for example, a  regular  file)  writing  takes
       place  at  the current file offset, and the file offset is incremented by the number of bytes actually written.
       If the file was open(2)ed with O_APPEND, the file offset is first set to the end of the  file  before  writing.
       The adjustment of the file offset and the write operation are performed as an atomic step.

       POSIX  requires  that a read(2) which can be proved to occur after a write() has returned returns the new data.
       Note that not all file systems are POSIX conforming.

RETURN VALUE
       On success, the number of bytes written is returned (zero indicates nothing was  written).   On  error,  -1  is
       returned, and errno is set appropriately.

       If count is zero and fd refers to a regular file, then write() may return a failure status if one of the errors
       below is detected.  If no errors are detected, 0 will be returned without causing any other effect.   If  count
       is zero and fd refers to a file other than a regular file, the results are not specified.
------解决思路----------------------
楼上正解,
write(fd,str_cmd_buf, strlen(str_cmd_buf));返回值0,表示正确;  --- 返回0表示没写进去
------解决思路----------------------
应该加"\r\n",先回车后换行
------解决思路----------------------
window "\r\n"
linux "\n"
mac "\r"  这个是听说的,没自己试过
------解决思路----------------------
你确定串口那边的程序,看到你发了“\r\n”,会把你发的一行字符串当命令来运行?
------解决思路----------------------
void HexDump(char *buf,int len,int addr) {
    int i,j,k;
    char binstr[80];

    for (i=0;i<len;i++) {
        if (0==(i%16)) {
            sprintf(binstr,"%08x -",i+addr);
            sprintf(binstr,"%s %02x",binstr,(unsigned char)buf[i]);
        } else if (15==(i%16)) {
            sprintf(binstr,"%s %02x",binstr,(unsigned char)buf[i]);
            sprintf(binstr,"%s  ",binstr);
            for (j=i-15;j<=i;j++) {
                sprintf(binstr,"%s%c",binstr,('!'<buf[j]&&buf[j]<='~')?buf[j]:'.');
            }
            printf("%s\n",binstr);
        } else {
            sprintf(binstr,"%s %02x",binstr,(unsigned char)buf[i]);
        }
    }
    if (0!=(i%16)) {
        k=16-(i%16);
        for (j=0;j<k;j++) {
            sprintf(binstr,"%s   ",binstr);
        }
        sprintf(binstr,"%s  ",binstr);
        k=16-k;
        for (j=i-k;j<i;j++) {
            sprintf(binstr,"%s%c",binstr,('!'<buf[j]&&buf[j]<='~')?buf[j]:'.');
        }
        printf("%s\n",binstr);
    }
}