本文整理汇总了C++中CanRead函数的典型用法代码示例。如果您正苦于以下问题:C++ CanRead函数的具体用法?C++ CanRead怎么用?C++ CanRead使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CanRead函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetAttributeIndexToRead
void CGXDLMSAutoConnect::GetAttributeIndexToRead(std::vector<int>& attributes)
{
//LN is static and read only once.
if (CGXDLMSObject::IsLogicalNameEmpty(m_LN))
{
attributes.push_back(1);
}
//Mode
if (CanRead(2))
{
attributes.push_back(2);
}
//Repetitions
if (CanRead(3))
{
attributes.push_back(3);
}
//RepetitionDelay
if (CanRead(4))
{
attributes.push_back(4);
}
//CallingWindow
if (CanRead(5))
{
attributes.push_back(5);
}
//Destinations
if (CanRead(6))
{
attributes.push_back(6);
}
}
示例2: CanConfig
int CanConfig(unsigned char channel)
{
unsigned char temp;
CanReset(channel); // reset CAN controller
//------ Write Control Register (CR)
CanWrite(channel, CR, 0x01); // Enter Reset Mode without setting RIE
// and enter reset mode (Set Reset Request bit)
//------ Write Bus Timing Register 0 & 1 (BTR0 & BTR1)
// BTR can be accessed (read/write) if the reset mode is active
CanWrite(channel, BTR0, CAN[channel].btr0); // Write Bus Timing Register 0 (BTR0)
CanWrite(channel, BTR1, CAN[channel].btr1); // Write Bus Timing Register 1 (BTR1)
temp = CanRead(channel, BTR0);
if(temp != CAN[channel].btr0) // Read BTR0 and confirm it
return(ERR_CONFIG); // fail to configure
temp = CanRead(channel, BTR1);
if(temp != CAN[channel].btr1) // Read BTR1 and confirm it
return(ERR_CONFIG); // fail to configure
//------ Write Acceptance Code Register (ACR) and
// Acceptance Mask Register (AMR)
CanWrite(channel, ACR, CAN[channel].acc_code); // Write ACR
CanWrite(channel, AMR, CAN[channel].acc_mask); // Write AMR
//------ Write Output Control Register (OCR)
// Set Normal Output Mode & Push-pull dirver
CanWrite(channel, OCR, 0xfa);
return(ERR_OK); // successful
}
示例3: GetAttributeIndexToRead
void CGXDLMSActivityCalendar::GetAttributeIndexToRead(std::vector<int>& attributes)
{
//LN is static and read only once.
if (CGXDLMSObject::IsLogicalNameEmpty(m_LN))
{
attributes.push_back(1);
}
//CalendarNameActive
if (CanRead(2))
{
attributes.push_back(2);
}
//SeasonProfileActive
if (CanRead(3))
{
attributes.push_back(3);
}
//WeekProfileTableActive
if (CanRead(4))
{
attributes.push_back(4);
}
//DayProfileTableActive
if (CanRead(5))
{
attributes.push_back(5);
}
//CalendarNamePassive
if (CanRead(6))
{
attributes.push_back(6);
}
//SeasonProfilePassive
if (CanRead(7))
{
attributes.push_back(7);
}
//WeekProfileTablePassive
if (CanRead(8))
{
attributes.push_back(8);
}
//DayProfileTablePassive
if (CanRead(9))
{
attributes.push_back(9);
}
//Time.
if (CanRead(10))
{
attributes.push_back(10);
}
}
示例4: GetWBack
wxInputStream& wxInputStream::Read(void *buf, size_t size)
{
char *p = (char *)buf;
m_lastcount = 0;
size_t read = GetWBack(buf, size);
for ( ;; )
{
size -= read;
m_lastcount += read;
p += read;
if ( !size )
{
// we read the requested amount of data
break;
}
if ( p != buf && !CanRead() )
{
// we have already read something and we would block in OnSysRead()
// now: don't do it but return immediately
break;
}
read = OnSysRead(p, size);
if ( !read )
{
// no more data available
break;
}
}
return *this;
}
示例5: RETURN_ZERO_IF_FALSE
size_t BufferStream::ReadDataTo(MemoryData& outData, DataReadingMode mode/*=DataReadingMode::AlwaysCopy*/)const
{
RETURN_ZERO_IF_FALSE(CanRead());
FlushOnReadWrite(StreamDataOperation::Read);
size_t outPos = 0;
size_t outSize = outData.Size();
//read left buffer data
size_t bufferLeftLength = mBufferLength - mBuffer.Position();
if (bufferLeftLength != 0)
{
size_t readSize = Math::Min(bufferLeftLength, outSize);
MemoryData tempData = MemoryData::FromStatic(outData.MutableData() + outPos, readSize);
readSize = mBuffer.ReadDataTo(tempData, DataReadingMode::AlwaysCopy);
outPos += readSize;
outSize -= readSize;
}
//directly read to out data block per block
size_t blockSize = mBuffer.Length();
size_t blockCount = outSize / blockSize;
FOR_EACH_SIZE(i, blockCount)
{
MemoryData tempData = MemoryData::FromStatic(outData.MutableData() + outPos, blockSize);
size_t readSize = mSourceStream->ReadDataTo(tempData);
outPos += readSize;
outSize -= readSize;
if (readSize != blockSize) //last block
{
return outPos;
}
}
示例6: accept
bool EzSockets::accept(EzSockets& socket)
{
if (!blocking && !CanRead())
return false;
#if defined(HAVE_INET_NTOP)
char buf[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &addr.sin_addr, buf, INET_ADDRSTRLEN);
address = buf;
#elif defined(HAVE_INET_NTOA)
address = inet_ntoa(addr.sin_addr);
#endif
int length = sizeof(socket);
socket.sock = ::accept(sock,(struct sockaddr*) &socket.addr,
(socklen_t*) &length);
lastCode = socket.sock;
if (socket.sock <= 0)
return false;
socket.state = skCONNECTED;
return true;
}
示例7: RETURN_ZERO_IF_FALSE
size_t IStream::ReadToStream(size_t size, IStream& dest, size_t bufferSize/*=1024*/)const
{
RETURN_ZERO_IF_FALSE(CanRead() && dest.CanWrite());
if (dest.IsPtrAvailable())//could directly write
{
dest.ReserveLeftSize(size);
byte* buffer = dest.MutablePtr();
MemoryData destBuffer = MemoryData::FromStatic(buffer, size);
return ReadDataTo(destBuffer, DataReadingMode::AlwaysCopy);
}
else
{
//should use temp buffer
size_t count = 0;
size_t realBufferSize = Math::Min(LeftLength(), bufferSize, size);
MemoryData tempBuffer = MemoryData::Alloc(realBufferSize);
do
{
size_t readSize = Math::Min(size, realBufferSize);
tempBuffer.ForceSetSize(readSize);
readSize = ReadDataTo(tempBuffer, DataReadingMode::AlwaysCopy);
BREAK_IF_ZERO(readSize);
tempBuffer.ForceSetSize(readSize);
count += dest.WriteData(tempBuffer);
tempBuffer.ForceSetSize(realBufferSize);
size -= readSize;
} while (size > 0);
return count;
}
}
示例8: RecvUnknowLen
// 接收数据
int RecvUnknowLen(int SocketFd, void *ptr, size_t nbytes, int nSecond, int nMiniSec) {
ssize_t n = -1;
if (nbytes > 0)
{
while ((n = recv(SocketFd, (char *)ptr, nbytes, 0)) < 0)
{
if (EWOULDBLOCK == errno)
{
if (nSecond || nMiniSec)
{
if (CanRead(SocketFd, nSecond, nMiniSec) <= 0)
{
break;
}
nSecond = 0;//nMiniSec只等一次
nMiniSec = 0;
}
else
{
break;
}
}
else
{
//连接需要关闭
n = 0;
break;
}
}
}
return n;
}
示例9: GetAttributeIndexToRead
void CGXDLMSAutoAnswer::GetAttributeIndexToRead(std::vector<int>& attributes)
{
//LN is static and read only once.
if (CGXDLMSObject::IsLogicalNameEmpty(m_LN))
{
attributes.push_back(1);
}
//Mode is static and read only once.
if (!IsRead(2))
{
attributes.push_back(2);
}
//ListeningWindow is static and read only once.
if (!IsRead(3))
{
attributes.push_back(3);
}
//Status is not static.
if (CanRead(4))
{
attributes.push_back(4);
}
//NumberOfCalls is static and read only once.
if (!IsRead(5))
{
attributes.push_back(5);
}
//NumberOfRingsInListeningWindow is static and read only once.
if (!IsRead(6))
{
attributes.push_back(6);
}
}
示例10: CanSendMsg
// CAN 메세지를 보내는 함수
int CanSendMsg(unsigned char channel, unsigned short id, unsigned char *data, unsigned char dlc, unsigned char rtr)
{
unsigned char v, i;
//RtWprintf(L"\n>>> ID:%x Tx_Data:%x Tx_DLC:%x", id, data[0], dlc);
v = id >> 3;
CanWrite(channel, TXID1, v); // write Identifier (ID.10 .. ID.3)
v = id & 0x07; // write Identifier (ID.2 .. ID.0) to b7..b5
v <<= 5;
if(rtr==1) v |= 0x10; // check Remote Transmit Request (RTR) bit
v += dlc; // add Data Length Code (DLC)
CanWrite(channel, TXID2, v); // Write Identifier unsigned char 2
for(i=0; i<dlc; i++) CanWrite(channel, TXDATA+i, *(data+i)); // write Data unsigned char
// Write TR of Command Register (CMR)
CanWrite(channel, CMR, 0x01); // Set Transmission Request (TR): message will be transmitted
while(1)
{
v = CanRead(channel, SR); // Read Status Register (SR)
if(v & 0x40) // If Error Status(ES) bit is set
return(ERR_SEND); // fail to send
if(v & 0x08) // when Transmission Complete Status (TCS) bit is set
return(ERR_OK); // return (=successful)
}
}
示例11: Read
void CBPacket::Read(void* buf, long size)
{
if (size < 1 || !CanRead(size))
return ;
memcpy(buf, m_buf + m_ptr, size);
m_ptr += size;
}
示例12: ReadBool
// Read a boolean value
bool BufferedSocket::ReadBool(bool &val)
{
if (!CanRead(1))
{
wxLogDebug(_T("ReadBool: End of buffer reached!"));
val = false;
m_BadRead = true;
return false;
}
wxDataInputStream dis(*m_ReceiveBufferHandler);
dis.BigEndianOrdered(BigEndian);
wxInt8 Value = 0;
Value = dis.Read8();
if (Value < 0 || Value > 1)
{
wxLogDebug(_T("ReadBool: Value is not 0 or 1, possibly corrupted packet"));
val = false;
m_BadRead = true;
return false;
}
val = Value ? true : false;
return true;
}
示例13: CanReset
// CAN Reset 함수
void CanReset(unsigned char channel)
{
unsigned char temp;
temp = CanRead(channel, 0x0100);
CanWrite(channel, 0x0100, temp);
Sleep(100); // wait 100ms
}
示例14: sizeof
ezSockets * ezSockets::Accept()
{
if (!bBlocking && !CanRead())
return NULL;
sockaddr_in local_addr;
int length = sizeof(local_addr);
int localsock = ::accept(sock,(struct sockaddr*) &local_addr,
(socklen_t*) &length);
if ( localsock == SOCKET_ERROR )
return NULL;
ezSockets * sNew = new ezSockets;
#if !( defined (_WIN32) || defined( _XBOX ) )
char buf[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &local_addr.sin_addr, buf, INET_ADDRSTRLEN);
sNew->address = buf;
#else
sNew->address = inet_ntoa(local_addr.sin_addr);
#endif
lastCode = localsock;
sNew->bBlocking = bBlocking;
sNew->lastCode = 0;
sNew->mode = mode;
sNew->pDataInHead = NULL;
sNew->sock = localsock;
sNew->state = skCONNECTED;
return sNew;
}
示例15: Accept
bool ezSockets::Accept(ezSockets& socket)
{
if (!bBlocking && !CanRead())
return false;
int length = sizeof(socket);
socket.sock = ::accept(sock,(struct sockaddr*) &socket.addr,
(socklen_t*) &length);
#if !( defined (_WIN32) || defined( _XBOX ) )
char buf[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &socket.addr.sin_addr, buf, INET_ADDRSTRLEN);
address = buf;
#else
address = inet_ntoa(socket.addr.sin_addr);
#endif
lastCode = socket.sock;
if ( socket.sock == SOCKET_ERROR )
return false;
socket.state = skCONNECTED;
return true;
}