Thread: Syntax error before ubyte

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    37

    Syntax error before ubyte

    Hi,

    I am trying to use the function 'outgoing_response' in the file 'port.c' 'outgoing_response' is defined in file 'cf_packet.h' so I included it in 'port.c' and it gives the compiler error:

    syntax error before "ubyte"

    port.c
    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <string.h>
    #include <unistd.h>
    #include "cf_packet.h"
    
    HANDLE hPort;
    
    
    BOOL WriteByte(BYTE bybyte)
    {
        DWORD iBytesWritten=0;
        DWORD iBytesToRead = 1;
        if(WriteFile(hPort,(LPCVOID) 
            &bybyte,iBytesToRead,&iBytesWritten,NULL)==0)
            return FALSE;
        else return TRUE;
    }
    
    BOOL WriteString(const void *instring, int length)
    {
        int index;
        BYTE *inbyte = (BYTE *) instring;
        for(index = 0; index< length; ++index)
        {
            if (WriteByte(inbyte[index]) == FALSE)
                return FALSE;
        }
        return TRUE;
    }
    
    BOOL ReadByte(BYTE  resp)
    {
        BOOL bReturn = TRUE;
        BYTE rx;
        DWORD dwBytesTransferred=0;
    
        if (ReadFile (hPort, &rx, 1, &dwBytesTransferred, 0)> 0)
        {
            if (dwBytesTransferred == 1)
            {
                resp=rx;
                bReturn  = TRUE;
            }
            else bReturn = FALSE;
        }
        else    bReturn = FALSE;
        return bReturn;
    }
    
    BOOL ReadString(void *outstring, int *length)
    {
        BYTE data;
        BYTE dataout[4096]={0};
        int index = 0;
        while(ReadByte(data)== TRUE)
        {
            dataout[index++] = data;
        }
        memcpy(outstring, dataout, index);
        *length = index;
        return TRUE;
    }
    
    void ClosePort()
    {
        CloseHandle(hPort);
        return;
    }
    
    HANDLE ConfigureSerialPort(LPCSTR  lpszPortName)
    {
        HANDLE hComm = NULL;
        DWORD dwError;
        DCB PortDCB;
        COMMTIMEOUTS CommTimeouts;
        // Open the serial port.
        hComm = CreateFile (lpszPortName, // Pointer to the name of the port
            GENERIC_READ | GENERIC_WRITE,
            // Access (read-write) mode
            0,              // Share mode
            NULL,           // Pointer to the security attribute
            OPEN_EXISTING,  // How to open the serial port
            0,              // Port attributes
            NULL);          // Handle to port with attribute to copy
        // Initialize the DCBlength member.
        PortDCB.DCBlength = sizeof (DCB);
        // Get the default port setting information.
        GetCommState (hComm, &PortDCB);
        // Change the DCB structure settings.
        PortDCB.BaudRate = 115200;              // Current baud
        PortDCB.fBinary = TRUE;               // Binary mode; no EOF check
        PortDCB.fParity = TRUE;               // Enable parity checking
        PortDCB.fOutxCtsFlow = FALSE;         // No CTS output flow control
        PortDCB.fOutxDsrFlow = FALSE;         // No DSR output flow control
        PortDCB.fDtrControl = DTR_CONTROL_ENABLE; // DTR flow control type
        PortDCB.fDsrSensitivity = FALSE;      // DSR sensitivity
        PortDCB.fTXContinueOnXoff = TRUE;     // XOFF continues Tx
        PortDCB.fOutX = FALSE;                // No XON/XOFF out flow control
        PortDCB.fInX = FALSE;                 // No XON/XOFF in flow control
        PortDCB.fErrorChar = FALSE;           // Disable error replacement
        PortDCB.fNull = FALSE;                // Disable null stripping
        PortDCB.fRtsControl = RTS_CONTROL_ENABLE; // RTS flow control
        PortDCB.fAbortOnError = FALSE;        // Do not abort reads/writes on error
        PortDCB.ByteSize = 8;                 // Number of bits/byte, 4-8
        PortDCB.Parity = NOPARITY;            // 0-4=no,odd,even,mark,space
        PortDCB.StopBits = ONESTOPBIT;        // 0,1,2 = 1, 1.5, 2
    
        // Configure the port according to the specifications of the DCB structure.
        if (!SetCommState (hComm, &PortDCB))
        {
            printf("Could not configure serial port\n");
            return NULL;
        }
        // Retrieve the time-out parameters for all read and write operations
        // on the port.
        GetCommTimeouts (hComm, &CommTimeouts);
        // Change the COMMTIMEOUTS structure settings.
        CommTimeouts.ReadIntervalTimeout = MAXDWORD;
        CommTimeouts.ReadTotalTimeoutMultiplier = 0;
        CommTimeouts.ReadTotalTimeoutConstant = 0;
        CommTimeouts.WriteTotalTimeoutMultiplier = 0;
        CommTimeouts.WriteTotalTimeoutConstant = 0;
        if (!SetCommTimeouts (hComm, &CommTimeouts))
        {
            printf("Could not set timeouts\n");
            return NULL;
        }
        printf("%s", lpszPortName);
        return hComm;
    }
    
    int main(void)
    {
        //  Can also use COM2, COM3 or COM4 here
        hPort = ConfigureSerialPort("COM1");
        if(hPort == NULL)
        {
            printf("Com port configuration failed\n");
            return -1;
        }
        // Call your ReadString and WriteString functions here
        outgoing_response.command = 31;
        getchar();
        getchar();
        ClosePort();
        return 0;
    }
    cf_packet.h
    Code:
    //============================================================================
    #define MAX_DATA_LENGTH 22
    //============================================================================
    #define MAX_COMMAND 35
    //============================================================================
    typedef struct
      {
      ubyte
        command;
      ubyte
        data_length;
      ubyte
        data[MAX_DATA_LENGTH];
      WORD_UNION
        CRC;
      }COMMAND_PACKET;
    //============================================================================
    word get_crc(ubyte *bufptr,word len,word seed);
    //============================================================================
    extern COMMAND_PACKET
      incoming_command;
    extern COMMAND_PACKET
      outgoing_response;
    //============================================================================
    ubyte check_for_packet(void);
    void send_packet(void);
    //============================================================================
    any ideas?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Where is ubyte defined?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    37
    You are right thank you.

    It is defined in another include file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM