MarshallSoft

C/C++ RS232 Serial Example


// C/C++ RS232 Serial Example

#include <windows.h>
#include <stdio.h>
#include <string.>
#include "wsc.h"

// send command string & wait for response

int SendCommand(int Port, int Baud, char *Command, char *Buffer, int BufLen)
{int Code;
 // reset (open) port (with 1024 TX & RX buffers)
 Code = SioReset(Port, 1024, 1024);
 // error ? (negative return codes are errors)
 if(Code<0) return Code;
 // set baud rate
 Code = SioBaud(Port, Baud);
 if(Code<0) return Code;
 // send string
 Code = SioPuts(Port, Command, strlen(Command));
 if(Code<0) return Code;
 // wait up to 250 mSec for a response
 if(SioWaitFor(Port, 250)<0) return Code;
 // allow time for entire response (depends on serial device)
 Sleep(1);
 // return data
 return SioGets(Port, Buffer, BufLen);
}

MSC Logo

HOME PAGE
MARSHALLSOFT is a trademark of MarshallSoft Computing, Inc.