how to send command to serial ports in C++

Discussion in 'C++' started by Cerebro, Mar 12, 2009.

  1. Cerebro

    Cerebro New Member

    Joined:
    Mar 12, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    I'm really new to C++. I'd like to know how to send command to serial ports.
    Im connecting to a uniwell POS machine and I dont know what commands I'll be using. They gave me this serial communication protocol manual with this format.

    1.4 Clear All Request
    It is always safest to clear all existing report requests before you request the days reports. This is done by sending the following request.
    SOH C - A STX 0 1 CR LF ETX BCC

    how do you send commands like that to a serial port? I know it would be using a WriteFile command but my concern is the format of the command that I'll be using.. coz I havent received any reply from the POS machine I'm trying to connect.

    Thank you.
     
  2. listendinesh

    listendinesh New Member

    Joined:
    Aug 3, 2007
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    You are right that "WriteFile" API would be used for writing data to serial port.
    First you have to take the data into the buffer. like

    Code:
    char buffer[256];
    memset(buffer,0,256);
    strcpy(buffer,"SOH C - A STX 0 1 CR LF ETX BCC");
    Now use WriteFile to write data char by char untill "\0".

    Thanks
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice