本文整理汇总了C++中serial_write函数的典型用法代码示例。如果您正苦于以下问题:C++ serial_write函数的具体用法?C++ serial_write怎么用?C++ serial_write使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了serial_write函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TFI_CJ_clean
void TFI_CJ_clean ( )
{
#ifdef OLDCJTFI
byte command[20];
int ret = 0;
int i = 0;
memset ( command , 0x00 , 20 ) ;
command[1] = DISP_OUT_LED; //命令字
for (i=3;i<15;++i)
{ //数据,清除显示时数据内容为空
command[i] = ' ';
}
command[15] = 0;
BBC(command);
ret = serial_write(LED_COM,command ,18) ;
#else
byte command[20];
int ret = 0;
memset ( command , 0x00 , 0x00 ) ;
//0x97 清屏 AA 04 97 BB
//0x98 清屏,语音:谢谢,祝您一路平安! AA 04 98 BB
//0x99 您好 AA 04 99 BB
//0xA0 谢谢 AA 04 A0 BB
//0xA1 欢迎光临 AA 04 A1 BB
//0xA2 别客气 AA 04 A2 BB
//0xA3 请慢走 AA 04 A3 BB
//0xA4 走好 AA 04 A4 BB
//0xA5 再见 AA 04 A5 BB
command[0] = 0xAA;
command[1] = 0x04;
command[2] = 0x97;
command[3] = 0xBB;
ret = serial_write(LED_COM,command ,4) ;
#endif
}
示例2: msr_iso_write
int
msr_iso_write(int fd, msr_tracks_t * tracks)
{
int i;
uint8_t buf[4];
msr_cmd (fd, MSR_CMD_WRITE);
buf[0] = MSR_ESC;
buf[1] = MSR_RW_START;
serial_write (fd, buf, 2);
for (i = 0; i < MSR_MAX_TRACKS; i++) {
buf[0] = MSR_ESC;
buf[1] = i + 1;
serial_write (fd, buf, 2);
serial_write (fd, tracks->msr_tracks[i].msr_tk_data,
tracks->msr_tracks[i].msr_tk_len);
}
buf[0] = MSR_RW_END;
buf[1] = MSR_FS;
serial_write (fd, buf, 2);
serial_readchar (fd, &buf[0]);
serial_readchar (fd, &buf[0]);
if (buf[0] != MSR_STS_OK)
warnx("write failed");
return (0);
}
示例3: serial_println
void serial_println(uint8_t port, String output) {
for (uint8_t i=0; i<output.length(); i++){
serial_write(port, output[i]);
}
serial_write(port, '\n');
serial_activate(port);
}
示例4: ulcd_blit
int ulcd_blit(ulcd_dev *dev,
uint16_t x, uint16_t y,
uint16_t w, uint16_t h,
const char* data) {
char buf[10];
buf[0] = 0x49;
buf[1] = x >> 8;
buf[2] = x & 0xFF;
buf[3] = y >> 8;
buf[4] = y & 0xFF;
buf[5] = w >> 8;
buf[6] = w & 0xFF;
buf[7] = h >> 8;
buf[8] = h & 0xFF;
buf[9] = 0x10;
serial_write(dev->port, buf, 10);
serial_write(dev->port, data, w*h*2);
if(!check_result(dev, "Error while blitting.")) {
return 0;
}
return 1;
}
示例5: ulcd_draw_text
int ulcd_draw_text(ulcd_dev *dev,
const char* text,
int x, int y,
int font,
uint16_t color) {
// Init
int textlen = strlen(text);
char buf[10];
// Commands
buf[0] = 0x53;
buf[1] = x >> 8;
buf[2] = x & 0xFF;
buf[3] = y >> 8;
buf[4] = y & 0xFF;
buf[5] = font & 0xFF;
buf[6] = color >> 8;
buf[7] = color & 0xFF;
buf[8] = 0x01;
buf[9] = 0x01;
// Send data
serial_write(dev->port, buf, 10);
serial_write(dev->port, text, textlen);
write_char(dev, 0x00);
// Check results
if(!check_result(dev, "Text drawing failed.")) {
return 0;
}
return 1;
}
示例6: save
static gboolean
save(QahiraFormat *self, cairo_surface_t *surface, GOutputStream *stream,
GCancellable *cancel, GError **error)
{
struct Private *priv = GET_PRIVATE(self);
gboolean status = TRUE;
guchar *data = qahira_format_surface_get_data(self, surface);
if (!data) {
g_set_error(error, QAHIRA_ERROR, QAHIRA_ERROR_FAILURE,
Q_("serial: surface data is NULL"));
goto error;
}
priv->header.stride = qahira_format_surface_get_stride(self, surface);
if (0 > priv->header.stride) {
g_set_error(error, QAHIRA_ERROR, QAHIRA_ERROR_FAILURE,
Q_("serial: invalid stride"));
goto error;
}
qahira_surface_size(surface, &priv->header.width,
&priv->header.height);
priv->header.content = cairo_surface_get_content(surface);
status = serial_write(self, stream, cancel, (gpointer)&priv->header,
sizeof(priv->header), error);
if (!status) {
goto error;
}
status = serial_write(self, stream, cancel, data,
priv->header.stride * priv->header.height, error);
exit:
return status;
error:
status = FALSE;
goto exit;
}
示例7: IRqueue
void IRqueue(char *param_fname,int fd)
{
FILE *fp=NULL;
FILE *fpq=NULL;
int res,i;
char buffer[255] = {0}; // buffer
//check filename if exist
printf(" Entering Queue mode: play commands from file\n");
fpq=fopen(param_fname,"r");
if (fpq==NULL)
printf(" Queue command file does not exist. \n");
else {
char cmdfile[255];
int len = 0;
while (fgets(cmdfile, sizeof(cmdfile), fpq )){
len = strlen(cmdfile);
if( cmdfile[len-1] == '\n' )
cmdfile[len-1] = 0;
fp=fopen(cmdfile,"rb");
if (fp==NULL) {
printf(" Comand file %s does not exist. \n", cmdfile);
break;
}
else{
printf(" Sending command file %s \n", cmdfile);
serial_write( fd, "\x03", 1);
int comsresult = 0;
while(!feof(fp)) {
if ((res=fread(&buffer,sizeof(unsigned char),sizeof(buffer),fp)) > 0) {
if (verbose){
printf(" ######Sending -%d- Bytes to IRToy...\n", res);
for(i=0;i<res;i++)
printf(" %02X ",(uint8_t) buffer[i]);
printf("\n");
}
comsresult = serial_write( fd, buffer, res);
if (comsresult != res){
printf("## comms error bytes sent %d <> bytes supposed to be sent %d\n", comsresult, res);
serial_write( fd, "\xFF\xFF\x00\x00\x00\x00\x00", 7); //trying to 'reset' IR Toy after error
exit(-1);
}
comsresult = 0;
#ifdef _WIN32
Sleep(500); //wait 500 milliseconds - for comms to finish, else get errors. Could try smaller, but no delay always fails & locks up the ORToy!
#else
sleep(500); //wait 500 milliseconds - for comms to finish, else get errors. Could try smaller, but no delay always fails & locks up the ORToy!
#endif
}
}
if(comsresult){
printf("comms error level 1 %d\n", comsresult);
break;
}
}
fclose(fp);
}
}
fclose(fpq);
}
示例8: msr_raw_write
int
msr_raw_write(int fd, msr_tracks_t * tracks)
{
int i;
uint8_t buf[4];
msr_cmd (fd, MSR_CMD_RAW_WRITE);
buf[0] = MSR_ESC;
buf[1] = MSR_RW_START;
serial_write (fd, buf, 2);
for (i = 0; i < MSR_MAX_TRACKS; i++) {
buf[0] = MSR_ESC; /* start delimiter */
buf[1] = i + 1; /* track number */
buf[2] = tracks->msr_tracks[i].msr_tk_len; /* data length */
serial_write (fd, buf, 3);
serial_write (fd, tracks->msr_tracks[i].msr_tk_data,
tracks->msr_tracks[i].msr_tk_len);
}
buf[0] = MSR_RW_END;
buf[1] = MSR_FS;
serial_write (fd, buf, 2);
serial_readchar (fd, &buf[0]);
serial_readchar (fd, &buf[0]);
if (buf[0] != MSR_STS_OK)
warnx("raw write failed");
return (0);
}
示例9: TFI_CJ_LedShow
void TFI_CJ_LedShow ( int CarType , int charge )
{
#ifdef OLDCJTFI
byte command[20];
int ret = 0;
memset ( command , 0x00 , 20 ) ;
command[1] = DISP_OUT_LED; //命令字
sprintf(&command[3],"% 4d% 4d% 4d",CarType,charge,0);
if(charge)
{
command[15] = CarType;
}
BBC(command);
ret = serial_write(LED_COM,command ,18) ;
#else
byte command[20];
int ret = 0;
memset ( command , 0x00 , 20 ) ;
//金额显示器显示 1 型车 金额 25元 余额不显示,语音:1型车 缴费25元
//AA 0B 95 31 30 32 35 30 30 30 BB
if(CarType>0&&CarType<10&&charge>0)
{
command[0] = 0xAA;
command[1] = 0x0B;
command[2] = 0x95;//95报价 95不报价
sprintf(&command[3],"%d%03d%03d",CarType,charge,0);
command[10] = 0xBB;
ret = serial_write(LED_COM,command ,11) ;
}
#endif
}
示例10: serial_write_hex_digit
static void serial_write_hex_digit(const uint32_t value) {
if( value < 10 ) {
serial_write((uint8_t)value + (uint8_t)'0');
} else if( value < 16 ) {
serial_write((uint8_t)(value - 10) + (uint8_t)'A');
} else {
serial_write('?');
}
}
示例11: sendByte
inline void sendByte(unsigned char b)
{
if (b==HDLC_frameFlag || b==HDLC_escapeFlag)
{
serial_write(HDLC_escapeFlag);
b ^= HDLC_escapeXOR;
}
serial_write(b);
}
示例12: loop
void loop()
{
serial_write("TEST\n\r");
if (serial_available()) {
serial_write("caractere");
caractere=serial_read();
serial_write(chaine);
serial_write(&caractere);
}
}
示例13: gprs_uart_tx
static void gprs_uart_tx(uint8_t *pData, uint16_t len)
{
DBG_ASSERT(pData != NULL __DBG_LINE);
DBG_ASSERT(len != 0 __DBG_LINE);
#if GPRS_DEBUG
serial_write(HAL_UART_2, pData, len);
#endif
serial_write(HAL_UART_4, pData, len);
}
示例14: acc_dump
void acc_dump(void) {
#ifdef ENABLE_DEBUG_SERIAL_DUMP
serial_write_str("ACC: ");
for (uint8_t i=0; i<3; i++) {
serial_write_int(acc_data[i]);
serial_write(' ');
}
serial_write('\n');
#endif
}
示例15: test_loopback
void test_loopback(void) {
serial_t serial;
unsigned int count;
time_t start, stop;
uint8_t lorem_ipsum[] = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
uint8_t lorem_hugesum[4096*3];
uint8_t buf[sizeof(lorem_hugesum)];
ptest();
passert(serial_open(&serial, device, 115200) == 0);
/* Test write/flush/read */
passert(serial_write(&serial, lorem_ipsum, sizeof(lorem_ipsum)) == sizeof(lorem_ipsum));
passert(serial_flush(&serial) == 0);
passert(serial_read(&serial, buf, sizeof(lorem_ipsum), -1) == sizeof(lorem_ipsum));
passert(memcmp(lorem_ipsum, buf, sizeof(lorem_ipsum)) == 0);
/* Test poll/write/flush/poll/input waiting/read */
passert(serial_poll(&serial, 500) == 0); /* Should timeout */
passert(serial_write(&serial, lorem_ipsum, sizeof(lorem_ipsum)) == sizeof(lorem_ipsum));
passert(serial_flush(&serial) == 0);
passert(serial_poll(&serial, 500) == 1);
usleep(500000);
passert(serial_input_waiting(&serial, &count) == 0);
passert(count == sizeof(lorem_ipsum));
passert(serial_read(&serial, buf, sizeof(lorem_ipsum), -1) == sizeof(lorem_ipsum));
passert(memcmp(lorem_ipsum, buf, sizeof(lorem_ipsum)) == 0);
/* Test non-blocking poll */
passert(serial_poll(&serial, 0) == 0);
/* Test a very large read-write (likely to exceed internal buffer size (~4096)) */
memset(lorem_hugesum, 0xAA, sizeof(lorem_hugesum));
passert(serial_write(&serial, lorem_hugesum, sizeof(lorem_hugesum)) == sizeof(lorem_hugesum));
passert(serial_flush(&serial) == 0);
passert(serial_read(&serial, buf, sizeof(lorem_hugesum), -1) == sizeof(lorem_hugesum));
passert(memcmp(lorem_hugesum, buf, sizeof(lorem_hugesum)) == 0);
/* Test read timeout */
start = time(NULL);
passert(serial_read(&serial, buf, sizeof(buf), 2000) == 0);
stop = time(NULL);
passert((stop - start) > 1);
/* Test non-blocking read */
start = time(NULL);
passert(serial_read(&serial, buf, sizeof(buf), 0) == 0);
stop = time(NULL);
/* Assuming we weren't context switched out for a second and weren't on a
* thin time boundary ;) */
passert((stop - start) == 0);
passert(serial_close(&serial) == 0);
}