void EIO_Write(uv_work_t* req) { WriteBaton* data = static_cast<WriteBaton*>(req->data); OVERLAPPED ov = {0}; ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); DWORD bytesWritten; if(!WriteFile((HANDLE)data->fd, data->bufferData, data->bufferLength, &bytesWritten, &ov)) { DWORD lastError = GetLastError(); if(lastError != ERROR_IO_PENDING) { ErrorCodeToString("Writing to COM port (WriteFile)", lastError, data->errorString); return; } if(WaitForSingleObject(ov.hEvent, 1000) != WAIT_OBJECT_0) { DWORD lastError = GetLastError(); ErrorCodeToString("Writing to COM port (WaitForSingleObject)", lastError, data->errorString); return; } if(!GetOverlappedResult((HANDLE)data->fd, &ov, &bytesWritten, TRUE)) { DWORD lastError = GetLastError(); ErrorCodeToString("Writing to COM port (GetOverlappedResult)", lastError, data->errorString); return; } } data->result = bytesWritten; }
void EIO_Write(uv_work_t* req) { QueuedWrite* queuedWrite = static_cast<QueuedWrite*>(req->data); WriteBaton* data = static_cast<WriteBaton*>(queuedWrite->baton); data->result = 0; do { OVERLAPPED ov = {0}; // Event used by GetOverlappedResult(..., TRUE) to wait for outgoing data or timeout // Event MUST be used if program has several simultaneous asynchronous operations // on the same handle (i.e. ReadFile and WriteFile) ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); // Start write operation - synchrounous or asynchronous DWORD bytesWrittenSync = 0; if(!WriteFile((HANDLE)data->fd, data->bufferData, static_cast<DWORD>(data->bufferLength), &bytesWrittenSync, &ov)) { DWORD lastError = GetLastError(); if(lastError != ERROR_IO_PENDING) { // Write operation error ErrorCodeToString("Writing to COM port (WriteFile)", lastError, data->errorString); } else { // Write operation is asynchronous and is pending // We MUST wait for operation completion before deallocation of OVERLAPPED struct // or write data buffer // Wait for async write operation completion or timeout DWORD bytesWrittenAsync = 0; if(!GetOverlappedResult((HANDLE)data->fd, &ov, &bytesWrittenAsync, TRUE)) { // Write operation error DWORD lastError = GetLastError(); ErrorCodeToString("Writing to COM port (GetOverlappedResult)", lastError, data->errorString); } else { // Write operation completed asynchronously data->result = bytesWrittenAsync; } } } else { // Write operation completed synchronously data->result = bytesWrittenSync; } data->offset += data->result; CloseHandle(ov.hEvent); } while (data->bufferLength > data->offset); }
void VisaEmitter::EIO_DeviceClear(GenericBaton* data) { if (!this->isConnected || session < 1) { ErrorCodeToString("not connected", 11, data->errorString); return; } char temp[QUERY_STRING_SIZE]; ViStatus status = viClear(session); if ((status < VI_SUCCESS)) { _snprintf(temp, sizeof(temp), "%d viClear", session); ErrorCodeToString(temp, status, data->errorString); return; } _snprintf_s(data->result, _countof(data->result), _TRUNCATE, "%d", 0); }
TranslationUnit::TranslationUnit(Index& index, const std::string& source, CompilationDatabase& comp_db) { auto commands = comp_db.getCompileCommands(source); unsigned cmd_args = commands.getSize(); if (cmd_args == 0) { throw std::runtime_error("No compilation info for file `" + source + "`"); } auto command = commands.getCommand(0); auto arguments = command.GetArguments(1); arguments.push_back("-I" + comp_db.GetClangHeadersLocation()); std::vector<const char*> c_arguments; c_arguments.reserve(arguments.size()); bool skip = false; for (auto& arg : arguments) { if (skip) { skip = false; continue; } if (arg == "-c") { skip = true; continue; } c_arguments.push_back(arg.c_str()); } CXErrorCode code = clang_parseTranslationUnit2( index.index_, source.c_str(), c_arguments.data(), c_arguments.size(), nullptr, 0, CXTranslationUnit_DetailedPreprocessingRecord, &unit_); if (code != CXError_Success) { throw std::runtime_error("Error while parsing file `" + source + "`: " + ErrorCodeToString(code)); } }
void Round::RPC::JSON::ErrorCodeToError(int jsonErrorCode, Error *error) { int httpStatusCode = HTTP::ErrorCodeToHTTPStatusCode(jsonErrorCode); error->setCode(httpStatusCode); error->setMessage(uHTTP::HTTP::StatusCodeToString(httpStatusCode)); error->setDetailCode(jsonErrorCode); error->setDetailMessage(ErrorCodeToString(jsonErrorCode)); }
void VisaEmitter::EIO_Query(GenericBaton* data) { if (!sizeof(data->command) || !this->isConnected || session < 1) { ErrorCodeToString("not connected or bad empty command", 11, data->errorString); return; } char temp[QUERY_STRING_SIZE]; ViChar rdBuffer[256]; ViStatus status = viQueryf(session, (ViString)data->command, "%256[^,]%*T", rdBuffer); if ((status < VI_SUCCESS)) { _snprintf(temp, sizeof(temp), "%d viQueryf, query: %s string length: %d", session, data->command, strlen(data->command)); ErrorCodeToString(temp, status, data->errorString); return; } // this will not go down nicely on non-WIN32... _snprintf_s(data->result, _countof(data->result), _TRUNCATE, "%s", rdBuffer ); return; }
void EIO_WatchPort(uv_work_t* req) { WatchPortBaton* data = static_cast<WatchPortBaton*>(req->data); data->disconnected = false; while(true){ OVERLAPPED ov = {0}; ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if(!ReadFile(data->fd, data->buffer, bufferSize, &data->bytesRead, &ov)) { data->errorCode = GetLastError(); if(data->errorCode == ERROR_OPERATION_ABORTED) { data->disconnected = true; return; } if(data->errorCode != ERROR_IO_PENDING) { ErrorCodeToString("Reading from COM port (ReadFile)", GetLastError(), data->errorString); return; } DWORD waitResult = WaitForSingleObject(ov.hEvent, 1000); if(waitResult == WAIT_TIMEOUT) { data->bytesRead = 0; data->errorCode = 0; return; } if(waitResult != WAIT_OBJECT_0) { DWORD lastError = GetLastError(); ErrorCodeToString("Reading from COM port (WaitForSingleObject)", lastError, data->errorString); return; } if(!GetOverlappedResult((HANDLE)data->fd, &ov, &data->bytesRead, TRUE)) { DWORD lastError = GetLastError(); if(lastError == ERROR_OPERATION_ABORTED) { data->disconnected = true; return; } ErrorCodeToString("Reading from COM port (GetOverlappedResult)", lastError, data->errorString); return; } } if(data->bytesRead > 0) { return; } } }
void EIO_Close(uv_work_t* req) { CloseBaton* data = static_cast<CloseBaton*>(req->data); g_closingHandles.push_back(data->fd); if(!CloseHandle((HANDLE)data->fd)) { ErrorCodeToString("closing connection", GetLastError(), data->errorString); return; } }
void VisaEmitter::EIO_Write(GenericBaton* data) { if (!sizeof(data->command) || !this->isConnected || session < 1) { ErrorCodeToString("not connected or bad empty command", 11, data->errorString); return; } char temp[QUERY_STRING_SIZE]; memset(temp, 0, sizeof(temp)); ViInt32 rdBufferSize = sizeof(temp); ViUInt32 returnCount; ViStatus status = viWrite(session, (ViBuf)data->command, (ViUInt32) strlen(data->command), &returnCount); if ((status < VI_SUCCESS)) { _snprintf(temp, sizeof(temp), "%d viWrite, query: %s string length: %d; wrote: %d", session, data->command, strlen(data->command), returnCount); ErrorCodeToString(temp, status, data->errorString); return; } _snprintf_s(data->result, _countof(data->result), _TRUNCATE, "%d", returnCount); }
/** Gets a copy of the object's message string. * @return the message string copy. */ std::string message () const { if (message_) { return *message_; } else { return ErrorCodeToString(code_); } }
void EIO_Update(uv_work_t* req) { ConnectionOptionsBaton* data = static_cast<ConnectionOptionsBaton*>(req->data); DCB dcb = { 0 }; SecureZeroMemory(&dcb, sizeof(DCB)); dcb.DCBlength = sizeof(DCB); if (!GetCommState((HANDLE)data->fd, &dcb)) { ErrorCodeToString("GetCommState", GetLastError(), data->errorString); return; } dcb.BaudRate = data->baudRate; if (!SetCommState((HANDLE)data->fd, &dcb)) { ErrorCodeToString("SetCommState", GetLastError(), data->errorString); return; } }
void EIO_Get(uv_work_t* req) { GetBaton* data = static_cast<GetBaton*>(req->data); DWORD bits = 0; if (!GetCommModemStatus((HANDLE)data->fd, &bits)) { ErrorCodeToString("Getting control settings on COM port (GetCommModemStatus)", GetLastError(), data->errorString); return; } data->cts = bits & MS_CTS_ON; data->dsr = bits & MS_DSR_ON; data->dcd = bits & MS_RLSD_ON; }
void VisaEmitter::EIO_Close(GenericBaton* data) { if (!this->isConnected || session < 1) { ErrorCodeToString("not connected", 11, data->errorString); return; } char temp[QUERY_STRING_SIZE]; ViStatus status; if(this->installedSRQHanlder) { status = viDisableEvent(session, VI_EVENT_SERVICE_REQ, VI_HNDLR); if (status < VI_SUCCESS) { _snprintf(temp, sizeof(temp), "viDisableEvent / Device close"); ErrorCodeToString(temp, status, data->errorString); return; } else { status = viUninstallHandler(session, VI_EVENT_SERVICE_REQ, callback, this->uniqueSRQhandlerIdentification); } if (status < VI_SUCCESS) { _snprintf(temp, sizeof(temp), "viUninstallHandler / Device close"); ErrorCodeToString(temp, status, data->errorString); return; } } status = viClose(session); if ((status < VI_SUCCESS)) { _snprintf(temp, sizeof(temp), "%d viClose", session); ErrorCodeToString(temp, status, data->errorString); return; } this->isConnected = false; if (isAsyncInitialized){ uv_close((uv_handle_t*) &m_async, NULL); this->isAsyncInitialized = false; } _snprintf_s(data->result, _countof(data->result), _TRUNCATE, "%d", 0); }
void VisaEmitter::EIO_Read(GenericBaton* data) { if (!this->isConnected || session < 1) { ErrorCodeToString("not connected", 11, data->errorString); return; } int64_t numberOfBytes = atoi(data->command); if (numberOfBytes < 1) { ErrorCodeToString("trying to read 0 bytes...", 11, data->errorString); return; } if (numberOfBytes > (uint32_t)-1) { ErrorCodeToString("trying to read more than uint32 bytes...", 11, data->errorString); return; } data->buffer = (char*) malloc(numberOfBytes + 1); char *temp = (char*) malloc(numberOfBytes + 1); char *p = temp; ViUInt32 returnCount; //while(p != temp+numberOfBytes) { // we need more checks before that cast below... //ViStatus status = viRead(session, reinterpret_cast<ViBuf>(p), (ViUInt32) (temp + numberOfBytes - p), &returnCount); ViStatus status = viRead(session, reinterpret_cast<ViBuf>(temp), (ViUInt32) numberOfBytes, &returnCount); if ((status < VI_SUCCESS)) { _snprintf(temp, sizeof(temp), "%d viRead, returnCount: %d", session, returnCount); ErrorCodeToString(temp, status, data->errorString); return; } //p += returnCount; //} temp[numberOfBytes] = 0; data->bufferLength = returnCount; memcpy(data->buffer, temp, returnCount); delete temp; }
void EIO_Close(uv_work_t* req) { CloseBaton* data = static_cast<CloseBaton*>(req->data); g_closingHandles.push_back(data->fd); HMODULE hKernel32 = LoadLibrary("kernel32.dll"); // Look up function address CancelIoExType pCancelIoEx = (CancelIoExType)GetProcAddress(hKernel32, "CancelIoEx"); // Do something with it if (pCancelIoEx) { // Function exists so call it // Cancel all pending IO Requests for the current device pCancelIoEx((HANDLE)data->fd, NULL); } if (!CloseHandle((HANDLE)data->fd)) { ErrorCodeToString("closing connection", GetLastError(), data->errorString); return; } }
void EIO_Set(uv_work_t* req) { SetBaton* data = static_cast<SetBaton*>(req->data); if (data->rts) { EscapeCommFunction((HANDLE)data->fd, SETRTS); } else { EscapeCommFunction((HANDLE)data->fd, CLRRTS); } if (data->dtr) { EscapeCommFunction((HANDLE)data->fd, SETDTR); } else { EscapeCommFunction((HANDLE)data->fd, CLRDTR); } if (data->brk) { EscapeCommFunction((HANDLE)data->fd, SETBREAK); } else { EscapeCommFunction((HANDLE)data->fd, CLRBREAK); } DWORD bits = 0; GetCommMask((HANDLE)data->fd, &bits); bits &= ~(EV_CTS | EV_DSR); if (data->cts) { bits |= EV_CTS; } if (data->dsr) { bits |= EV_DSR; } if (!SetCommMask((HANDLE)data->fd, bits)) { ErrorCodeToString("Setting options on COM port (SetCommMask)", GetLastError(), data->errorString); return; } }
void EIO_Open(uv_work_t* req) { OpenBaton* data = static_cast<OpenBaton*>(req->data); char originalPath[1024]; strncpy_s(originalPath, sizeof(originalPath), data->path, _TRUNCATE); // data->path is char[1024] but on Windows it has the form "COMx\0" or "COMxx\0" // We want to prepend "\\\\.\\" to it before we call CreateFile strncpy(data->path + 20, data->path, 10); strncpy(data->path, "\\\\.\\", 4); strncpy(data->path + 4, data->path + 20, 10); HANDLE file = CreateFile( data->path, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if (file == INVALID_HANDLE_VALUE) { DWORD errorCode = GetLastError(); char temp[100]; _snprintf_s(temp, sizeof(temp), _TRUNCATE, "Opening %s", originalPath); ErrorCodeToString(temp, errorCode, data->errorString); return; } bufferSize = data->bufferSize; if (bufferSize > MAX_BUFFER_SIZE) { bufferSize = MAX_BUFFER_SIZE; } DCB dcb = { 0 }; dcb.DCBlength = sizeof(DCB); if (data->hupcl == false) { dcb.fDtrControl = DTR_CONTROL_DISABLE; // disable DTR to avoid reset } else { dcb.fDtrControl = DTR_CONTROL_ENABLE; } dcb.BaudRate = CBR_9600; dcb.Parity = NOPARITY; dcb.ByteSize = 8; dcb.StopBits = ONESTOPBIT; dcb.fInX = FALSE; dcb.fOutX = FALSE; dcb.fOutxDsrFlow = FALSE; dcb.fOutxCtsFlow = FALSE; dcb.fRtsControl = RTS_CONTROL_ENABLE; dcb.fBinary = true; dcb.BaudRate = data->baudRate; dcb.ByteSize = data->dataBits; switch (data->parity) { case SERIALPORT_PARITY_NONE: dcb.Parity = NOPARITY; break; case SERIALPORT_PARITY_MARK: dcb.Parity = MARKPARITY; break; case SERIALPORT_PARITY_EVEN: dcb.Parity = EVENPARITY; break; case SERIALPORT_PARITY_ODD: dcb.Parity = ODDPARITY; break; case SERIALPORT_PARITY_SPACE: dcb.Parity = SPACEPARITY; break; } switch (data->stopBits) { case SERIALPORT_STOPBITS_ONE: dcb.StopBits = ONESTOPBIT; break; case SERIALPORT_STOPBITS_ONE_FIVE: dcb.StopBits = ONE5STOPBITS; break; case SERIALPORT_STOPBITS_TWO: dcb.StopBits = TWOSTOPBITS; break; } if (!SetCommState(file, &dcb)) { ErrorCodeToString("SetCommState", GetLastError(), data->errorString); return; } // Set the com port read/write timeouts DWORD serialBitsPerByte = 8/*std data bits*/ + 1/*start bit*/; serialBitsPerByte += (data->parity == SERIALPORT_PARITY_NONE) ? 0 : 1; serialBitsPerByte += (data->stopBits == SERIALPORT_STOPBITS_ONE) ? 1 : 2; DWORD msPerByte = (data->baudRate > 0) ? ((1000 * serialBitsPerByte + data->baudRate - 1) / data->baudRate) : 1; if (msPerByte < 1) { msPerByte = 1; } COMMTIMEOUTS commTimeouts = {0}; commTimeouts.ReadIntervalTimeout = msPerByte; // Minimize chance of concatenating of separate serial port packets on read commTimeouts.ReadTotalTimeoutMultiplier = 0; // Do not allow big read timeout when big read buffer used commTimeouts.ReadTotalTimeoutConstant = 1000; // Total read timeout (period of read loop) commTimeouts.WriteTotalTimeoutConstant = 1000; // Const part of write timeout commTimeouts.WriteTotalTimeoutMultiplier = msPerByte; // Variable part of write timeout (per byte) if (!SetCommTimeouts(file, &commTimeouts)) { ErrorCodeToString("SetCommTimeouts", GetLastError(), data->errorString); return; } // Remove garbage data in RX/TX queues PurgeComm(file, PURGE_RXCLEAR); PurgeComm(file, PURGE_TXCLEAR); data->result = (int)file; }
void EIO_WatchPort(uv_work_t* req) { WatchPortBaton* data = static_cast<WatchPortBaton*>(req->data); data->bytesRead = 0; data->disconnected = false; // Event used by GetOverlappedResult(..., TRUE) to wait for incoming data or timeout // Event MUST be used if program has several simultaneous asynchronous operations // on the same handle (i.e. ReadFile and WriteFile) HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); while (true) { OVERLAPPED ov = {0}; ov.hEvent = hEvent; // Start read operation - synchrounous or asynchronous DWORD bytesReadSync = 0; if (!ReadFile((HANDLE)data->fd, data->buffer, bufferSize, &bytesReadSync, &ov)) { data->errorCode = GetLastError(); if (data->errorCode != ERROR_IO_PENDING) { // Read operation error if (data->errorCode == ERROR_OPERATION_ABORTED) { data->disconnected = true; } else { ErrorCodeToString("Reading from COM port (ReadFile)", data->errorCode, data->errorString); CloseHandle(hEvent); return; } break; } // Read operation is asynchronous and is pending // We MUST wait for operation completion before deallocation of OVERLAPPED struct // or read data buffer // Wait for async read operation completion or timeout DWORD bytesReadAsync = 0; if (!GetOverlappedResult((HANDLE)data->fd, &ov, &bytesReadAsync, TRUE)) { // Read operation error data->errorCode = GetLastError(); if (data->errorCode == ERROR_OPERATION_ABORTED) { data->disconnected = true; } else { ErrorCodeToString("Reading from COM port (GetOverlappedResult)", data->errorCode, data->errorString); CloseHandle(hEvent); return; } break; } else { // Read operation completed asynchronously data->bytesRead = bytesReadAsync; } } else { // Read operation completed synchronously data->bytesRead = bytesReadSync; } // Return data received if any if (data->bytesRead > 0) { break; } } CloseHandle(hEvent); }
void FPhysXErrorCallback::reportError(PxErrorCode::Enum e, const char* message, const char* file, int line) { // if not in game, ignore Perf warnings - i.e. Moving Static actor in editor will produce this warning if (GIsEditor && e == PxErrorCode::ePERF_WARNING) { return; } // Make string to print out, include physx file/line FString ErrorString = FString::Printf(TEXT("PHYSX: (%s %d) %s : %s"), ANSI_TO_TCHAR(file), line, *ErrorCodeToString(e), ANSI_TO_TCHAR(message)); if (e == PxErrorCode::eOUT_OF_MEMORY || e == PxErrorCode::eABORT) { UE_LOG(LogPhysics, Error, TEXT("%s"), *ErrorString); //ensureMsgf(false, TEXT("%s"), *ErrorString); } else if (e == PxErrorCode::eINVALID_PARAMETER || e == PxErrorCode::eINVALID_OPERATION) { UE_LOG(LogPhysics, Error, TEXT("%s"), *ErrorString); //ensureMsgf(false, TEXT("%s"), *ErrorString); } else if (e == PxErrorCode::ePERF_WARNING || e == PxErrorCode::eINTERNAL_ERROR) { UE_LOG(LogPhysics, Warning, TEXT("%s"), *ErrorString); } #if UE_BUILD_DEBUG else if (e == PxErrorCode::eDEBUG_WARNING) { UE_LOG(LogPhysics, Warning, TEXT("%s"), *ErrorString); } #endif else { UE_LOG(LogPhysics, Log, TEXT("%s"), *ErrorString); } }
// This method will return true if we should keep attempting to use a proxy // or false if the auto proxy determination was to use a direct connection. static bool GetAutoProxiesForURL(string& url, vector<SharedProxy>& proxies) { bool shouldUseProxy = true; WINHTTP_PROXY_INFO autoProxyInfo; ZeroMemory(&autoProxyInfo, sizeof(WINHTTP_PROXY_INFO)); WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions; ZeroMemory(&autoProxyOptions, sizeof(WINHTTP_AUTOPROXY_OPTIONS)); // This type of auto-detection might take several seconds, so // if the user specified an autoconfiguration URL don't do it. // TODO: Maybe we should use this as a fallback later, but it's *very* expensive. if (autoConfigURL.empty() && useProxyAutoConfig) { autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT; autoProxyOptions.dwAutoDetectFlags = WINHTTP_AUTO_DETECT_TYPE_DHCP | WINHTTP_AUTO_DETECT_TYPE_DNS_A; } if (!autoConfigURL.empty()) { autoProxyOptions.dwFlags |= WINHTTP_AUTOPROXY_CONFIG_URL; autoProxyOptions.lpszAutoConfigUrl = autoConfigURL.c_str(); } // From Chromium: // Per http://msdn.microsoft.com/en-us/library/aa383153(VS.85).aspx, it is // necessary to first try resolving with fAutoLogonIfChallenged set to false. // Otherwise, we fail over to trying it with a value of true. This way we // get good performance in the case where WinHTTP uses an out-of-process // resolver. This is important for Vista and Win2k3. wstring wideURL = UTF8ToWide(url); autoProxyOptions.fAutoLogonIfChallenged = FALSE; BOOL ok = WinHttpGetProxyForUrl( httpSession.GetHandle(), wideURL.c_str(), &autoProxyOptions, &autoProxyInfo); if (!ok && ERROR_WINHTTP_LOGIN_FAILURE == GetLastError()) { autoProxyOptions.fAutoLogonIfChallenged = TRUE; ok = WinHttpGetProxyForUrl( httpSession.GetHandle(), wideURL.c_str(), &autoProxyOptions, &autoProxyInfo); } if (ok && autoProxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY && autoProxyInfo.lpszProxy) { // Only the first proxy in the list will get a copy of the bypass list. std::string bypassList; if (autoProxyInfo.lpszProxyBypass) { std::wstring bypassW = autoProxyInfo.lpszProxyBypass; bypassList = string(bypassW.begin(), bypassW.end()); } std::wstring proxyListW = autoProxyInfo.lpszProxy; string proxyList = string(proxyListW.begin(), proxyListW.end()); ParseProxyList(proxyList, bypassList, proxies); } else if (ok && autoProxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NO_PROXY) { // The only case in which we do not continue to try using a proxy. // In this case the auto proxy setup told us to use a direct connection. shouldUseProxy = false; } else { // Auto proxy failed, so try another method string error = "Could not get proxy for url="; error.append(url); error.append(": "); error.append(ErrorCodeToString(GetLastError())); Logger::Get("Proxy")->Error(error); } // Always cleanup if (autoProxyInfo.lpszProxy) GlobalFree(autoProxyInfo.lpszProxy); if (autoProxyInfo.lpszProxyBypass) GlobalFree(autoProxyInfo.lpszProxyBypass); return shouldUseProxy; }
PassRefPtr<SpeechRecognitionError> SpeechRecognitionError::create(ErrorCode code, const String& message) { return adoptRef(new SpeechRecognitionError(ErrorCodeToString(code), message)); }
void VisaEmitter::EIO_Open(GenericBaton* data) { char temp[QUERY_STRING_SIZE]; ViStatus status = -1; if (this->isConnected) { _snprintf(temp, sizeof(temp), "Already connected %s", session); ErrorCodeToString(temp, status, data->errorString); return; } status = viOpenDefaultRM(&defaultRM); if (status < VI_SUCCESS) { _snprintf(temp, sizeof(temp), "Opening RM"); ErrorCodeToString(temp, status, data->errorString); return; } status = viOpen(defaultRM, data->command, VI_NULL, this->timeoutMiliSeconds, &session); if (status < VI_SUCCESS) { _snprintf(temp, sizeof(temp), "Opening session %s", data->command); ErrorCodeToString(temp, status, data->errorString); return; } status = viSetAttribute(session, VI_ATTR_TMO_VALUE, this->timeoutMiliSeconds); if (status < VI_SUCCESS) { _snprintf(temp, sizeof(temp), "Setting timeout to %d", this->timeoutMiliSeconds); ErrorCodeToString(temp, status, data->errorString); return; } this->isConnected = true; // status = viSetAttribute(instr, VI_ATTR_SEND_END_EN, VI_TRUE); // terminate reads on a carriage return 0x0a 0x0d // LF (Line feed, '\n', 0x0A, 10 in decimal) // Carriage return, '\r', 0x0D, 13 in decimal // status = viSetAttribute(session, VI_ATTR_TERMCHAR, 0x0A); //status = viSetAttribute(session, VI_ATTR_TERMCHAR_EN, VI_TRUE); if (this->assertREN) { viGpibControlREN(session, VI_GPIB_REN_ASSERT); } if (this->enableSRQ) { m_async = uv_async_t(); m_async.data = this; uv_async_init(uv_default_loop(), &m_async, reinterpret_cast<uv_async_cb>(aCallback)); isAsyncInitialized = true; status = viInstallHandler(session, VI_EVENT_SERVICE_REQ, callback, this->uniqueSRQhandlerIdentification); if (status >= VI_SUCCESS) { status = viEnableEvent(session, VI_EVENT_SERVICE_REQ, VI_HNDLR, VI_NULL); } if (status < VI_SUCCESS) { _snprintf(temp, sizeof(temp), "Post AfterOpenSuccess session %s", data->command); ErrorCodeToString(temp, status, data->errorString); return; } this->installedSRQHanlder = true; } _snprintf_s(data->result, _countof(data->result), _TRUNCATE, "%d", session); }
void EIO_Open(uv_work_t* req) { OpenBaton* data = static_cast<OpenBaton*>(req->data); char originalPath[1024]; strncpy_s(originalPath, sizeof(originalPath), data->path, _TRUNCATE); // data->path is char[1024] but on Windows it has the form "COMx\0" or "COMxx\0" // We want to prepend "\\\\.\\" to it before we call CreateFile strncpy(data->path + 20, data->path, 10); strncpy(data->path, "\\\\.\\", 4); strncpy(data->path + 4, data->path + 20, 10); int shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; if (data->lock) { shareMode = 0; } HANDLE file = CreateFile( data->path, GENERIC_READ | GENERIC_WRITE, shareMode, // dwShareMode 0 Prevents other processes from opening if they request delete, read, or write access NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, // allows for reading and writing at the same time and sets the handle for asynchronous I/O NULL ); if (file == INVALID_HANDLE_VALUE) { DWORD errorCode = GetLastError(); char temp[100]; _snprintf_s(temp, sizeof(temp), _TRUNCATE, "Opening %s", originalPath); ErrorCodeToString(temp, errorCode, data->errorString); return; } DCB dcb = { 0 }; SecureZeroMemory(&dcb, sizeof(DCB)); dcb.DCBlength = sizeof(DCB); if (!GetCommState(file, &dcb)) { ErrorCodeToString("Open (GetCommState)", GetLastError(), data->errorString); CloseHandle(file); return; } if (data->hupcl) { dcb.fDtrControl = DTR_CONTROL_ENABLE; } else { dcb.fDtrControl = DTR_CONTROL_DISABLE; // disable DTR to avoid reset } dcb.Parity = NOPARITY; dcb.ByteSize = 8; dcb.StopBits = ONESTOPBIT; dcb.fInX = FALSE; dcb.fOutX = FALSE; dcb.fOutxDsrFlow = FALSE; dcb.fOutxCtsFlow = FALSE; dcb.fRtsControl = RTS_CONTROL_ENABLE; dcb.fBinary = true; dcb.BaudRate = data->baudRate; dcb.ByteSize = data->dataBits; switch (data->parity) { case SERIALPORT_PARITY_NONE: dcb.Parity = NOPARITY; break; case SERIALPORT_PARITY_MARK: dcb.Parity = MARKPARITY; break; case SERIALPORT_PARITY_EVEN: dcb.Parity = EVENPARITY; break; case SERIALPORT_PARITY_ODD: dcb.Parity = ODDPARITY; break; case SERIALPORT_PARITY_SPACE: dcb.Parity = SPACEPARITY; break; } switch (data->stopBits) { case SERIALPORT_STOPBITS_ONE: dcb.StopBits = ONESTOPBIT; break; case SERIALPORT_STOPBITS_ONE_FIVE: dcb.StopBits = ONE5STOPBITS; break; case SERIALPORT_STOPBITS_TWO: dcb.StopBits = TWOSTOPBITS; break; } if (!SetCommState(file, &dcb)) { ErrorCodeToString("Open (SetCommState)", GetLastError(), data->errorString); CloseHandle(file); return; } // Clear all timeouts for read and write operations COMMTIMEOUTS commTimeouts = {0}; commTimeouts.ReadIntervalTimeout = 0; // Minimize chance of concatenating of separate serial port packets on read commTimeouts.ReadTotalTimeoutMultiplier = 0; // Do not allow big read timeout when big read buffer used commTimeouts.ReadTotalTimeoutConstant = 0; // Total read timeout (period of read loop) commTimeouts.WriteTotalTimeoutConstant = 0; // Const part of write timeout commTimeouts.WriteTotalTimeoutMultiplier = 0; // Variable part of write timeout (per byte) if (!SetCommTimeouts(file, &commTimeouts)) { ErrorCodeToString("Open (SetCommTimeouts)", GetLastError(), data->errorString); CloseHandle(file); return; } // Remove garbage data in RX/TX queues PurgeComm(file, PURGE_RXCLEAR); PurgeComm(file, PURGE_TXCLEAR); data->result = (int)file; }
void EIO_Open(uv_work_t* req) { OpenBaton* data = static_cast<OpenBaton*>(req->data); HANDLE file = CreateFile( data->path, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if (file == INVALID_HANDLE_VALUE) { char temp[100]; sprintf(temp, "Opening %s", data->path); ErrorCodeToString(temp, GetLastError(), data->errorString); return; } bufferSize = data->bufferSize; DCB dcb = { 0 }; dcb.DCBlength = sizeof(DCB); if(!BuildCommDCB("9600,n,8,1", &dcb)) { ErrorCodeToString("BuildCommDCB", GetLastError(), data->errorString); return; } dcb.fBinary = true; dcb.BaudRate = data->baudRate; dcb.ByteSize = data->dataBits; switch(data->parity) { case SERIALPORT_PARITY_NONE: dcb.Parity = NOPARITY; break; case SERIALPORT_PARITY_MARK: dcb.Parity = MARKPARITY; break; case SERIALPORT_PARITY_EVEN: dcb.Parity = EVENPARITY; break; case SERIALPORT_PARITY_ODD: dcb.Parity = ODDPARITY; break; case SERIALPORT_PARITY_SPACE: dcb.Parity = SPACEPARITY; break; } switch(data->stopBits) { case SERIALPORT_STOPBITS_ONE: dcb.StopBits = ONESTOPBIT; break; case SERIALPORT_STOPBITS_ONE_FIVE: dcb.StopBits = ONE5STOPBITS; break; case SERIALPORT_STOPBITS_TWO: dcb.StopBits = TWOSTOPBITS; break; } if(!SetCommState(file, &dcb)) { ErrorCodeToString("SetCommState", GetLastError(), data->errorString); return; } // set the com port to return immediatly after a read COMMTIMEOUTS commTimeouts = {0}; commTimeouts.ReadIntervalTimeout = MAXDWORD; commTimeouts.ReadTotalTimeoutMultiplier = MAXDWORD; commTimeouts.ReadTotalTimeoutConstant = 1000; commTimeouts.WriteTotalTimeoutConstant = 1000; commTimeouts.WriteTotalTimeoutMultiplier = 1000; if(!SetCommTimeouts(file, &commTimeouts)) { ErrorCodeToString("SetCommTimeouts", GetLastError(), data->errorString); return; } data->result = (int)file; }
void EIO_Open(uv_work_t* req) { OpenBaton* data = static_cast<OpenBaton*>(req->data); HANDLE file = CreateFile( data->path, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if (file == INVALID_HANDLE_VALUE) { DWORD errorCode = GetLastError(); char temp[100]; sprintf(temp, "Opening %s", data->path); ErrorCodeToString(temp, errorCode, data->errorString); return; } bufferSize = data->bufferSize; if(bufferSize > MAX_BUFFER_SIZE) { bufferSize = MAX_BUFFER_SIZE; } DCB dcb = { 0 }; dcb.DCBlength = sizeof(DCB); if(!BuildCommDCB("9600,n,8,1", &dcb)) { ErrorCodeToString("BuildCommDCB", GetLastError(), data->errorString); return; } dcb.fBinary = true; dcb.BaudRate = data->baudRate; dcb.ByteSize = data->dataBits; switch(data->parity) { case SERIALPORT_PARITY_NONE: dcb.Parity = NOPARITY; break; case SERIALPORT_PARITY_MARK: dcb.Parity = MARKPARITY; break; case SERIALPORT_PARITY_EVEN: dcb.Parity = EVENPARITY; break; case SERIALPORT_PARITY_ODD: dcb.Parity = ODDPARITY; break; case SERIALPORT_PARITY_SPACE: dcb.Parity = SPACEPARITY; break; } switch(data->stopBits) { case SERIALPORT_STOPBITS_ONE: dcb.StopBits = ONESTOPBIT; break; case SERIALPORT_STOPBITS_ONE_FIVE: dcb.StopBits = ONE5STOPBITS; break; case SERIALPORT_STOPBITS_TWO: dcb.StopBits = TWOSTOPBITS; break; } if(!SetCommState(file, &dcb)) { ErrorCodeToString("SetCommState", GetLastError(), data->errorString); return; } // Set the com port read/write timeouts DWORD serialBitsPerByte = 8/*std data bits*/ + 1/*start bit*/; serialBitsPerByte += (data->parity == SERIALPORT_PARITY_NONE ) ? 0 : 1; serialBitsPerByte += (data->stopBits == SERIALPORT_STOPBITS_ONE) ? 1 : 2; DWORD msPerByte = (data->baudRate > 0) ? ((1000 * serialBitsPerByte + data->baudRate - 1) / data->baudRate) : 1; if (msPerByte < 1) { msPerByte = 1; } COMMTIMEOUTS commTimeouts = {0}; commTimeouts.ReadIntervalTimeout = msPerByte; // Minimize chance of concatenating of separate serial port packets on read commTimeouts.ReadTotalTimeoutMultiplier = 0; // Do not allow big read timeout when big read buffer used commTimeouts.ReadTotalTimeoutConstant = 1000; // Total read timeout (period of read loop) commTimeouts.WriteTotalTimeoutConstant = 1000; // Const part of write timeout commTimeouts.WriteTotalTimeoutMultiplier = msPerByte; // Variable part of write timeout (per byte) if(!SetCommTimeouts(file, &commTimeouts)) { ErrorCodeToString("SetCommTimeouts", GetLastError(), data->errorString); return; } // Remove garbage data in RX/TX queues PurgeComm(file, PURGE_RXCLEAR); PurgeComm(file, PURGE_TXCLEAR); data->result = (int)file; }
SpeechRecognitionError* SpeechRecognitionError::create(ErrorCode code, const String& message) { return new SpeechRecognitionError(ErrorCodeToString(code), message); }
std::string JSONReader::GetErrorMessage() const { return FormatErrorMessage(error_line_, error_col_, ErrorCodeToString(error_code_)); }