本文整理汇总了C++中serialWrite函数的典型用法代码示例。如果您正苦于以下问题:C++ serialWrite函数的具体用法?C++ serialWrite怎么用?C++ serialWrite使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了serialWrite函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: gpsEnablePassthrough
gpsEnablePassthroughResult_e gpsEnablePassthrough(void)
{
if (gpsData.state != GPS_RECEIVING_DATA)
return GPS_PASSTHROUGH_NO_GPS;
serialPort_t *gpsPassthroughPort = findOpenSerialPort(FUNCTION_GPS_PASSTHROUGH);
if (gpsPassthroughPort) {
waitForSerialPortToFinishTransmitting(gpsPassthroughPort);
serialSetBaudRate(gpsPassthroughPort, serialConfig->gps_passthrough_baudrate);
} else {
gpsPassthroughPort = openSerialPort(FUNCTION_GPS_PASSTHROUGH, NULL, serialConfig->gps_passthrough_baudrate, MODE_RXTX, SERIAL_NOT_INVERTED);
if (!gpsPassthroughPort) {
return GPS_PASSTHROUGH_NO_SERIAL_PORT;
}
}
LED0_OFF;
LED1_OFF;
while(1) {
if (serialTotalBytesWaiting(gpsPort)) {
LED0_ON;
serialWrite(gpsPassthroughPort, serialRead(gpsPort));
LED0_OFF;
}
if (serialTotalBytesWaiting(gpsPassthroughPort)) {
LED1_ON;
serialWrite(gpsPort, serialRead(gpsPassthroughPort));
LED1_OFF;
}
}
return GPS_PASSTHROUGH_ENABLED;
}
开发者ID:ChrisNisbet01,项目名称:cleanflight,代码行数:34,代码来源:gps.c
示例2: run_command
int run_command(int fd, uint8_t *data, uint8_t len)
{
uint8_t inbuf[2];
uint8_t sum = 0;
uint8_t *sump = data;
uint8_t i = len;
uint8_t packet_len = len+2;
while(i--)
sum += *sump++;
if (1 != serialWrite(fd, &packet_len, 1))
return 1;
if (1 != serialWrite(fd, &sum, 1))
return 1;
if (len != serialWrite(fd, data, len))
return 1;
if (2 != serialRead(fd, inbuf, 2))
return 1;
if (0x00 != inbuf[0] || 0xCC != inbuf[1])
{
fprintf(stderr, "NAK\n");
return 1;
}
return 0;
}
开发者ID:1248,项目名称:cc2538-prog,代码行数:26,代码来源:cc2538-prog.c
示例3: ltm_initialise_packet
static void ltm_initialise_packet(uint8_t ltm_id)
{
ltm_crc = 0;
serialWrite(ltmPort, '$');
serialWrite(ltmPort, 'T');
serialWrite(ltmPort, ltm_id);
}
开发者ID:Liquidas,项目名称:betaflight,代码行数:7,代码来源:ltm.c
示例4: gpsEnablePassthrough
void gpsEnablePassthrough(serialPort_t *gpsPassthroughPort)
{
waitForSerialPortToFinishTransmitting(gpsState.gpsPort);
waitForSerialPortToFinishTransmitting(gpsPassthroughPort);
if(!(gpsState.gpsPort->mode & MODE_TX))
serialSetMode(gpsState.gpsPort, gpsState.gpsPort->mode | MODE_TX);
LED0_OFF;
LED1_OFF;
char c;
while(1) {
if (serialRxBytesWaiting(gpsState.gpsPort)) {
LED0_ON;
c = serialRead(gpsState.gpsPort);
serialWrite(gpsPassthroughPort, c);
LED0_OFF;
}
if (serialRxBytesWaiting(gpsPassthroughPort)) {
LED1_ON;
c = serialRead(gpsPassthroughPort);
serialWrite(gpsState.gpsPort, c);
LED1_OFF;
}
}
}
开发者ID:iforce2d,项目名称:cleanflight,代码行数:27,代码来源:gps.c
示例5: stmWriteCommand
void stmWriteCommand(serialStruct_t *s, char *msb, char *lsb, char *len, char *data) {
char startAddress[9];
char lenPlusData[128];
char c;
strncpy(startAddress, msb, sizeof(startAddress));
strcat(startAddress, lsb);
sprintf(lenPlusData, "%02x%s", stmHexToChar(len) - 1, data);
write:
// send WRITE MEMORY command
do {
c = getResults[5];
serialWrite(s, &c, 1);
c = 0xff ^ c;
serialWrite(s, &c, 1);
} while (!stmWaitAck(s, STM_RETRIES_LONG));
// send address
if (!stmWrite(s, startAddress)) {
putchar('A');
goto write;
}
// send len + data
if (!stmWrite(s, lenPlusData)) {
putchar('D');
goto write;
}
putchar('='); fflush(stdout);
}
开发者ID:DarkVegetableMatter,项目名称:naze32,代码行数:33,代码来源:stmbootloader.c
示例6: serialWrite
int DLS::setOutputFilter (int nsamples, int nspikes, int nerrors)
{
// Request Current Config
char write_data[] = "s0fi\r\n";
serialWrite(write_data, sizeof(write_data)/sizeof(write_data[0]));
// Read Current Config
char read_data[] = "g0fi+aa+bb+cc\r\n";
serialRead(read_data);
//
// Check for error indicator (@) and parse error value.
if (read_data[2]=='@') {
char errcode_str [] = "000";
sprintf (errcode_str, "%*s", 3, read_data+4);
return(-1 * atoi (errcode_str));
}
char aa_str [] = "aa";
aa_str[0] = read_data [5];
aa_str[1] = read_data [6];
char bb_str [] = "bb";
bb_str[0] = read_data [8];
bb_str[1] = read_data [9];
char cc_str [] = "cc";
cc_str[0] = read_data [11];
cc_str[1] = read_data [12];
if ((nsamples < 0) || (nsamples > 32))
nsamples = atoi (aa_str);
if (nspikes < 0)
nspikes = atoi (bb_str);
if (nerrors < 0)
nerrors = atoi (cc_str);
debug_print("samples %i\n", nsamples);
debug_print("spikes %i\n", nspikes);
debug_print("errors %i\n", nerrors);
if (2*nspikes+nerrors > 0.4 * nsamples) {
fprintf(stderr, "ERROR: Make sure that (2*nspikes + nerrors) <= nsamples\n");
nspikes = atoi (bb_str);
nerrors = atoi (cc_str);
nsamples = atoi (aa_str);
}
char write_data2[] = "s0fi+aa+bb+cc\r\n";
sprintf(write_data2, "s0fi+%02i+%02i+%02i\r\n",nsamples,nspikes,nerrors);
serialWrite(write_data2, sizeof(write_data2)/sizeof(write_data[0]));
int status = rxData();
if (status < 0)
printErrorMsg(status);
return(status);
}
开发者ID:andrewpeck,项目名称:dimetix-lasersensor,代码行数:56,代码来源:libdls.cpp
示例7: main
int main(int argc, char *argv[]) {
SerialPort SP;
char buf[1025];
int nr;
if (argc<1) {
printf("Usage: setupbluesmirf <device>\n");
printf(" <device> must be your serial port, e.g, COM3: on Windows, or /dev/ttyS0 on Linux\n");
return 0;
}
if (!serialOpenByName(&SP, argv[1])) {
fprintf(stderr, "Could not open serial port %s\n", argv[1]);
return 1;
}
// last parameter is timeout in 1/10 of a second
if (!serialSetParameters(&SP, 57600, 8, 0, 1, 1)) {
fprintf(stderr, "Could not modify serial port parameters\n");
return 1;
}
nr = serialRead(&SP, 1024, buf);
serialWrite(&SP, 3, "$$$");
nr = serialRead(&SP, 1024, buf);
if (nr > 0) {
buf[nr]=0;
printf("Received after $$$: %s", buf);
} else {
goto cleanup;
}
serialWrite(&SP, 2, "D\r");
nr = serialRead(&SP, 1024, buf);
if (nr > 0) {
buf[nr]=0;
printf("Received after D<cr>: %s", buf);
} else {
goto cleanup;
}
serialWrite(&SP, 9, "U,576K,N\r");
nr = serialRead(&SP, 1024, buf);
if (nr > 0) {
buf[nr]=0;
printf("Received after U,576K,N<cr>: %s", buf);
} else {
goto cleanup;
}
cleanup:
serialClose(&SP);
return 0;
}
开发者ID:KoraST,项目名称:ft_BIU-1,代码行数:56,代码来源:setupbluesmirf.c
示例8: serialize16
void serialize16(int16_t a)
{
static uint8_t t;
t = a;
serialWrite(core.mainport, t);
checksum ^= t;
t = a >> 8 & 0xff;
serialWrite(core.mainport, t);
checksum ^= t;
}
开发者ID:jef79m,项目名称:baseflight,代码行数:10,代码来源:serial.c
示例9: get16bitValue
// Get a 16 bit value off the serial port by doing two successive reads
// Assumes that data is being transmitted high byte first
int16_t get16bitValue(int serialIndex){
int16_t returnValue = 0;
serialWrite(serialIndex);
serialIndex++;
returnValue = serialRead(25);
serialWrite(serialIndex);
serialIndex++;
returnValue += serialRead(25) << 8;
return returnValue;
}
开发者ID:555learnwithme555,项目名称:UnoJoy,代码行数:13,代码来源:MegaJoy.c
示例10: loop
void loop() {
for(i = 0; i < 6; ++i) {
int old = accum[i];
v = analogRead(i);
v = smooth(v, &accum[i], 100);
if(v != old) {
serialWrite(0x80 | i);
serialWrite(v >> 7);
serialWrite(v & 0x7F);
x = 5;
}
}
开发者ID:lijon,项目名称:ctrlbox,代码行数:12,代码来源:ctrlbox-firmware.c
示例11: serializeFrsky
static void serializeFrsky(uint8_t data)
{
// take care of byte stuffing
if (data == 0x5e) {
serialWrite(frskyPort, 0x5d);
serialWrite(frskyPort, 0x3e);
} else if (data == 0x5d) {
serialWrite(frskyPort, 0x5d);
serialWrite(frskyPort, 0x3d);
} else
serialWrite(frskyPort, data);
}
开发者ID:qwedsazxc78,项目名称:betaflight_IST8310,代码行数:12,代码来源:frsky.c
示例12: stmWriteLen
int stmWriteLen(serialStruct_t *s, char *data, int len, unsigned char ck) {
unsigned char c;
int i;
for (i = 0; i < len; i++) {
c = data[i];
ck ^= c;
serialWrite(s, (char *)&c, 1);
}
serialWrite(s, (char *)&ck, 1);
return stmWaitAck(s, STM_RETRIES_LONG);
}
开发者ID:739374663,项目名称:esc32,代码行数:13,代码来源:stmbootloader.c
示例13: setServo
/**
*void setServo(int servo, int pos)
*@param servo - int, what servo channel are we talking about?
*@param pos - int, the position or the speed of the servo being requested
*@param hf - int, whether or not the servo is in half or full duplex. 0 = half, 1 is full.
*@return void
*
*Sets a motor as half duplex or full duplex. All default as
*/
void setServo(int servo, int pos, int hf){
int startBit;
//If the servo is in full duplex, set it to such.
if(hf == FULL) servo += 8;
startBit = STARTBIT;
serialWrite(4, startBit);
serialWrite(4, servo);
serialWrite(4, pos);
}
开发者ID:hlfshell,项目名称:MQP-Project,代码行数:22,代码来源:servo.c
示例14: writeEscapedByte
void writeEscapedByte(
unsigned char byte,
GioEndpoint *gioEndpoint){
unsigned char escapeChar = ESCAPE_CHAR;
switch(byte){
case START_FLAG:
case END_FLAG:
case ESCAPE_CHAR:
serialWrite(gioEndpoint, escapeChar);
default:
break;
}
serialWrite(gioEndpoint, byte);
}
开发者ID:Feechka,项目名称:UOBP,代码行数:14,代码来源:level2.c
示例15: slaveLoop
void slaveLoop()
{
watchdogReset();
uint32_t now = micros();
bool needHop=false;
switch (state) {
case 0: // waiting for packet
if (RF_Mode == Received) {
Green_LED_ON;
Red_LED_OFF;
// got packet
lastReceived = now;
lostpkts=0;
linkQuality = (linkQuality << 1) | 1;
RF_Mode = Receive;
spiSendAddress(0x7f); // Send the package read command
for (int16_t i = 0; i < bind_data.packetSize; i++) {
rx_buf[i] = spiReadData();
}
uint8_t payloadBytes = (rx_buf[0] & 0x3f);
if (payloadBytes > (bind_data.packetSize - 1)) {
// INVALID DATA
payloadBytes = 0;
}
// Check if this is a new packet from master and not a resent one
if ((rx_buf[0] ^ tx_buf[0]) & MASTER_SEQ) {
tx_buf[0] ^= MASTER_SEQ;
if (payloadBytes) {
// DATA FRAME
if (bind_data.flags & PACKET_MODE) {
serialWrite(0xf0);
serialWrite(payloadBytes);
CRCtx = 0;
}
for (uint8_t i=0; i < payloadBytes; i++) {
serialWrite(rx_buf[1 + i]);
if ((bind_data.flags & PACKET_MODE) && (bind_data.flags & PACKETCRC_MODE)) {
CRC16_add(&CRCtx, rx_buf[1 + i]);
}
}
if ((bind_data.flags & PACKET_MODE) && (bind_data.flags & PACKETCRC_MODE)) {
serialWrite(CRCtx >> 8);
serialWrite(CRCtx & 0xff);
}
}
}
开发者ID:JerryLutor,项目名称:openLRSngDL,代码行数:50,代码来源:main.cpp
示例16: ReceiveInterrupt
__interrupt void ReceiveInterrupt(void)
{
char rec = UCA0RXBUF;
if(rec == '1'){
serialWrite('0');
}else if(rec == '2'){
serialWrite('9');
}else if(rec == '3'){
serialWrite('0');
}else if(rec == '4'){
serialWrite('1');
}else if(rec == 'a' && alarm_state ==3){
TA0CCR1 = period>>2;
alarm_state = 4;
}
开发者ID:MemeTeme,项目名称:ELEC327-Final-Project,代码行数:15,代码来源:alarmMain.c
示例17: serialPrint
void serialPrint(serialPort_t *instance, const char *str)
{
uint8_t ch;
while ((ch = *(str++)) != 0) {
serialWrite(instance, ch);
}
}
开发者ID:iforce2d,项目名称:cleanflight,代码行数:7,代码来源:serial.c
示例18: sendPacket
void sendPacket(TPacket *packet)
{
char buffer[PACKET_SIZE];
int len = serialize(buffer, packet, sizeof(TPacket));
serialWrite(buffer, len);
}
开发者ID:khairulhazril,项目名称:EPP_Git_Solo_Demo,代码行数:7,代码来源:vincent-pi.cpp
示例19: _putc
static void _putc(void *p, char c)
{
(void)p; // avoid compiler warning about unused variable
serialWrite(Serial1, c);
while (!isSerialTransmitBufferEmpty(Serial1));
}
开发者ID:byu-magicc,项目名称:BreezySTM32,代码行数:7,代码来源:term.c
示例20: cliUsage
void cliUsage(cliCommand_t *cmd) {
serialPrint("usage: ");
serialPrint(cmd->name);
serialWrite(' ');
serialPrint(cmd->params);
serialPrint("\r\n");
}
开发者ID:739374663,项目名称:esc32,代码行数:7,代码来源:cli.c
注:本文中的serialWrite函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论