协助我找到错误

时间:2013-06-03 11:51:55

标签: c pointers interface serial-port embedded

我正在研究用于aeroflex盖斯勒硬件(RTEMS操作系统和leon2处理器)与桌面终端之间通信的接口(RS232)。我已经为他们之间的通信编写了代码。我在所有函数调用中都收到错误,如果有人遇到过这种问题,请帮我解决。

注意:此错误与我之前的问题不同。

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <ioctl.h>
#include <apbuart.h>
#include <rtems.h>
#include <drvmgr/drvmgr.h>


#ifndef serial_h
    #define serial_h
    #include "serial-com.h"
#endif

//#ifndef read_serial_h
//  #define read_serial_h
//  #include "read-serial.h"
//#endif

#ifndef memory_h
    #define memory_h
    #include "memory.h"
#endif

#define BUFSIZE 500

void readSerialPort(char portname, char tbuffer[8])
{
    char fd;

    // create a new handle for the serial com port
    fd = createSerialPort("portname", DWORD accessdirection); // function call

    // set the configuration of the handle
    setComPortConfig(fd);

    // set the timeout configuration of the handle
    setComPortTimeouts(fd);


    char TBuffer[BUFSIZE];


    sprintf(TBuffer,"%c",tbuffer);


    char nread = strlen(TBuffer);

    readFromSerialPort(fd, TBuffer, nread);
    // read from terminal.
//  // create a new char buffer
//  //char outputBuffer[BUFSIZE];
//  int h1, h2, h3 ;
//
//
//  // copy the two value in the outputbuffer
//  // the ";" is used a delimiter
//  // copy the two value in the outputbuffer
//  // the ";" is used a delimiter
//  sscanf(EF->a,"%d\n",&h1);
//  sscanf(EF->b,"%d",&h2);
//  sscanf(EF->c,"%d\n",&h3);
//
//  // compute the actual size of the output string
//  int nread1 = strlen(EF->a);
//  int nread2 = strlen(EF->b);
//  int nread3 = strlen(EF->c);

    // write the outputBuffer to the serial com port
//  readFromSerialPort(hSerial, EF->a, nread1);
//  readFromSerialPort(hSerial, EF->b, nread2);
//  readFromSerialPort(hSerial, EF->c, nread3);

    // close the handle
    CloseHandle(fd);
}

功能正文:

char createSerialPort("portname", DWORD accessdirection)
{
//  HANDLE hSerial = CreateFile(portname,
//          accessdirection,
//          0,
//          0,
//          OPEN_EXISTING,
//          0,
//          0);
    char fd = CreateFile("/dev/rastaio0/apbuart1", GENERIC_READ | GENERIC_WRITE);  // create = open

    if (fd == INVALID_HANDLE_VALUE) {
        //call GetLastError(); to gain more information
    }

    return hSerial;
}

错误如:     DWORD未初始化     GENERIC_READ | GENERIC_WRITE未初始化     访问方向未初始化

我对函数调用和函数体有疑问。给我一些想法。

2 个答案:

答案 0 :(得分:4)

更改

void readSerialPort(char portname, char tbuffer[8])void readSerialPort(char portname, char *tbuffer)

char createSerialPort("portname", DWORD accessdirection)char createSerialPort(char *portname, DWORD accessdirection)

fd = createSerialPort("portname", DWORD accessdirection);更改为

fd = createSerialPort("/dev/rastaio0/apbuart1", GENERIC_READ | GENERIC_WRITE);

然后

char fd = CreateFile("/dev/rastaio0/apbuart1", GENERIC_READ | GENERIC_WRITE);  

 char fd = CreateFile(portname, accessdirection);  

这将解决您的一些错误。 问候, 卢卡

答案 1 :(得分:4)

在使用之前定义DWORD访问方向。不需要使用其数据类型调用accessdirection。您可以像下面这样调用它

fd = createSerialPort("portname",accessdirection); // function call

但只有在您声明DWORD accessdirection;

之后,这才有效

您没有为char createSerialPort(“portname”,DWORD accessdirection)函数添加原型,因此最好在调用之前定义它。