bool Uart::readData() { unsigned long cmpt_read = 0; char buf[4096] = {0}; if ( !isDeviceOpen() ) return false; #ifdef WIN32 if (!ReadFile( _device, buf, 4096, &cmpt_read, NULL)) { int LastError = GetLastError() ; cerr<<"Error read file : "<<LastError<<endl; return false; } #endif #ifdef unix cmpt_read = read (*(int*)_device, buf, 4096); #endif if ( cmpt_read > 0) { if ( buf[cmpt_read-1] =='\n' && buf[cmpt_read-2] =='\n' ) { buf[cmpt_read-1] ='\0'; _bufferedData.append( buf ); return true; } else { _bufferedData.append( buf ); } } else { return false; } }
// Helper function, perform a sanity check on the device MythMediaError MythCDROMFreeBSD::testMedia() { bool OpenedHere = false; if (!isDeviceOpen()) { if (!openDevice()) { if (errno == EBUSY) { return isMounted() ? MEDIAERR_OK : MEDIAERR_FAILED; } else { return MEDIAERR_FAILED; } } OpenedHere = true; } // Be nice and close the device if we opened it, otherwise it might be locked when the user doesn't want it to be. if (OpenedHere) closeDevice(); return MEDIAERR_OK; }
// Helper function, perform a sanity check on the device MediaError MythCDROMFreeBSD::testMedia() { //cout << "MythCDROMLinux::testMedia - "; bool OpenedHere = false; if (!isDeviceOpen()) { //cout << "Device is not open - "; if (!openDevice()) { //cout << "failed to open device - "; if (errno == EBUSY) { //cout << "errno == EBUSY" << endl; return isMounted(true) ? MEDIAERR_OK : MEDIAERR_FAILED; } else { return MEDIAERR_FAILED; } } //cout << "Opened it - "; OpenedHere = true; } // Be nice and close the device if we opened it, otherwise it might be locked when the user doesn't want it to be. if (OpenedHere) closeDevice(); return MEDIAERR_OK; }
MythMediaError MythCDROMFreeBSD::eject(bool open_close) { if (!isDeviceOpen()) openDevice(); if (open_close) return (ioctl(m_DeviceHandle, CDIOCEJECT) == 0) ? MEDIAERR_OK : MEDIAERR_FAILED; else return MEDIAERR_UNSUPPORTED; }
void Uart::closeDevice() { if ( isDeviceOpen() ) { #ifdef WIN32 CloseHandle( (HANDLE)_device ); #endif #ifdef unix close( *(int*)_device ); #endif } }
MediaError MythCDROMFreeBSD::unlock() { if (isDeviceOpen() || openDevice()) { //cout << "Unlocking CDROM door" << endl; ioctl(m_DeviceHandle, CDIOCALLOW); } else { VERBOSE(VB_GENERAL, "Failed to open device, CDROM try will remain " "locked."); } return MythMediaDevice::unlock(); }
void Uart::send(string data) { string datas = data; datas+="\n"; if ( isDeviceOpen() ) { #ifdef WIN32 unsigned long cmpt_read; if (!WriteFile( _device, datas.c_str(), datas.size(), &cmpt_read, NULL)) { } #endif #ifdef unix write ( *((int*)(_device)) , datas.c_str(), datas.size()); #endif } }
MythMediaError MythCDROMFreeBSD::unlock() { if (isDeviceOpen() || openDevice()) { #if 0 LOG(VB_GENERAL, LOG_DEBUG, "Unlocking CDROM door"); #endif ioctl(m_DeviceHandle, CDIOCALLOW); } else { LOG(VB_GENERAL, LOG_INFO, "Failed to open device, CDROM tray will " "remain locked."); } return MythMediaDevice::unlock(); }