用C++编程一个串口,用Dev C++编译软件出现No such file or directory一个头文件找不到咋解决。

这个程序用Dev C++可以不
#include <stdio.h>

#include <string.h>

#include <sys/types.h>

#include <errno.h>

#include <sys/stat.h>

#include <fcntl.h>

#include <unistd.h>

#include <termios.h>

#include <stdlib.h>

#define TRUE 1

#define FALSE 0

int analysis(char *buff);

int OpenDev(char *Dev);

void set_speed(int fd, int speed);

int set_Parity(int fd,int databits,int stopbits,int parity);

int speed_arr[] = { B38400, B19200, B9600, B4800, B2400, B1200, B300, B38400, B19200, B9600, B4800, B2400, B1200, B300, };

int name_arr[] = {38400, 19200, 9600, 4800, 2400, 1200, 300, 38400, 19200, 9600, 4800, 2400, 1200, 300, };

int OpenDev(char *Dev)

{

int fd = open(Dev,O_RDWR | O_NOCTTY | O_NONBLOCK);

if(-1 == fd)

{

perror("Can't Open Serial Port");

return -1;

}

else

{

printf("Open com success!!!!!!!!!!!");

return fd;

}

}

void set_speed(int fd, int speed)

{

int i;

int status;

struct termios Opt;

?tcgetattr(fd, &Opt);

for ( i= 0; i < sizeof(speed_arr) / sizeof(int); i++)

?{

if (speed == name_arr[i])

{

第1个回答  2018-07-18
#include<windows.h>
#include<stdio.h>
int main()
{
  HANDLE hComm;

  hComm = CreateFile(“\\\\.\\COM24”,                //port name
                      GENERIC_READ | GENERIC_WRITE, //Read/Write
                      0,                            // No Sharing
                      NULL,                         // No Security
                      OPEN_EXISTING,// Open existing port only
                      0,            // Non Overlapped I/O
                      NULL);        // Null for Comm Devices

  if (hComm == INVALID_HANDLE_VALUE)
      printf(“Error in opening serial port”);
  else
      printf(“opening serial port successful”);

  CloseHandle(hComm);//Closing the Serial Port

  return 0;
}
//正确操作方法
hComm = CreateFile(“COM1”,          // for COM1—COM9 only
                   GENERIC_READ | GENERIC_WRITE, //Read/Write
                   0,               // No Sharing
                   NULL,            // No Security
                   OPEN_EXISTING,   // Open existing port only
                   0,               // Non Overlapped I/O
                   NULL);

本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网