0

我正在研究用于 aeroflex gaisler 硬件(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 未初始化 访问方向未初始化

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

4

2 回答 2

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);  

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

于 2013-06-03T11:58:52.537 回答
4

使用前定义DWORD accessdirection。无需使用其数据类型调用accessdirection。您可以像下面这样调用它

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

但这只有在您声明时才有效DWORD accessdirection

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

于 2013-06-03T11:59:46.503 回答