2

I am working on the interface (RS232) for communication between aeroflex gaisler hardware (RTEMS operating system and leon2 processor) and the desktop terminal. I have written a code for communication between them. I am getting a error in all the function calls, if anyone had experienced this kind of problem then please help me to fix it.

NOTE: I am not able to upload my code here.

ERRORS:  expected `)` before `hserial`
         expected `)` before `hserial`
         expected `)` before `hserial`
         expected `=``,`,`;`,`,`asm`or'_attribute_` before `openserialport`

Code:

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

Header file:

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

The header file contains a function call and the error I am getting in the function call only. The code contains the function body and I also included the header file in the code. the path for all the remaining header file is also included.

unwind
  • 391,730
  • 64
  • 469
  • 606

2 Answers2

2

the link below might helps you....

This also contains serial port related operation.

http://www.dreamincode.net/forums/topic/18720-handle-and-dword-in-serial-programming/

Chirag Desai
  • 1,249
  • 1
  • 10
  • 22
2

The type HANDLE is probably undefined at the point it's occuring, try adding

#include <windows.h>

around the top of the header.

unwind
  • 391,730
  • 64
  • 469
  • 606