本文整理汇总了C++中BuildCommDCB函数的典型用法代码示例。如果您正苦于以下问题:C++ BuildCommDCB函数的具体用法?C++ BuildCommDCB怎么用?C++ BuildCommDCB使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BuildCommDCB函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetIniCommValues
BOOL
GetIniCommValues(
_In_ LPWSTR pName,
LPDCB pdcb,
LPCOMMTIMEOUTS pcto
)
{
BOOL bRet = TRUE;
LPWSTR pszEntry = NULL;
if (bRet)
{
bRet = GetIniCommValuesFromRegistry (pName, &pszEntry);
}
if (bRet)
{
bRet = BuildCommDCB (pszEntry, pdcb);
}
if (bRet)
{
GetTransmissionRetryTimeoutFromRegistry (&pcto-> WriteTotalTimeoutConstant);
pcto->WriteTotalTimeoutConstant*=1000;
}
FreeSplMem(pszEntry);
return bRet;
}
示例2: serial_io_init
/** @fn int serial_io_init( const char* port, const char* strsettings )
*****************************************************************************
* @b Description: initialise a serial port communication
*****************************************************************************
* @param port : port name
* example 'COM7'
* @param strsettings : port settings
* example ; 'baud=115200 parity=N data=8 stop=1'
*****************************************************************************
* @return file descriptor
* -1 if error
*****************************************************************************
**/
int serial_io_init( const char* port, const char* strsettings )
{
HANDLE hCom = NULL;
char strport[16];
snprintf( strport, sizeof( strport ), "\\\\.\\%s", port );
hCom = CreateFile(
strport,
GENERIC_WRITE | GENERIC_READ,
0,
0,
OPEN_EXISTING,
0,
NULL);
if (hCom == INVALID_HANDLE_VALUE)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
dbg(1, "return (fd) : '-1' : serial_io_init error : '%s'\n", lpMsgBuf);
LocalFree( lpMsgBuf ); // Free the buffer.
return -1;
}
DCB dcb;
ZeroMemory(&dcb, sizeof(DCB));
GetCommState(hCom, &dcb);
BuildCommDCB( strsettings, &dcb);
SetupComm(hCom, 4096, 4096);
SetCommState(hCom, &dcb);
COMMTIMEOUTS sCT;
memset(&sCT, 0, sizeof(sCT));
sCT.ReadTotalTimeoutConstant = 10;
SetCommTimeouts(hCom, &sCT);
dbg(1, "serial_io_init return (fd) : '%d'\n", (int)hCom);
return (int)hCom;
}
示例3: setRs232
/*-------------------------------------------
| Name:setRs2322
| Description:
| Parameters:
| Return Type:
| Comments:
| See:
---------------------------------------------*/
int setRs232(uart_config* config){
COMMCONFIG commconfig;
DWORD dwSize=sizeof(COMMCONFIG);
char buffer[256]={0};
sprintf(buffer,"%s: baud=%d parity=%c data=%d stop=%d",USE_COM,
config->speed,
config->parity,
config->data,
config->stop);
if(!GetCommConfig(hCom,&commconfig,&dwSize))
return -1;
BuildCommDCB(buffer,&commconfig.dcb);
//CommConfigDialog(USE_COM,NULL,&commconfig);
if(!SetCommConfig(hCom,&commconfig,dwSize))
return -1;
printf("com cfg: %s\n",buffer);
memcpy(¤t_config,config,sizeof(uart_config));
return 0;
}
示例4: zBuildCommDCB
int far pascal zBuildCommDCB( LPCSTR pp1, DCB far* pp2 )
{
int r;
SaveRegs();
/*
** Log IN Parameters (No Create/Destroy Checking Yet!)
*/
LogIn( (LPSTR)"APICALL:BuildCommDCB ++",
(short)0, (short)0 );
/*
** Call the API!
*/
RestoreRegs();
GrovelDS();
r = BuildCommDCB(pp1,pp2);
UnGrovelDS();
SaveRegs();
/*
** Log Return Code & OUT Parameters (No Create/Destroy Checking Yet!)
*/
LogOut( (LPSTR)"APIRET:BuildCommDCB int+LPCSTR+DCB far*+",
r, pp1, pp2 );
RestoreRegs();
return( r );
}
示例5: initSerial
/**
* @brief This function initializes the serial port for both directions (reading/writing) with fixed parameters:
* \n baud=38400, parity=N, data=8, stop=1
* @param *serialPort is a pointer to the name of the serial port
* @return TRUE if success, FALSE in case of error.
*/
BOOL initSerial(CHAR *serialPort)
{
COMMTIMEOUTS timeouts;
int rc;
DCB dcbStruct;
CHAR msgTextBuf[256];
// open the comm port.
comPort = CreateFile(serialPort, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, NULL);
if (comPort == INVALID_HANDLE_VALUE)
{
printf("Unable to open %s. \n", serialPort);
return FALSE;
}
// get the current DCB, and adjust a few bits to our liking.
memset(&dcbStruct, 0, sizeof(dcbStruct));
dcbStruct.DCBlength = sizeof(dcbStruct);
// printf("dcbStruct.DCBlength(): %ld \n", dcbStruct.DCBlength);
rc = GetCommState(comPort, &dcbStruct);
if (rc == 0)
{
printf("\nGetCommState(): ");
printf(getLastErrorText(msgTextBuf, sizeof(msgTextBuf)));
return FALSE;
}
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa363143(v=vs.85).aspx
BuildCommDCB("baud=38400 parity=N data=8 stop=1", &dcbStruct);
rc = SetCommState(comPort, &dcbStruct);
// If the function fails, the return value is zero.
if (rc == 0)
{
printf("\nSetCommState(): ");
printf(getLastErrorText(msgTextBuf, sizeof(msgTextBuf)));
return FALSE;
}
// Retrieve the timeout parameters for all read and write operations on the port.
GetCommTimeouts (comPort, &timeouts);
timeouts.ReadIntervalTimeout = 250;
timeouts.ReadTotalTimeoutMultiplier = 1;
timeouts.ReadTotalTimeoutConstant = 500;
timeouts.WriteTotalTimeoutMultiplier = 1;
timeouts.WriteTotalTimeoutConstant = 2500;
rc = SetCommTimeouts(comPort, &timeouts); // If the function fails, the return value is zero.
if (rc == 0)
{
printf("\nSetCommTimeouts(): ");
printf(getLastErrorText(msgTextBuf, sizeof(msgTextBuf)));
return FALSE;
}
return TRUE;
}
示例6: CreateFile
static SERIALPORT *serial_open(const char *device){
HANDLE fh;
DCB dcb={sizeof(DCB)};
COMMTIMEOUTS timeouts;
SERIALPORT *port;
fh = CreateFile(device,GENERIC_READ|GENERIC_WRITE,0,NULL,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if (!fh) return NULL;
port = malloc(sizeof(SERIALPORT));
ZeroMemory(port, sizeof(SERIALPORT));
port->fh = fh;
/* save current port settings */
GetCommState(fh,&port->dcb_save);
GetCommTimeouts(fh,&port->timeouts_save);
dcb.DCBlength=sizeof(DCB);
BuildCommDCB("96,n,8,1",&dcb);
SetCommState(fh,&dcb);
ZeroMemory(&timeouts,sizeof(timeouts));
timeouts.ReadTotalTimeoutConstant=1;
timeouts.WriteTotalTimeoutConstant=1;
SetCommTimeouts(fh,&timeouts);
serial_flush(port);
return port;
}
示例7: sconfig
// configure serial port
bool sconfig(char* fmt) {
DCB dcb;
COMMTIMEOUTS cmt;
// clear dcb
memset(&dcb,0,sizeof(DCB));
dcb.DCBlength=sizeof(DCB);
// configure serial parameters
if(!BuildCommDCB(fmt,&dcb)) return false;
dcb.fOutxCtsFlow=0;
dcb.fOutxDsrFlow=0;
dcb.fDtrControl=0;
dcb.fOutX=0;
dcb.fInX=0;
dcb.fRtsControl=0;
if(!SetCommState(h_serial,&dcb)) return false;
// configure buffers
if(!SetupComm(h_serial,1024,1024)) return false;
// configure timeouts
GetCommTimeouts(h_serial,&cmt);
memcpy(&restore,&cmt,sizeof(cmt));
cmt.ReadIntervalTimeout=100;
cmt.ReadTotalTimeoutMultiplier=100;
cmt.ReadTotalTimeoutConstant=100;
cmt.WriteTotalTimeoutConstant=100;
cmt.WriteTotalTimeoutMultiplier=100;
if(!SetCommTimeouts(h_serial,&cmt)) return false;
return true;
}
示例8: Open
bool Open(qCtx *ctx, qStr *out, CStr port, CStr dcb_def) {
DCB dcb;
HANDLE tCom;
tCom = CreateFile( port,
GENERIC_READ | GENERIC_WRITE,
0, // comm devices must be opened w/exclusive-access
NULL, // no security attributes
OPEN_EXISTING, // comm devices must use OPEN_EXISTING
0, // not overlapped I/O
NULL // hTemplate must be NULL for comm devices
);
if (tCom == INVALID_HANDLE_VALUE) {
ctx->ThrowF(out, 601, "Invalid comm port. %y", GetLastError());
return false;
}
GetCommState(tCom, &dcb);
if (!dcb_def.IsEmpty() &&
(!BuildCommDCB(dcb_def, &dcb) || !SetCommState(tCom, &dcb))
) {
ctx->ThrowF(out, 602, "Invalid comm definition parameter(s). %y", GetLastError());
return false;
}
myCom = tCom;
return true;
}
示例9: serial_params
// configures port from string of format
// baudrate,parity,databits,stopbits
// example
// 9600,n,8,1
int serial_params( char* params ) {
DCB dcb;
COMMTIMEOUTS cmt;
memset( &dcb, 0, sizeof( DCB ) );
dcb.DCBlength = sizeof( DCB );
// Configure serial parameters
//printf( "BuildCommDCB\n" );
if( !BuildCommDCB( params, &dcb ) ) return( -1 );
//printf( "SetCommState\n" );
dcb.fOutxCtsFlow = 0;
dcb.fOutxDsrFlow = 0;
dcb.fDtrControl = 0;
dcb.fOutX = 0;
dcb.fInX = 0;
dcb.fRtsControl = 0;
if( !SetCommState( h_serial, &dcb ) ) return( -1 );
// Configure buffers
//printf( "SetupComm\n" );
if( !SetupComm( h_serial, 1024, 1024) ) return( -1 );
// Configure timeouts
cmt.ReadIntervalTimeout = 1000;
cmt.ReadTotalTimeoutMultiplier = 1000;
cmt.ReadTotalTimeoutConstant = 1000;
cmt.WriteTotalTimeoutConstant = 1000;
cmt.WriteTotalTimeoutMultiplier = 1000;
if( !SetCommTimeouts( h_serial, &cmt ) ) return( -1 );
return( 0 );
}
示例10: CreateFile
bool CSerialPort::Open( LPCTSTR lpszComPort,LPCTSTR lpszConString ,int delay_us)
{
CString sPort;
sPort.Format(_T("\\\\.\\%s"), lpszComPort);
m_hComm = CreateFile(sPort, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,0,0);
if (m_hComm == INVALID_HANDLE_VALUE)
{
CString str;
GetErrorStr(str);
LogMessage(str);
return false;
}
Delay_US = delay_us;
// Set Com Settings
DCB dcb;
FillMemory(&dcb, sizeof(dcb), 0);
dcb.DCBlength = sizeof(dcb);
if (!BuildCommDCB(lpszConString, &dcb))
{
// Couldn't build the DCB. Usually a problem
// with the communications specification string.
CString str;
GetErrorStr(str);
LogMessage(str);
LogMessage("Seri Port Hatasý. (BuildComDCB)");
CloseHandle(m_hComm);
m_hComm = NULL;
return false;
}
if (!SetCommState(m_hComm, &dcb))
{
CString str;
GetErrorStr(str);
LogMessage(str);
LogMessage("Seri Port Hatasý. (SetCommState)");
CloseHandle(m_hComm);
m_hComm = NULL;
return false;
}
COMMTIMEOUTS cm;
FillMemory(&cm, sizeof(cm), 0);
cm.ReadIntervalTimeout = 10;
cm.ReadTotalTimeoutConstant = 10;
if(!SetCommTimeouts(m_hComm,&cm))
{
CString str;
GetErrorStr(str);
LogMessage(str);
LogMessage("Seri Port Hatasý. (SetCommTimeouts)");
CloseHandle(m_hComm);
m_hComm = NULL;
return false;
}
LogMessage("Seri port açýldý.");
return true;
}
示例11: open_com_port
//------------------------------------------------------------------------------
bool open_com_port( HANDLE &hCOM_HANDLE, int i_com_port, int i_baud_rate)
{
if ( hCOM_HANDLE != NULL && hCOM_HANDLE != INVALID_HANDLE_VALUE )
{
PurgeComm( hCOM_HANDLE, PURGE_TXABORT);
PurgeComm( hCOM_HANDLE, PURGE_RXABORT);
PurgeComm( hCOM_HANDLE, PURGE_TXCLEAR);
PurgeComm( hCOM_HANDLE, PURGE_RXCLEAR);
CloseHandle( hCOM_HANDLE);
hCOM_HANDLE = NULL;
}
char c_com[50];
::sprintf(c_com, "\\\\.\\COM%d", i_com_port);
hCOM_HANDLE = ::CreateFile( c_com,
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if( hCOM_HANDLE == INVALID_HANDLE_VALUE )
{
//ShowMessage(" COM" + IntToStr( i_com_port) + " is used by other program.");
GC_TRACE("<EfuseWriter> open_com_port(): Com %d is used by other program", i_com_port);
hCOM_HANDLE = NULL;
return false;
}
if( ::SetupComm(hCOM_HANDLE, 8192, 8192)==FALSE )
return false;
if( ::PurgeComm(hCOM_HANDLE, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR)==FALSE )
return false;
COMMTIMEOUTS TimeOut;
TimeOut.ReadIntervalTimeout = 0;
TimeOut.ReadTotalTimeoutMultiplier = 1;
TimeOut.ReadTotalTimeoutConstant = 700;
TimeOut.WriteTotalTimeoutMultiplier = 1;
TimeOut.WriteTotalTimeoutConstant = 700;
SetCommTimeouts(hCOM_HANDLE, &TimeOut);
char c_dcb[50];
::sprintf( c_dcb, "%d,n,8,1", i_baud_rate);
BuildCommDCB( c_dcb, &dcb );
SetCommState( hCOM_HANDLE, &dcb );
return true;
}
示例12: openCOMPort
void openCOMPort(int port)
{
char portString[100];
sprintf(portString, "\\\\.\\COM%i", port);
hComm = CreateFile(portString, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, NULL, 0);
if (hComm == INVALID_HANDLE_VALUE) {
printf("port open error\n");
exit(1);
}
COMMTIMEOUTS commTimeouts;
commTimeouts.ReadIntervalTimeout = MAXDWORD;
commTimeouts.ReadTotalTimeoutMultiplier = MAXDWORD ;
commTimeouts.ReadTotalTimeoutConstant = 1;
commTimeouts.WriteTotalTimeoutMultiplier = 1000;
commTimeouts.WriteTotalTimeoutConstant = 1000;
if (!SetCommTimeouts(hComm, &commTimeouts)) {
printf("SetCommTimeouts error\n");
exit(1);
}
DCB dcb;
if (!GetCommState(hComm, &dcb)) {
printf("GetCommState error\n");
exit(1);
}
if (!BuildCommDCB("baud=115200 parity=N data=8 stop=1", &dcb)) {
printf("BuildCommDCB() error\n");
exit(1);
}
dcb.BaudRate = CBR_115200;
dcb.fBinary = TRUE;
dcb.fParity = FALSE;
dcb.fOutxCtsFlow = FALSE;
dcb.fOutxDsrFlow = FALSE;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fDsrSensitivity = FALSE;
dcb.fOutX = FALSE;
dcb.fInX = FALSE;
dcb.fErrorChar = FALSE;
dcb.fNull = FALSE;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
dcb.fAbortOnError = FALSE;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
if (!SetCommState(hComm, &dcb)) {
printf("SetCommState() error\n");
exit(1);
}
PurgeComm(hComm, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT);
DWORD threadID;
HANDLE thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) commThread, NULL, 0, &threadID);
if (!thread) {
printf("CreateThread() error\n");
exit(1);
}
}
示例13: PrnOpen
BOOL PrnOpen(PCHAR DevName)
{
char Temp[MAXPATHLEN], *c;
DCB dcb;
DWORD DErr;
COMMTIMEOUTS ctmo;
OSVERSIONINFO osvi;
strncpy_s(Temp, sizeof(Temp),DevName, _TRUNCATE);
c = Temp;
while (*c != '\0' && *c != ':') {
c++;
}
*c = '\0';
LPTFlag = (Temp[0]=='L') ||
(Temp[0]=='l');
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
// ネットワーク共有にマップされたデバイスが相手の場合、こうしないといけないらしい (2011.01.25 maya)
// http://logmett.com/forum/viewtopic.php?f=2&t=1383
// http://msdn.microsoft.com/en-us/library/aa363858(v=vs.85).aspx#5
PrnID = CreateFile(Temp,GENERIC_WRITE | FILE_READ_ATTRIBUTES,
FILE_SHARE_READ,NULL,CREATE_ALWAYS,
0,NULL);
}
else {
// 9x では上記のコードでうまくいかないので従来通りの処理
PrnID = CreateFile(Temp,GENERIC_WRITE,
0,NULL,OPEN_EXISTING,
0,NULL);
}
if (PrnID == INVALID_HANDLE_VALUE) {
return FALSE;
}
if (GetCommState(PrnID,&dcb)) {
BuildCommDCB(DevName,&dcb);
SetCommState(PrnID,&dcb);
}
ClearCommError(PrnID,&DErr,NULL);
if (! LPTFlag) {
SetupComm(PrnID,0,CommOutQueSize);
}
/* flush output buffer */
PurgeComm(PrnID, PURGE_TXABORT | PURGE_TXCLEAR);
memset(&ctmo,0,sizeof(ctmo));
ctmo.WriteTotalTimeoutConstant = 1000;
SetCommTimeouts(PrnID,&ctmo);
if (! LPTFlag) {
EscapeCommFunction(PrnID,SETDTR);
}
return TRUE;
}
示例14: SerialInit
static const char * SerialInit(struct serial *sn, const char *Device,
enum SerialBaud Baud, enum SerialStopbits StopBits,
enum SerialProtocol Protocol, enum SerialParity Parity,
enum SerialDatabits DataBits, int dowrite)
{
char mydevice[50];
if(Device[0] != '\\')
snprintf(mydevice, sizeof(mydevice), "\\\\.\\%s", Device);
else
mydevice[0] = 0;
if((sn->Stream = CreateFile(mydevice[0] ? mydevice : Device,
dowrite ? GENERIC_WRITE|GENERIC_READ : GENERIC_READ, 0, 0, OPEN_EXISTING,
0, 0)) == INVALID_HANDLE_VALUE)
return "could not create file";
memset(&sn->Termios, 0, sizeof(sn->Termios));
GetCommState(sn->Stream, &sn->Termios);
DCB dcb;
memset(&dcb, 0, sizeof(dcb));
char str[100];
snprintf(str,sizeof(str),
"baud=%d parity=%c data=%d stop=%d xon=%s octs=%s rts=%s",
Baud, Parity, DataBits, StopBits,
Protocol == SPAPROTOCOL_XON_XOFF ? "on" : "off",
Protocol == SPAPROTOCOL_RTS_CTS ? "on" : "off",
Protocol == SPAPROTOCOL_RTS_CTS ? "on" : "off");
#ifdef DEBUG
fprintf(stderr, "COM Settings: %s\n", str);
#endif
COMMTIMEOUTS ct = {MAXDWORD, 0, 0, 0, 0};
if(!BuildCommDCB(str, &dcb))
{
CloseHandle(sn->Stream);
return "creating device parameters failed";
}
else if(!SetCommState(sn->Stream, &dcb))
{
CloseHandle(sn->Stream);
return "setting device parameters failed";
}
else if(!SetCommTimeouts(sn->Stream, &ct))
{
CloseHandle(sn->Stream);
return "setting timeouts failed";
}
return 0;
}
示例15: sscanf
void CUartChannel::SetupBaud(char *setting)
{
DCB dcb;
sscanf(setting, "%d", &this->m_baud);
if(this->IsOpened() == FALSE)
return;
memset( &dcb, 0, sizeof(DCB) );
dcb.DCBlength = sizeof(DCB);
if (!BuildCommDCB(setting, &dcb))
return;
SetCommState(this->m_Hcomm, &dcb);
}