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 に答える