我正在研究用于 aeroflex gaisler 硬件(RTEMS 操作系统和 leon2 处理器)和桌面终端之间通信的接口(RS232)。我写了一个代码用于它们之间的通信。我在所有函数调用中都遇到了错误,如果有人遇到过这种问题,请帮助我解决它。
注意:我无法在此处上传我的代码。
ERRORS: expected `)` before `hserial`
expected `)` before `hserial`
expected `)` before `hserial`
expected `=``,`,`;`,`,`asm`or'_attribute_` before `openserialport`
代码:
#include <stdio.h>
#include <stdlib.h>
#include "serial-com.h"
#include <drvmgr/drvmgr.h>
#include <rtems.h>
#include <ioctl.h>
#include <apbuart.h>
HANDLE openSerialPort(LPCSTR portname, DWORD accessdirection){
// HANDLE hSerial = CreateFile(portname,
// accessdirection,
// 0,
// 0,
// OPEN_EXISTING,
// 0,
// 0);
HANDLE hSerial = CreateFile("/dev/rastaio2/apbuart1", O_RDWR);
if (hSerial == INVALID_HANDLE_VALUE) {
//call GetLastError(); to gain more information
}
return hSerial;
}
void setComPortConfig(HANDLE hSerial){
COMMCONFIG dcbSerialParams;
if (!GetCommState(hSerial, &dcbSerialParams.dcb))
{
printf("error getting state \n");
}
dcbSerialParams.dcb.DCBlength = sizeof(dcbSerialParams.dcb);
dcbSerialParams.dcb.BaudRate = 9600;
dcbSerialParams.dcb.ByteSize = 8;
dcbSerialParams.dcb.StopBits = ONESTOPBIT;
dcbSerialParams.dcb.Parity = NOPARITY;
dcbSerialParams.dcb.fBinary = TRUE;
dcbSerialParams.dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcbSerialParams.dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcbSerialParams.dcb.fOutxCtsFlow = FALSE;
dcbSerialParams.dcb.fOutxDsrFlow = FALSE;
dcbSerialParams.dcb.fDsrSensitivity= FALSE;
dcbSerialParams.dcb.fAbortOnError = TRUE;
if (!SetCommState(hSerial, &dcbSerialParams.dcb))
{
printf(" error setting serial port state \n");
}
}
void setComPortTimeouts(HANDLE hSerial){
COMMTIMEOUTS timeouts;
GetCommTimeouts(hSerial,&timeouts);
timeouts.ReadIntervalTimeout = 50;
timeouts.ReadTotalTimeoutConstant = 50;
timeouts.ReadTotalTimeoutMultiplier = 10;
timeouts.WriteTotalTimeoutConstant = 50;
timeouts.WriteTotalTimeoutMultiplier= 10;
}
DWORD writeToSerialPort(HANDLE hSerial, char *data, int length)
{
DWORD dwBytesRead = 1;
if(!WriteFile(hSerial, data, length, &dwBytesRead, NULL)){
//printLastError();
}
return dwBytesRead;
}
DWORD readFromSerialPort(HANDLE hSerial, char *h, int size)
{
DWORD dwBytesRead = 1;
if(!ReadFile(hSerial, h, size, &dwBytesRead, NULL)){
//handle error
}
return dwBytesRead;
}
void closeSerialPort(HANDLE hSerial)
{
CloseHandle(hSerial);
}
头文件:
#include <stdlib.h>
#include <stdint.h>
#include <ioctl.h>
#include <apbuart.h>
#include <rtems.h>
#include <drvmgr/drvmgr.h>
HANDLE openSerialPort(LPCSTR portname, DWORD accessdirection);
DWORD writeToSerialPort(HANDLE hSerial, char *data, int length);
DWORD readFromSerialPort(HANDLE hSerial, char *buffer, int length);
void setComPortConfig(HANDLE hSerial);
void setComPortTimeouts (HANDLE hSerial);
void closeSerialPort(HANDLE hSerial);
头文件包含一个函数调用和我在函数调用中遇到的错误。代码包含函数体,我还在代码中包含了头文件。还包括所有剩余头文件的路径。