当前位置: 首页>>代码示例>>C++>>正文


C++ serial类代码示例

本文整理汇总了C++中serial的典型用法代码示例。如果您正苦于以下问题:C++ serial类的具体用法?C++ serial怎么用?C++ serial使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了serial类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: invalid_argument

void
Serial::SerialImpl::open ()
{
  if (port_.empty ()) {
    throw invalid_argument ("Empty port is invalid.");
  }
  if (is_open_ == true) {
    throw SerialExecption ("Serial port already open.");
  }

  fd_ = CreateFile(port_.c_str(),
                   GENERIC_READ | GENERIC_WRITE,
                   0,
                   0,
                   OPEN_EXISTING,
                   FILE_ATTRIBUTE_NORMAL,
                   0);

  if (fd_ == INVALID_HANDLE_VALUE) {
    DWORD errno_ = GetLastError();
	stringstream ss;
    switch (errno_) {
    case ERROR_FILE_NOT_FOUND:
      ss << "Specified port, " << port_ << ", does not exist.";
      THROW (IOException, ss.str().c_str());
    default:
      ss << "Unknown error opening the serial port: " << errno;
      THROW (IOException, ss.str().c_str());
    }
  }

  reconfigurePort();
  is_open_ = true;
}
开发者ID:byteman,项目名称:finger,代码行数:34,代码来源:win.cpp

示例2: inportb

/*
int c;
 do { c = inportb(PORT1 + 5);
      if (c & 1) {buffer[bufferin] = inportb(PORT1);
		  bufferin++;
		  if (bufferin == 1024) {bufferin = 0;}}
    }while (c & 1);
 outportb(0x20,0x20);
*/
EXTERNC void handle_serial()
{
	//display("?");
	unsigned int result = 0;
	result = inportb(COM1_PORT + INT_ID);
	unsigned int status;	//stores the status of whatever needs checking
	if ((result & IID_NO_INT) != IID_NO_INT)
	{	//interrupt pending
		//display("\nInterrupt pending: ");
		//PrintNumber(result);
		//display("\n");
		if ((result & 0x06) == IID_MODEM)
		{
			
		}
		if ((result & 0x06) == IID_REC_STAT)
		{
			//status = inportb(COM1_PORT);
			
		}
		if ((result & 0x06) == IID_TRANSMIT)
		{
			
		}
		if ((result & 0x06) == IID_RECEIVED)
		{
			add_me_serial.data1 = kellogs.read_serial();
			add_system_event(&add_me_serial);
		}
	}
	outportb(0x20,0x20);	//signal end of interrupt
	//display("+");
}
开发者ID:uglyoldbob,项目名称:doors-os,代码行数:42,代码来源:serial.cpp

示例3: loop

// bii:#entry_point()
void loop() {

	msg = serialport.read(); //read a message
	if(msg != "")
	{
		serialport.writeOpen();
		serialport.writeString(msg); //send a message
		serialport.writeEnd();

		if(premsg=="servo"){
			int n;
			n = atoi(msg.c_str());
			myservo.write(n);
		}
		premsg = msg;
	}
}
开发者ID:JeffAbrahamson,项目名称:docs,代码行数:18,代码来源:main_arduino.cpp

示例4: invalid_argument

void
Serial::SerialImpl::open ()
{
  if (port_.empty ()) {
    throw invalid_argument ("Empty port is invalid.");
  }
  if (is_open_ == true) {
    throw SerialException ("Serial port already open.");
  }

  // See: https://github.com/wjwwood/serial/issues/84
  wstring port_with_prefix = _prefix_port_if_needed(port_);
  LPCWSTR lp_port = port_with_prefix.c_str();
  fd_ = CreateFileW(lp_port,
                    GENERIC_READ | GENERIC_WRITE,
                    0,
                    0,
                    OPEN_EXISTING,
                    FILE_ATTRIBUTE_NORMAL,
                    0);

  if (fd_ == INVALID_HANDLE_VALUE) {
    DWORD errno_ = GetLastError();
	stringstream ss;
    switch (errno_) {
    case ERROR_FILE_NOT_FOUND:
      // Use this->getPort to convert to a std::string
      ss << "Specified port, " << this->getPort() << ", does not exist.";
      THROW (IOException, ss.str().c_str());
    default:
      ss << "Unknown error opening the serial port: " << errno;
      THROW (IOException, ss.str().c_str());
    }
  }

  reconfigurePort();
  is_open_ = true;
}
开发者ID:4ib3r,项目名称:domoticz,代码行数:38,代码来源:win.cpp

示例5: setup

void setup() {
	myservo.attach(9);
	serialport.init();
}
开发者ID:JeffAbrahamson,项目名称:docs,代码行数:4,代码来源:main_arduino.cpp

示例6: __irq_dma1_channel4

 void __irq_dma1_channel4(void) {
     //DMA_ClearITPendingBit(DMA1_IT_TC4);
     serial1.txIsr();
 }
开发者ID:jackeyjiang,项目名称:meizi_f7disc,代码行数:4,代码来源:m_serial.cpp

示例7: PortNotOpenedException

void
Serial::SerialImpl::setDTR (bool level)
{
  if (is_open_ == false) {
    throw PortNotOpenedException ("Serial::setDTR");
  }

  int command = TIOCM_DTR;

  if (level) {
    if (-1 == ioctl (fd_, TIOCMBIS, &command))
    {
      stringstream ss;
      ss << "setDTR failed on a call to ioctl(TIOCMBIS): " << errno << " " << strerror(errno);
      throw(SerialException(ss.str().c_str()));
    }
  } else {
    if (-1 == ioctl (fd_, TIOCMBIC, &command))
    {
      stringstream ss;
      ss << "setDTR failed on a call to ioctl(TIOCMBIC): " << errno << " " << strerror(errno);
      throw(SerialException(ss.str().c_str()));
    }
  }
}
开发者ID:4ib3r,项目名称:domoticz,代码行数:25,代码来源:unix.cpp

示例8: main

void main() {
  char data; //To store the character to send
  printf("Enter character to be sent"); //User prompt
  scanf("%c",&data); //User input

  comm.startDevice("COM2", 9600);
  /* “COM 2” refers to the com port in which the USB to SERIAL port is attached. It is shown by right clicking on my computer, then going to properties and then device manager
  9600 is the baud-rate in bits per second */

  comm.send_data(data); //The data is sent through the port
  comm.stopDevice(); //The device is closed down

}
开发者ID:Robotix,项目名称:image-processing-wws-2014,代码行数:13,代码来源:senddata.cpp

示例9: invalid_argument

void
Serial::SerialImpl::open ()
{
  if (port_.empty ()) {
    throw invalid_argument ("Empty port is invalid.");
  }
  if (is_open_ == true) {
    throw SerialException ("Serial port already open.");
  }

  fd_ = ::open (port_.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);

  if (fd_ == -1) {
    switch (errno) {
    case EINTR:
      // Recurse because this is a recoverable error.
      open ();
      return;
    case ENFILE:
    case EMFILE:
      THROW (IOException, "Too many file handles open.");
    default:
      THROW (IOException, errno);
    }
  }

  reconfigurePort();
  is_open_ = true;
}
开发者ID:4ib3r,项目名称:domoticz,代码行数:29,代码来源:unix.cpp

示例10: PortNotOpenedException

void
Serial::SerialImpl::flush ()
{
  if (is_open_ == false) {
    throw PortNotOpenedException ("Serial::flush");
  }
  FlushFileBuffers (fd_);
}
开发者ID:4ib3r,项目名称:domoticz,代码行数:8,代码来源:win.cpp

示例11: ioctl

bool
Serial::SerialImpl::waitForChange ()
{
#ifndef TIOCMIWAIT

while (is_open_ == true) {

    int status;

    if (-1 == ioctl (fd_, TIOCMGET, &status))
    {
        stringstream ss;
        ss << "waitForChange failed on a call to ioctl(TIOCMGET): " << errno << " " << strerror(errno);
        throw(SerialException(ss.str().c_str()));
    }
    else
    {
        if (0 != (status & TIOCM_CTS)
         || 0 != (status & TIOCM_DSR)
         || 0 != (status & TIOCM_RI)
         || 0 != (status & TIOCM_CD))
        {
          return true;
        }
    }

    usleep(1000);
  }

  return false;
#else
  int command = (TIOCM_CD|TIOCM_DSR|TIOCM_RI|TIOCM_CTS);

  if (-1 == ioctl (fd_, TIOCMIWAIT, &command)) {
    stringstream ss;
    ss << "waitForDSR failed on a call to ioctl(TIOCMIWAIT): "
       << errno << " " << strerror(errno);
    throw(SerialException(ss.str().c_str()));
  }
  return true;
#endif
}
开发者ID:4ib3r,项目名称:domoticz,代码行数:42,代码来源:unix.cpp

示例12: PortNotOpenedException

bool
Serial::SerialImpl::getCD()
{
  if (is_open_ == false) {
    throw PortNotOpenedException ("Serial::getCD");
  }
  DWORD dwModemStatus;
  if (!GetCommModemStatus(fd_, &dwModemStatus))
    // Error in GetCommModemStatus;
    THROW (IOException, "Error getting the status of the DSR line.");

  return (bool) (MS_RLSD_ON & dwModemStatus);
}
开发者ID:byteman,项目名称:finger,代码行数:13,代码来源:win.cpp

示例13: main

int main(void)
{

	halInit();
	chSysInit();

	//kruciální řádky - odpojit jtag; nechat jenom swd - sou na nem piny pro SPI1
	//premapovat SPI1 na PB3;4;5
	RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
	AFIO->MAPR |= AFIO_MAPR_SPI1_REMAP;
	AFIO->MAPR |= 0b010 << 24;

#if 1
	spiStart(&SPID1, &config);
	palSetPadMode(config.ssport, config.sspad, PAL_MODE_OUTPUT_PUSHPULL);
	palSetPadMode(SPI_SCK_PORT, SPI_SCK_PIN, SPI_SCK_MODE);
	palSetPadMode(SPI_MISO_PORT, SPI_MISO_PIN, SPI_MISO_MODE);
	palSetPadMode(SPI_MOSI_PORT, SPI_MOSI_PIN, SPI_MOSI_MODE);

#else
	palSetPadMode(config.ssport, config.sspad, PAL_MODE_OUTPUT_PUSHPULL);
	palSetPadMode(SPI_SCK_PORT, SPI_SCK_PIN, PAL_MODE_OUTPUT_PUSHPULL);
	palSetPadMode(SPI_MISO_PORT, SPI_MISO_PIN, PAL_MODE_OUTPUT_PUSHPULL);
	palSetPadMode(SPI_MOSI_PORT, SPI_MOSI_PIN, PAL_MODE_OUTPUT_PUSHPULL);

	palClearPad(config.ssport, config.sspad);
	palClearPad(SPI_SCK_PORT, SPI_SCK_PIN);
	palClearPad(SPI_MISO_PORT, SPI_MISO_PIN);
	palClearPad(SPI_MOSI_PORT, SPI_MOSI_PIN);

	palSetPad(config.ssport, config.sspad);
	palClearPad(config.ssport, config.sspad);
	palClearPad(SPI_SCK_PORT, SPI_SCK_PIN);
	palClearPad(SPI_MISO_PORT, SPI_MISO_PIN);
	palClearPad(SPI_MOSI_PORT, SPI_MOSI_PIN);
	palSetPad(SPI_SCK_PORT, SPI_SCK_PIN);
	palClearPad(config.ssport, config.sspad);
	palClearPad(SPI_SCK_PORT, SPI_SCK_PIN);
	palClearPad(SPI_MISO_PORT, SPI_MISO_PIN);
	palClearPad(SPI_MOSI_PORT, SPI_MOSI_PIN);
	palSetPad(SPI_MISO_PORT, SPI_MISO_PIN);
	palClearPad(config.ssport, config.sspad);
	palClearPad(SPI_SCK_PORT, SPI_SCK_PIN);
	palClearPad(SPI_MISO_PORT, SPI_MISO_PIN);
	palClearPad(SPI_MOSI_PORT, SPI_MOSI_PIN);
	palSetPad(SPI_MOSI_PORT, SPI_MOSI_PIN);
	palClearPad(config.ssport, config.sspad);
	palClearPad(SPI_SCK_PORT, SPI_SCK_PIN);
	palClearPad(SPI_MISO_PORT, SPI_MISO_PIN);
	palClearPad(SPI_MOSI_PORT, SPI_MOSI_PIN);

	//
#endif

	palSetPadMode(TEST_LED_PORT, TEST_LED_PIN, PAL_MODE_INPUT);
	palSetPadMode(TEST_LED_PORT2, TEST_LED_PIN2, PAL_MODE_OUTPUT_PUSHPULL);

	palClearPad(TEST_LED_PORT, TEST_LED_PIN);
	palClearPad(TEST_LED_PORT2, TEST_LED_PIN2);

	s1.Register();

	palSetPadMode(GPIOA, 2, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
//	palSetPad(GPIOA,2);
	//DBGMCU->CR |= DBGMCU_CR_DBG_TIM2_STOP;
	pwmStart(&PWMD2, &pwmcfg);
	pwmEnableChannel(&PWMD2,2,PWM_PERCENTAGE_TO_WIDTH(&PWMD2,5000));

	//setup watchdog
	DBGMCU->CR |= DBGMCU_CR_DBG_IWDG_STOP;
	IWDG->KR = 0x5555;
	IWDG->PR = 6;
	IWDG->RLR = 0xFFF;
	IWDG->KR = 0xCCCC;

#if 1
	ser.Init();

	rf.begin();
	rf.enableAckPayload();
	rf.enableDynamicPayloads();
	for (int i = 0; i < 5; i++)
		rf.openReadingPipe(i, pipe + i);
	rf.startListening();

#endif
	while (TRUE)
	{
		Scheduler::Play();
		ser.Loop();
		sysTime = chTimeNow();
	}

	return 1;
}
开发者ID:kubanecxxx,项目名称:homeautomation,代码行数:95,代码来源:main.cpp


注:本文中的serial类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。