我正在研究用于aeroflex盖斯勒硬件(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);
头文件包含一个函数调用和我在函数调用中得到的错误。代码包含函数体,我还在代码中包含了头文件。还包括所有剩余头文件的路径。
答案 0 :(得分:2)
以下链接可能对您有帮助....
这也包含与串口相关的操作。
http://www.dreamincode.net/forums/topic/18720-handle-and-dword-in-serial-programming/
答案 1 :(得分:2)
类型HANDLE
在发生时可能未定义,请尝试添加
#include <windows.h>
在标题的顶部。