本文整理汇总了C++中serial::Serial::read方法的典型用法代码示例。如果您正苦于以下问题:C++ Serial::read方法的具体用法?C++ Serial::read怎么用?C++ Serial::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类serial::Serial
的用法示例。
在下文中一共展示了Serial::read方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: receive
void receive(){
if(!checkConnection()){
return;
}
// reads:
// 3 bytes:
// 1 byte to compare with START_BYTE
// 1 bytes into _msg->len
// 1 byte into _msg->type
// len+1 bytes:
// len bytes into _msg->data
// 1 byte to compare with _msg->checksum
size_t amount;
while((amount=port.available()) > 0){
if(_pos > 0){
amount = min((unsigned int)amount, _msg->length + 3 - _pos);
port.read(&(_msg->data[_pos]), amount);
_pos += amount;
if(_pos == _msg->length + 3 && port.available()){
uint8_t checksum;
port.read(&checksum, 1);
_msg->calcChecksum();
if(checksum == _msg->checksum){
parse(_msg);
}else{
ROS_WARN_THROTTLE(1, "Serial: Checksum mismatch: %u != %u", checksum, _msg->checksum);
}
resetMessage();
}
}else if(amount >= 3){
uint8_t b;
port.read(&b, 1);
if(b != START_BYTE){
ROS_WARN_THROTTLE(1, "Serial: Expected start byte, got this instead: %u", b);
return;
}
uint8_t d[2];
port.read(d, 2);
uint16_t len = d[0];
if(len > 0){
_msg = new Message(len - 1, d[1]); // TODO catch exception?
_pos = 3;
}
}
}
}
示例2: update_mavlink
void update_mavlink(void){
mavlink_message_t msg;
mavlink_status_t status;
if(ser.available()){
uint16_t num_bytes = ser.available();
uint8_t buffer[num_bytes];
ser.read(buffer, num_bytes);
for(uint16_t i = 0; i < num_bytes; i++){
if (mavlink_parse_char(MAVLINK_COMM_0, buffer[i], &msg, &status)) {
handleMessage(&msg, MAVLINK_COMM_0);
}
}
}
}
示例3: getBytes
// Get all bytes available
bool getBytes(char * buffer, int& buf_len) {
bool res = false;
//buf_len = 0;
try {
while (true) {
int res = 0;
size_t available = m_serial.available();
if (!available) {
break;
} else {
res = m_serial.read((uint8_t*)buffer + buf_len, available);
}
if (res <= 0) {
break;
}
buf_len += res;
m_last_read_time = Datapoint::get_current_time();
}
} catch (...) {
if (debug) {
std::cout << "exception thrown while wattsup reading" << std::endl;
}
close();
}
if (buf_len > 0) {
res = true;
}
return res;
}
示例4: if
void RSDPA10::run()
{
// ----------- PA10 Robot Main State Machine -----------
plc_status = PLCserial.read(s+500);
if (plc_status == "t")
{
set_rsd_info(INFO_TYPE_STATUS, INFO_ACTION_SET, STATUS_SAFETY_SYSTEM_TRIPPED);
set_rsd_info(INFO_TYPE_STATUS, INFO_ACTION_SET, STATUS_SAFETY_SYSTEM_BLINK);
plc_status = "";
}
if(get_rsd_info(INFO_TYPE_MES_COMMAND) & MES_COMMAND_WAIT)
{
set_rsd_info(INFO_TYPE_MES_COMMAND, INFO_ACTION_CLEAR, MES_COMMAND_WAIT);
if(mes_state == FREE)
rw::common::Log::log().info() << "In MES State: " << "FREE" << std::endl;
else if (mes_state == OUT_OF_BRICKS)
rw::common::Log::log().info() << "In MES State: " << "OUT_OF_BRICKS" << std::endl;
}
else if(get_rsd_info(INFO_TYPE_MES_COMMAND) & MES_COMMAND_SORTBRICKS)
{
set_rsd_info(INFO_TYPE_MES_COMMAND, INFO_ACTION_CLEAR, MES_COMMAND_SORTBRICKS);
rw::common::Log::log().info() << "In MES State: " << "SORTING" << std::endl;
mes_state = SORTING;
}
else if(get_rsd_info(INFO_TYPE_MES_COMMAND) & MES_COMMAND_LOADBRICKS)
{
set_rsd_info(INFO_TYPE_STATUS, INFO_ACTION_CLEAR, STATUS_ORDER_COMPLETE);
set_rsd_info(INFO_TYPE_MES_COMMAND, INFO_ACTION_CLEAR, MES_COMMAND_LOADBRICKS);
rw::common::Log::log().info() << "In MES State: " << "LOADING" << std::endl;
mes_state = LOADING;
}
else if(get_rsd_info(INFO_TYPE_MES_COMMAND) & MES_COMMAND_ABORT)
{
set_rsd_info(INFO_TYPE_MES_COMMAND, INFO_ACTION_CLEAR, MES_COMMAND_ABORT);
rw::common::Log::log().info() << "In MES State: " << "FREE" << std::endl;
mes_state = FREE;
}
if(get_rsd_info(INFO_TYPE_STATUS) & STATUS_ORDER_COMPLETE)
{
rw::common::Log::log().info() << "In MES State: " << "ORDER_SORTED" << std::endl;
mes_state = ORDER_SORTED;
}
else if(get_rsd_info(INFO_TYPE_STATUS) & STATUS_OUT_OF_BRICKS)
{
set_rsd_info(INFO_TYPE_STATUS, INFO_ACTION_CLEAR, STATUS_OUT_OF_BRICKS);
rw::common::Log::log().info() << "In MES State: " << "OUT_OF_BRICKS" << std::endl;
mes_state = OUT_OF_BRICKS;
}
if (get_rsd_info(INFO_TYPE_STATUS) & STATUS_RESETJOINTS)
{
set_rsd_info(INFO_TYPE_STATUS, INFO_ACTION_CLEAR, STATUS_RESETJOINTS);
linearPath.clear();
rw::common::Log::log().info() << "In State: " << "RESET" << std::endl;
mes_state = SORTING;
control_state = RESET;
}
switch(mes_state)
{
case INIT_ROS:
rw::common::Log::log().info() << "In MES State: " << "ROS_INIT" << std::endl;
_ROS->start();
mes_state = FREE;
break;
case FREE:
set_rsd_info(INFO_TYPE_MES_STATE, INFO_ACTION_CLEAR, MES_STATE_LOADING);
set_rsd_info(INFO_TYPE_MES_STATE, INFO_ACTION_CLEAR, MES_STATE_ERROR);
set_rsd_info(INFO_TYPE_MES_STATE, INFO_ACTION_CLEAR, MES_STATE_OUTOFBRICKS);
set_rsd_info(INFO_TYPE_MES_STATE, INFO_ACTION_CLEAR, MES_STATE_SORTING);
set_rsd_info(INFO_TYPE_MES_STATE, INFO_ACTION_CLEAR, MES_STATE_ORDERSORTED);
set_rsd_info(INFO_TYPE_STATUS, INFO_ACTION_CLEAR, STATUS_ORDER_COMPLETE);
set_rsd_info(INFO_TYPE_MES_STATE, INFO_ACTION_SET, MES_STATE_FREE);
break;
case SORTING:
set_rsd_info(INFO_TYPE_MES_STATE, INFO_ACTION_CLEAR, MES_STATE_FREE);
set_rsd_info(INFO_TYPE_MES_STATE, INFO_ACTION_SET, MES_STATE_SORTING);
if(!orderQueue.empty() && !workingOnOrder)
{
currentOrder = orderQueue.front();
nrOfBricksInOrder = currentOrder.get_blueBricks() + currentOrder.get_redBricks() + currentOrder.get_yellowBricks();
workingOnOrder = true;
startBatchTime = ros::Time::now().toSec();
LINFO << "Working on Order: " << currentOrder.get_orderID();
}
switch (control_state)
{
case INIT:
{
if (linearPath.empty())
{
rw::common::Log::log().info() << "In State: " << "INIT" << std::endl;
Q gripperInitOpenQ(1, 0.020);
sendQtoGripper(gripperInitOpenQ);
//.........这里部分代码省略.........