gpt4 book ai didi

c - 帮我找出错误

转载 作者:太空宇宙 更新时间:2023-11-04 05:19:39 24 4
gpt4 key购买 nike

我正在研究 aeroflex gaisler 硬件(RTEMS 操作系统和 leon2 处理器)与桌面终端之间的通信接口(interface) (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_WRITE 未初始化 访问方向未初始化

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

最佳答案

改变

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

这将修复您的一些错误。问候,卢卡

关于c - 帮我找出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16896080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com