Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   how to send command to serial ports in C++ (http://www.go4expert.com/forums/send-command-serial-ports-cpp-t16517/)

Cerebro 12Mar2009 06:18

how to send command to serial ports in C++
 
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.

listendinesh 12Mar2009 14:06

Re: how to send command to serial ports in C++
 
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


All times are GMT +5.5. The time now is 02:38.