problems with portwrite functions

This is a discussion on problems with portwrite functions within the C++ Programming forums, part of the General Programming Boards category; i need to write a 3 byte protocol to it with the first byte containing 255 the second 1 and ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    14

    problems with portwrite functions

    i need to write a 3 byte protocol to it with the first byte containing 255 the second 1 and the third 127. but in my port write function it gives me an error function does not take 3 parameters
    my code so far is

    /************************************************** *********************

    PortWrite (BYTE Byte)

    ************************************************** *********************/
    void PortWrite (BYTE Byte)
    {
    DWORD dwError,
    dwNumBytesWritten;

    if (!WriteFile (hPort, // Port handle
    &Byte, // Pointer to the data to write
    1, // Number of bytes to write
    &dwNumBytesWritten, // Pointer to the number of bytes
    // written
    NULL)) // Must be NULL for Windows CE
    {
    // WriteFile failed. Report error.
    dwError = GetLastError ();
    }
    }

    how can i write this three byte protocol to the serial port?? iam using a windows OS and using embedded C++
    hope u can help thanx

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    14

    sorry

    no i didnt ignore your suggestions i just couldnt get them to work!
    could i email u my code so you could have a look at it??

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    > could i email u my code so you could have a look at it??
    No.

    Code:
    unsigned char buff[] = { 255, 1, 127 };
    if (!WriteFile (hPort,              // Port handle
                    buff,               // Pointer to the data to write 
                    3,                  // Number of bytes to write
                    &dwNumBytesWritten, // Pointer to the number of bytes written
                    NULL))              // Must be NULL for Windows CE
    {
        // WriteFile failed. Report error.
        dwError = GetLastError ();
    }
    Did you try this?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    14

    yep tried it

    i tried that but i have got probs in my main what should i have in there other than
    /*
    *
    * controller.cpp
    *
    *
    *
    *
    */

    #include <windows.h>
    #include "carcontrol.h"


    /************************************************** *********************

    WINMAIN ( HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPTSTR lpCmdLine,
    int nCmdShow)

    ************************************************** *********************/

    int WINAPI WinMain( HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPTSTR lpCmdLine,
    int nCmdShow)


    {

    DWORD dwError;
    hPort = INVALID_HANDLE_VALUE; // Serial port handle
    hReadThread = NULL; // Handle to the read thread



    lpszDevName = TEXT("COM1:");

    // Initialize the port.
    if (!PortInitialize (lpszDevName))
    {
    return 0 ;
    }



    PortClose(hPort) ;


    return 0 ;

    }


    because at the moment nothing is been sent to the serial port

    ps thanks for your help

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    > because at the moment nothing is been sent to the serial port
    Well your main only seems to open and close the port

    Perhaps you should attach more code - this board supports attachments.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Attaching functions to a class/struct
    By VirtualAce in forum Tech Board
    Replies: 2
    Last Post: 08-04-2003, 10:56 AM
  2. Replies: 6
    Last Post: 05-06-2003, 03:08 PM
  3. Problems with functions in a class with pointer to self
    By BigDaddyDrew in forum C++ Programming
    Replies: 6
    Last Post: 02-03-2003, 10:24 PM
  4. problems passing parameters between functions
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 11-21-2001, 10:41 AM
  5. problems with functions
    By catalyst in forum C Programming
    Replies: 2
    Last Post: 11-18-2001, 05:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21