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


C++ Serial类代码示例

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


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

示例1: console

void SerialCommunicationApp::setup()
{

	lastString = "";
    bTextureComplete = false;
    
	//SERIAL SETUP
	const vector<Serial::Device> &devices( Serial::getDevices() );
	for( vector<Serial::Device>::const_iterator deviceIt = devices.begin(); deviceIt != devices.end(); ++deviceIt ) {
		console() << "Device: " << deviceIt->getName() << endl;
	}
	
	try {
		Serial::Device dev = Serial::findDeviceByNameContains("tty.usbmodem");
		serial = Serial( dev, 9600);
	}
	catch( ... ) {
		console() << "There was an error initializing the serial device!" << std::endl;
		exit( -1 );
	}
	contact = 0;
	serial.flush();
    
    //OSC SETUP
    port = 12346;
    host = "127.0.0.1";
    sender.setup( host, port, true );

    
    
    
}
开发者ID:dmelancon,项目名称:Prototypes,代码行数:32,代码来源:SerialCommunicationApp.cpp

示例2: setup

void setup() 
{
  size(1300, 1000);
  img = (loadImage("pic4.jpg"));

  /*//Use this to create your own pic of a specific colour to test individual RGB vals
   img = createImage(cols,rows,RGB); // 
   for(int i = 0; i < img.pixels.length; i++) {
   img.pixels[i] = color(0, 0, 255); 
   }
   */

  loadPixels(); 
  System.out.println(img.pixels.length);
  String portName = "COM4";
  myPort = new Serial(this, portName, 9600);
  background(0);
  dataIn[0][0] = 0;

  //send ack every 2 seconds, wait for ack back (see serial event
  //this begins negotiation between machines
  //reception of the ack is handled by serial interrupt method below
  while (!ack) {  
    myPort.write(88); 
    delay(2000);
  }
    ack = true;
}//end setup
开发者ID:tothepowerofe,项目名称:UMSATS-CAMDIVISION,代码行数:28,代码来源:Processing.c

示例3: iridiumLoop

/* This function tries to send the latest logging data over Iridium */
void iridiumLoop(const void *context) {
    char data_buffer[200];
    sprintf(data_buffer,"IRIDIUM: %s %.6f %.6f %.6f %lu %.6f %.6f %.6f %.6f %lu %hu %hu",
        date,latitude,longitude,altitude,precision,internal_temp,external_temp,pressure,power,
        encoded_chars,good_sentences,failed_checksums);
    int err = isbd.sendSBDText(data_buffer);
    if (err == ISBD_BUSY) {
        diagSerial.printf("IRIDIUM IS BUSY\r\n");
        return;
    }
    if (err != 0) {
        diagSerial.printf("sendReceiveSBDText failed: error ");
        diagSerial.printf("%d\n", err);
    }

}
开发者ID:bharad6,项目名称:arm_hab_controller,代码行数:17,代码来源:main.cpp

示例4: getElapsedSeconds

void SerialCommunicationApp::update()
{
//	console() << "Bytes available: " << serial.getNumBytesAvailable() << std::endl;
	
	double now = getElapsedSeconds();
	double deltaTime = now - lastUpdate;
	lastUpdate = now;
	sinceLastRead += deltaTime;
	
	if(sinceLastRead > READ_INTERVAL)
	{
		bSendSerialMessage = true;
		sinceLastRead = 0.0;
	}
		
	
	if (bSendSerialMessage)
	{
		// request next chunk
		serial.writeByte(ctr);
		
		try{
			// read until newline, to a maximum of BUFSIZE bytes
			lastString = serial.readStringUntil('\n', BUFSIZE );

		} catch(SerialTimeoutExc e) {
			console() << "timeout" << endl;
		}
		
		
		bSendSerialMessage = false;
		
		ctr+=8;
		console() << lastString << endl;
		
		
		TextLayout simple;
		simple.setFont( Font( "Arial Black", 24 ) );
		simple.setColor( Color( .7, .7, .2 ) );
		simple.addLine( lastString );
		simple.setLeadingOffset( 0 );
		mTexture = gl::Texture( simple.render( true, false ) );
		bTextureComplete = true;
		
		serial.flush();
	}
}
开发者ID:AKS2346,项目名称:Cinder,代码行数:47,代码来源:SerialCommunicationApp.cpp

示例5: console

void SerialCommunicationApp::setup()
{
	ctr = 0;
	lastString = "";
	sinceLastRead = 0.0;
	lastUpdate = 0.0;
	
	bSendSerialMessage = false;
	bTextureComplete = false;

	// print the devices
	const vector<Serial::Device> &devices( Serial::getDevices() );
	for( vector<Serial::Device>::const_iterator deviceIt = devices.begin(); deviceIt != devices.end(); ++deviceIt ) {
		console() << "Device: " << deviceIt->getName() << endl;
	}
	
	try {
		Serial::Device dev = Serial::findDeviceByNameContains("tty.usbserial");
		serial = Serial( dev, 9600);
	}
	catch( ... ) {
		console() << "There was an error initializing the serial device!" << std::endl;
		exit( -1 );
	}
	
	// wait for * as a sign for first contact
	char contact = 0;
	while(contact != '*')
	{
		contact = (char) serial.readByte();
	}
	
	// request actual data
	serial.writeByte(ctr);
	
	// clear accumulated contact messages in buffer
	char b = '*';
	while(serial.getNumBytesAvailable() > -1)
	{
		b = serial.readByte();
		console() << b << "_";
	}
		
	serial.flush();
}
开发者ID:AKS2346,项目名称:Cinder,代码行数:45,代码来源:SerialCommunicationApp.cpp

示例6: main

int main()
{
    Server              *s;
    Coordinator			*co;
	ModuleManager       *mm;
    XBeeController      *xbc;
	Serial              *se;
    MyModule            *mym;
	int                 mIndex;
    char                dn[128];
    dn[0] = '/';
    
    printf("Please Enter Your Device Name!\n");
    scanf("%s", &dn[1]);

	s = new Server();
    xbc = new XBeeController(s, "/XBC", "/dev/cu.usbserial-A50178PJ");
	mm	= new ModuleManager(s, dn);
	co	= new Coordinator(s, "/Coordinator");
    se  = new Serial(s, "/Serial", "/dev/cu.usbmodemfd131");
	mym = new MyModule(s, "/MM");

	mm->sendModuleList();
    xbc->co = co;
    co->xbc = xbc;
    
    se->connectTo(mym, "/Stream");
    
    while (1) {
        printf("Enter Module Index\n");
        scanf("%d", &mIndex);
        if (!mIndex) break;
        
        if (mIndex == -1) {
            co->ml->requestML();
            co->ml->displayModules();
        }
        
        if (mym->tID) 
            co->ml->createModule(mym->tID, mIndex);

    }	

	return 0;
}
开发者ID:MusashiNakajima,项目名称:System_cpp_Mac,代码行数:45,代码来源:main.cpp

示例7: Lua_ReadSerialChar

/**
 * Read a character from the specified serial port
 * Lua Params:
 * port - the serial port to initialize
 *        (SERIAL_USB, SERIAL_GPS, SERIAL_TELEMETRY, SERIAL_WIRELESS, SERIAL_AUX)
 * timeout - the read timeout, in ms.
 *
 * Lua Returns:
 * the character read, or nil if no characters received (receive timeout)
 *
 */
int Lua_ReadSerialChar(lua_State *L)
{
    int params = lua_gettop(L);
    if (!params)
        return 0;

    serial_id_t port = lua_tointeger(L,1);
    size_t timeout = params >= 2 ? lua_tointeger(L, 2) : DEFAULT_SERIAL_TIMEOUT;
    Serial *serial = get_serial(port);
    if (serial) {
        char c;
        if (serial->get_c_wait(&c, timeout)) {
            lua_pushnumber(L, c);
            return 1;
        }
    }
    return 0;
}
开发者ID:autosportlabs,项目名称:RaceCapture-Pro-firmware-mk1,代码行数:29,代码来源:luaLoggerBinding.c

示例8: at_sockwrite_wnc

void at_sockwrite_wnc(const char * s)
{
  string * pRespStr;
  char num2str[6];
  size_t sLen = strlen(s);
  if (sLen <= 99999)
  {
    string cmd_str("[email protected]=1,");
    itoa(sLen, num2str, 10);
    cmd_str += num2str;
    cmd_str += ",\"";
    while(*s != '\0')
    {
      itoa((int)*s++, num2str, 16);
      // Always 2-digit ascii hex:
      if (strlen(num2str) == 1)
      {
        num2str[2] = '\0';
        num2str[1] = num2str[0];
        num2str[0] = '0';
      }
      cmd_str += num2str;
    }
    cmd_str += "\"";
    send_wnc_cmd(cmd_str.data(), &pRespStr, WNC_TIMEOUT_MS);
  }
  else
    pc.puts("sockwrite Err, string to long\r\n");
}
开发者ID:DevinMui,项目名称:InternetOfToast,代码行数:29,代码来源:wnc_control.cpp

示例9: sockwrite_mdm

void sockwrite_mdm(const char * s)
{
    if (socketOpen == 1)
    {
    do
    {
      WNC_MDM_ERR = WNC_OK;
      at_sockwrite_wnc(s);
      if (WNC_MDM_ERR == WNC_NO_RESPONSE)
      {
        reinitialize_mdm();
        software_init_mdm();
      }
      else if (WNC_MDM_ERR == WNC_CMD_ERR)
      {
        pc.puts("Socket Write fail!!!\r\n");
        // Have seen when write fails modem gets stuck in bad state, try to recover
        reinitialize_mdm();
        software_init_mdm();
      }
    } while (WNC_MDM_ERR != WNC_OK);
    }
    else
      puts("Socket is closed for write!\r\n");
}
开发者ID:DevinMui,项目名称:InternetOfToast,代码行数:25,代码来源:wnc_control.cpp

示例10: sendRollCommand

void sendRollCommand(char ch,int pre)
{
    rollComm.preamble = pre;
    //command.info_byte = 0b00000000;
    rollComm.ch = ch;
    sPort.Write(&rollComm, sizeof(rollCommand));
}
开发者ID:abhinavcoder,项目名称:sirius,代码行数:7,代码来源:main.cpp

示例11: set_i2c_pointer

char set_i2c_pointer(char addr, char reg)
{
    if (i2c.write(addr) == 0)
    {
        if (DEBUG)
            pc.printf("Could not write device address (set_i2c_pointer)\r\n");
        return 0;
    }
    if (i2c.write(reg) == 0)
    {
        if (DEBUG)
            pc.printf("Could not write reg address (set_i2c_pointer)\r\n");
        return 0;
    }
    return 1;
}
开发者ID:Quadcopter-safety,项目名称:IMU-mbed-interface,代码行数:16,代码来源:sensor.cpp

示例12: print_board

void LED_board::print_board(){
   for(int i = 0; i < NUM_ROW; i++){
        for(int j = 0; j < NUM_COL; j++){
            pc.printf("row_buffer[%d][%d] = %x\r\n", i, j, row_buffer[i][j]);
        }
    }
}
开发者ID:ljasmine,项目名称:ese350,代码行数:7,代码来源:LED_board.cpp

示例13: createSensor

/** SENSOR functions -----------------------------------------------------------------------------*/
void node::createSensor(PinName sensorPin, PinName voltageCtrl, int num)  //Create new ligths in the node.
{
    if (num <= 5) {
        mySensors[num - 1] = new sensor(sensorPin, voltageCtrl);
    } else {
        pc.printf("Sensor number %d is invalid", num);
    }
}
开发者ID:andycarle,项目名称:SanLeandroRepository,代码行数:9,代码来源:node.cpp

示例14: LWM2M_notification_init

/*
initialize the limits for LWM2M mode and set the state by reporting the first sample
set LWM2M_observing true or false depending on desired behavior
if LWM2M_observing is false, the sample won't be transmitted
*/
void LWM2M_notification_init()
{
    pc.printf("init\r\n");
    limits[0] = LWM2M_lt;
    limits[1] = LWM2M_gt;
    report_sample(get_sample());
    return;
}
开发者ID:connectIOT,项目名称:lwm2m-objects,代码行数:13,代码来源:LWM2M_resource.cpp

示例15: DllMain

BOOL APIENTRY DllMain(HMODULE /*module*/, DWORD reason_for_call, LPVOID /*reseved*/)
{
  if (reason_for_call == DLL_PROCESS_DETACH)
  {
		serial_port.close();
	}
	return TRUE;
}
开发者ID:SouzaJBR,项目名称:ets2_dashboard,代码行数:8,代码来源:plugin.cpp


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