本文整理汇总了C++中serialRead函数的典型用法代码示例。如果您正苦于以下问题:C++ serialRead函数的具体用法?C++ serialRead怎么用?C++ serialRead使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了serialRead函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: stm32CmdGet
int stm32CmdGet()
{
int ret = STM_ERR;
if ( sendCommand(0x00)==STM_OK ) {
int i;
unsigned char num;
serialRead(board.serial_fd, &num, 1); // number of bytes
serialRead(board.serial_fd, &board.version, 1);
serialRead(board.serial_fd, board.cmd, num);
if ( waitAck()==STM_OK ) {
printf("Bootloader version: %x.%x\nCommand set-[", board.version >> 4, board.version & 0x0F);
for ( i=0; i < num; i++ )
printf(" %02X", board.cmd[i]);
printf("]\n");
ret = STM_OK;
}
开发者ID:sunjiawe,项目名称:stm32isp,代码行数:19,代码来源:stm32.c
示例2: serialCom
void serialCom(void)
{
uint8_t c;
int i;
for (i = 0; i < numTelemetryPorts; i++) {
currentPortState = &ports[i];
// in cli mode, all serial stuff goes to here. enter cli mode by sending #
if (cliMode) {
cliProcess();
return;
}
if (pendReboot)
systemReset(false); // noreturn
while (serialTotalBytesWaiting(currentPortState->port)) {
c = serialRead(currentPortState->port);
if (currentPortState->c_state == IDLE) {
currentPortState->c_state = (c == '$') ? HEADER_START : IDLE;
if (currentPortState->c_state == IDLE && !f.ARMED)
evaluateOtherData(c); // if not armed evaluate all other incoming serial data
} else if (currentPortState->c_state == HEADER_START) {
currentPortState->c_state = (c == 'M') ? HEADER_M : IDLE;
} else if (currentPortState->c_state == HEADER_M) {
currentPortState->c_state = (c == '<') ? HEADER_ARROW : IDLE;
} else if (currentPortState->c_state == HEADER_ARROW) {
if (c > INBUF_SIZE) { // now we are expecting the payload size
currentPortState->c_state = IDLE;
continue;
}
currentPortState->dataSize = c;
currentPortState->offset = 0;
currentPortState->checksum = 0;
currentPortState->indRX = 0;
currentPortState->checksum ^= c;
currentPortState->c_state = HEADER_SIZE; // the command is to follow
} else if (currentPortState->c_state == HEADER_SIZE) {
currentPortState->cmdMSP = c;
currentPortState->checksum ^= c;
currentPortState->c_state = HEADER_CMD;
} else if (currentPortState->c_state == HEADER_CMD && currentPortState->offset < currentPortState->dataSize) {
currentPortState->checksum ^= c;
currentPortState->inBuf[currentPortState->offset++] = c;
} else if (currentPortState->c_state == HEADER_CMD && currentPortState->offset >= currentPortState->dataSize) {
if (currentPortState->checksum == c) { // compare calculated and transferred checksum
evaluateCommand(); // we got a valid packet, evaluate it
}
currentPortState->c_state = IDLE;
}
}
}
}
开发者ID:fiendie,项目名称:baseflight,代码行数:55,代码来源:serial.c
示例3: serialRead
//Get power of a specific channel
unsigned short Parallax::getPower(unsigned char channel) {
if(channel > PARALLAX_NUM_MOTORS) {
Log::logf(Log::WARN, "Invalid PWM channel!\n");
return 0;
}
unsigned char command[8] = {'!', 'S', 'C', 'R', 'S', 'P', channel, '\r'};
//3 preamble bytes, 3 command bytes, channel byte, command terminator
if(serialWrite(&command, sizeof(command)) != sizeof(command)) {
Log::logf(Log::ERR, "Error writing to Parallax servo controller!\n");
}
serialRead(&command, sizeof(command)); //Remove remote echo from input buffer, ignore any errors
unsigned char data[3] = {0};
if(serialRead(&data, sizeof(data)) == sizeof(data)) {
return (data[1] << 8) | data[2];
} else {
return 0;
}
}
开发者ID:Techwolfy,项目名称:telepresence,代码行数:21,代码来源:parallax.cpp
示例4: while
//!Wait the response of the module
void WaspRFID::waitResponse(void)
{
int val = 0xFF;
long cont = 0;
while((val != PREAMBLE) && (cont < timeOut)) {
val = serialRead(_uart);
delay(5);
cont ++;
}
}
开发者ID:ferrangb,项目名称:waspmoteapi,代码行数:12,代码来源:WaspRFID13.cpp
示例5: gpsSetPassthrough
int8_t gpsSetPassthrough(void)
{
if (gpsData.state != GPS_RECEIVINGDATA)
return -1;
LED0_OFF;
LED1_OFF;
while(1) {
if (serialTotalBytesWaiting(core.gpsport)) {
LED0_ON;
serialWrite(core.mainport, serialRead(core.gpsport));
LED0_OFF;
}
if (serialTotalBytesWaiting(core.mainport)) {
LED1_ON;
serialWrite(core.gpsport, serialRead(core.mainport));
LED1_OFF;
}
}
}
开发者ID:carballada,项目名称:baseflight,代码行数:21,代码来源:gps.c
示例6: initlbuf
void initlbuf(void) {
lbufptr = lbuf;
#if defined(SERIAL_OVERRIDE) && 0
// don't do the prompt in serialIsOverridden mode
if (serialIsOverridden()) return;
#endif
prompt();
// flush any pending serial input
while (serialAvailable()) serialRead();
}
开发者ID:realthunder,项目名称:bitlash,代码行数:13,代码来源:bitlash-cmdline.c
示例7: serialPassthrough
/*
A high-level serial passthrough implementation. Used by cli to start an
arbitrary serial passthrough "proxy". Optional callbacks can be given to allow
for specialized data processing.
*/
void serialPassthrough(serialPort_t *left, serialPort_t *right, serialConsumer
*leftC, serialConsumer *rightC)
{
waitForSerialPortToFinishTransmitting(left);
waitForSerialPortToFinishTransmitting(right);
if (!leftC)
leftC = &nopConsumer;
if (!rightC)
rightC = &nopConsumer;
LED0_OFF;
LED1_OFF;
// Either port might be open in a mode other than MODE_RXTX. We rely on
// serialRxBytesWaiting() to do the right thing for a TX only port. No
// special handling is necessary OR performed.
while(1) {
// TODO: maintain a timestamp of last data received. Use this to
// implement a guard interval and check for `+++` as an escape sequence
// to return to CLI command mode.
// https://en.wikipedia.org/wiki/Escape_sequence#Modem_control
if (serialRxBytesWaiting(left)) {
LED0_ON;
uint8_t c = serialRead(left);
serialWrite(right, c);
leftC(c);
LED0_OFF;
}
if (serialRxBytesWaiting(right)) {
LED0_ON;
uint8_t c = serialRead(right);
serialWrite(left, c);
rightC(c);
LED0_OFF;
}
}
}
开发者ID:mmiers,项目名称:betaflight,代码行数:43,代码来源:serial.c
示例8: gpsEnablePassthrough
void gpsEnablePassthrough(serialPort_t *gpsPassthroughPort)
{
waitForSerialPortToFinishTransmitting(gpsPort);
waitForSerialPortToFinishTransmitting(gpsPassthroughPort);
if(!(gpsPort->mode & MODE_TX))
serialSetMode(gpsPort, gpsPort->mode | MODE_TX);
LED0_OFF;
LED1_OFF;
#ifdef DISPLAY
if (feature(FEATURE_DISPLAY)) {
displayShowFixedPage(PAGE_GPS);
}
#endif
char c;
while(1) {
if (serialRxBytesWaiting(gpsPort)) {
LED0_ON;
c = serialRead(gpsPort);
gpsNewData(c);
serialWrite(gpsPassthroughPort, c);
LED0_OFF;
}
if (serialRxBytesWaiting(gpsPassthroughPort)) {
LED1_ON;
c = serialRead(gpsPassthroughPort);
serialWrite(gpsPort, c);
LED1_OFF;
}
#ifdef DISPLAY
if (feature(FEATURE_DISPLAY)) {
updateDisplay();
}
#endif
}
}
开发者ID:180jacob,项目名称:cleanflight,代码行数:38,代码来源:gps.c
示例9: serialFlush
/* getCellInfo() - gets the information from the cell where the module is connected
*
* This function gets the information from the cell where the module is connected
*
* It stores in 'RSSI' and 'cellID' variables the information from the cell
*
* It modifies 'flag' if expected answer is not received after sending a command to GPRS module
*
* Returns '1' on success and '0' if error
*/
uint8_t WaspGPRS::getCellInfo()
{
char command[30];
uint8_t byteIN[200];
long previous=millis();
uint8_t counter=0;
uint8_t a,b,c=0;
serialFlush(PORT_USED);
sprintf(command,"AT%s\r\n",AT_GPRS_CELLID);
printString(command,PORT_USED);
while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<3000) );
previous=millis();
a=0;
while( (millis()-previous) < 2000 )
{
while( serialAvailable(PORT_USED) && (millis()-previous) < 2000 && (a<200) )
{
byteIN[a]=serialRead(PORT_USED);
a++;
}
}
a=0;
while( counter < 5 )
{
while( (byteIN[a]!=',') && (a<200) )
{
a++;
}
a++;
counter++;
}
if(a>=200) return 0;
counter=0;
while( (byteIN[a]!=',') && (a<200) )
{
cellID[c]=byteIN[a];
a++;
c++;
}
a++;
while( (byteIN[a]!=',') && (a<200) )
{
RSSI[b]=byteIN[a];
delay(10);
b++;
a++;
}
return 1;
}
开发者ID:ipadron,项目名称:waspmote-api,代码行数:60,代码来源:WaspGPRS.cpp
示例10: serialWrite
uint16_t Arduino::command(uint8_t nid, uint8_t cmd, uint8_t pin, uint8_t val) {
// Send.
// printf("Sending command\n");
serialWrite(MESSAGE_HEADER);
serialWrite(nid);
serialWrite(cmd);
serialWrite(pin);
serialWrite(val);
usleep(100); // let it time to reply
// Receive.
char rd = serialRead();
if (rd != MESSAGE_HEADER) {
printf("Error: wrong message header received from node %d: '%c'\n", nid, rd);
exit(-1);
}
uint8_t h = serialRead();
uint8_t l = serialRead();
// Return received value.
return (uint16_t) ( (h << 8) | l );
}
开发者ID:malloch,项目名称:qualia,代码行数:23,代码来源:SimpleFirmware.cpp
示例11: hottCheckSerialData
static void hottCheckSerialData(uint32_t currentMicros)
{
static bool lookingForRequest = true;
uint8_t bytesWaiting = serialTotalBytesWaiting(hottPort);
if (bytesWaiting <= 1) {
return;
}
if (bytesWaiting != 2) {
flushHottRxBuffer();
lookingForRequest = true;
return;
}
if (lookingForRequest) {
lastHoTTRequestCheckAt = currentMicros;
lookingForRequest = false;
return;
} else {
bool enoughTimePassed = currentMicros - lastHoTTRequestCheckAt >= HOTT_RX_SCHEDULE;
if (!enoughTimePassed) {
return;
}
lookingForRequest = true;
}
uint8_t requestId = serialRead(hottPort);
uint8_t address = serialRead(hottPort);
if ((requestId == 0) || (requestId == HOTT_BINARY_MODE_REQUEST_ID) || (address == HOTT_TELEMETRY_NO_SENSOR_ID)) {
processBinaryModeRequest(address);
}
}
开发者ID:Hwurzburg,项目名称:cleanflight,代码行数:36,代码来源:hott.c
示例12: beginLed
/**
* Send a file over the serial port.
* @param file file to send
*/
int Xmodem::send(File* file) {
_file = file;
_packetNumber = 1;
beginLed();
while (true) {
int c = serialRead();
if (c != -1) {
resetTimer();
break;
}
delay(100);
}
int status = 0;
while (true) {
size_t bytesRead = readPacket();
resetTimer();
if (bytesRead > 0) {
status = sendPacket();
if (_packetNumber % 20 == 0) {
toggleLed();
}
if (status < 0) {
break;
}
}
if (bytesRead < PACKET_SIZE) {
break;
}
}
serialWrite(EOT);
while (serialRead() == -1);
endLed();
return status;
}
开发者ID:mgk,项目名称:reaper,代码行数:40,代码来源:Xmodem.cpp
示例13: sp_process
void sp_process()
{
char c;
while((c = serialRead()) != -1)
{
if((char_counter > 0) && ((c == '\n') || (c == '\r'))) { // Line is complete. Then execute!
line[char_counter] = 0; // treminate string
status_message(gc_execute_line(line));
char_counter = 0; // reset line buffer index
} else if (c <= ' ') { // Throw away whitepace and control characters
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
line[char_counter++] = c-'a'+'A';
} else {
line[char_counter++] = c;
}
}
}
开发者ID:neimar2009,项目名称:grbl,代码行数:17,代码来源:serial_protocol.c
示例14: gpsReceiveData
static bool gpsReceiveData(void)
{
bool hasNewData = false;
if (gpsState.gpsPort) {
while (serialRxBytesWaiting(gpsState.gpsPort)) {
uint8_t newChar = serialRead(gpsState.gpsPort);
if (gpsNewFrameNMEA(newChar)) {
gpsSol.flags.gpsHeartbeat = !gpsSol.flags.gpsHeartbeat;
gpsSol.flags.validVelNE = 0;
gpsSol.flags.validVelD = 0;
hasNewData = true;
}
}
}
return hasNewData;
}
开发者ID:iforce2d,项目名称:cleanflight,代码行数:18,代码来源:gps_nmea.c
示例15: gpsThread
void gpsThread(void)
{
// read out available GPS bytes
if (gpsPort) {
while (serialRxBytesWaiting(gpsPort))
gpsNewData(serialRead(gpsPort));
}
switch (gpsData.state) {
case GPS_UNKNOWN:
break;
case GPS_INITIALIZING:
case GPS_CHANGE_BAUD:
case GPS_CONFIGURE:
gpsInitHardware();
break;
case GPS_LOST_COMMUNICATION:
gpsData.timeouts++;
if (gpsConfig()->autoBaud) {
// try another rate
gpsData.baudrateIndex++;
gpsData.baudrateIndex %= GPS_INIT_ENTRIES;
}
gpsData.lastMessage = millis();
// TODO - move some / all of these into gpsData
GPS_numSat = 0;
DISABLE_STATE(GPS_FIX);
gpsSetState(GPS_INITIALIZING);
break;
case GPS_RECEIVING_DATA:
// check for no data/gps timeout/cable disconnection etc
if (millis() - gpsData.lastMessage > GPS_TIMEOUT) {
// remove GPS from capability
sensorsClear(SENSOR_GPS);
gpsSetState(GPS_LOST_COMMUNICATION);
}
break;
}
}
开发者ID:180jacob,项目名称:cleanflight,代码行数:42,代码来源:gps.c
示例16: getPower
//Get power of a specific channel
unsigned short Pololu::getPower(unsigned char channel) {
if(channel > POLOLU_NUM_MOTORS) {
Log::logf(Log::WARN, "Invalid PWM channel!\n");
return 0;
}
unsigned char command[2] = {0x90, channel};
//Command byte, channel byte
if(serialWrite(&command, sizeof(command)) != sizeof(command)) {
Log::logf(Log::ERR, "Error writing to Pololu Maestro servo controller!\n");
}
unsigned char data[2] = {0};
if(serialRead(&data, sizeof(data)) == sizeof(data)) {
return (data[0] << 8) | data[1];
} else {
Log::logf(Log::ERR, "Error reading from Pololu Maestro servo controller!\n");
return 0;
}
}
开发者ID:Techwolfy,项目名称:telepresence,代码行数:21,代码来源:pololu.cpp
示例17: loop
void loop(){
seq.rotation.update(getAnalogValue(SEQUENCER_ROTATE_CONTROL));
seq.step.update(getAnalogValue(SEQUENCER_STEP_CONTROL));
seq.fill.update(getAnalogValue(SEQUENCER_FILL_CONTROL));
seq.update();
#ifdef SERIAL_DEBUG
if(serialAvailable() > 0){
serialRead();
printString("a: [");
seq.dump();
printString("] ");
seq.print();
if(clockIsHigh())
printString(" clock high");
if(resetIsHigh())
printString(" reset high");
printNewline();
}
#endif
}
开发者ID:madwort,项目名称:EuclideanSequencer,代码行数:21,代码来源:VoltageControlledEuclideanSequencer.cpp
示例18: handleIbusTelemetry
void handleIbusTelemetry(void)
{
if (!ibusTelemetryEnabled) {
return;
}
while (serialRxBytesWaiting(ibusSerialPort) > 0) {
uint8_t c = serialRead(ibusSerialPort);
if (outboundBytesToIgnoreOnRxCount) {
outboundBytesToIgnoreOnRxCount--;
continue;
}
pushOntoTail(ibusReceiveBuffer, IBUS_RX_BUF_LEN, c);
if (isChecksumOkIa6b(ibusReceiveBuffer, IBUS_RX_BUF_LEN)) {
outboundBytesToIgnoreOnRxCount += respondToIbusRequest(ibusReceiveBuffer);
}
}
}
开发者ID:4712betaflight,项目名称:betaflight,代码行数:21,代码来源:ibus.c
示例19: stm32Sync
int stm32Sync()
{
int ret = STM_ERR;
static unsigned char STM32_INIT = 0x7F;
unsigned char r;
int rr;
int i;
printf("Sync");
fflush(stdout);
for ( i=0; i<MAXTRY; i++ ) {
printf(".");
fflush(stdout);
rr = serialWrite(board.serial_fd, &STM32_INIT, 1);
if ( rr == SER_OK ) {
serialFlush(board.serial_fd);
rr = serialRead(board.serial_fd, &r, sizeof(r));
if ( rr == SER_OK ) {
if ( r==STM32_ACK || r==STM32_NACK) {
ret = STM_OK;
break;
}
}
}
}
printf("\n");
if ( ret == STM_OK ) {
printf("Connected to board.\n");
} else {
printf("Can not connect to board, ");
if ( rr == SER_ERR ) {
printf(" failed.\n");
} else {
printf(" timed-out.\n");
}
}
return ret;
}
开发者ID:sunjiawe,项目名称:stm32isp,代码行数:40,代码来源:stm32.c
示例20: gpsThread
void gpsThread(void)
{
// read out available GPS bytes
if (core.gpsport) {
while (serialTotalBytesWaiting(core.gpsport))
gpsNewData(serialRead(core.gpsport));
}
switch (gpsData.state) {
case GPS_UNKNOWN:
break;
case GPS_INITIALIZING:
case GPS_INITDONE:
gpsInitHardware();
break;
case GPS_LOSTCOMMS:
gpsData.errors++;
// try another rate
gpsData.baudrateIndex++;
gpsData.baudrateIndex %= GPS_INIT_ENTRIES;
gpsData.lastMessage = millis();
// TODO - move some / all of these into gpsData
GPS_numSat = 0;
f.GPS_FIX = 0;
gpsSetState(GPS_INITIALIZING);
break;
case GPS_RECEIVINGDATA:
// check for no data/gps timeout/cable disconnection etc
if (millis() - gpsData.lastMessage > GPS_TIMEOUT) {
// remove GPS from capability
sensorsClear(SENSOR_GPS);
gpsSetState(GPS_LOSTCOMMS);
}
break;
}
}
开发者ID:carballada,项目名称:baseflight,代码行数:39,代码来源:gps.c
注:本文中的serialRead函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论