本文整理汇总了C++中Serial类的典型用法代码示例。如果您正苦于以下问题:C++ Serial类的具体用法?C++ Serial怎么用?C++ Serial使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Serial类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: main
main() {
Serial usb; // usb object, represents the USB serial connection
/* when a character is received on usb the SignalInterruptoin object calls serialEvent() function.
It is a signal interruption object so he call a function when a event (of signal) occurs */
SignalInterruption characterReceive(
usb.getSignalCharacterReceived(), // the signal of interruption is get from usb
serialEvent); // the funciton to be called is serialEvent()
while(true) { // repreat forever
if (stringComplete) { // if a newline character was received
usb << input.str(); // get the string from input stream and put on usb serial stream
input.str(""); // clear the stream input set your string to ""
stringComplete = false; // and now the string is't complete
}
}
}
开发者ID:DavidUser,项目名称:BEmbed,代码行数:18,代码来源:main.cpp
示例9: iridiumSetup
/* This function initializes the iridium module to work*/
void iridiumSetup() {
// Initialize timer
set_time(1256729737);
startMillis();
diagSerial.baud(115200);
nss.baud(19200);
isbd.attachConsole(diagSerial);
//isbd.attachDiags(diagSerial);
isbd.adjustATTimeout(60); // adjust to longer time out time
isbd.attachMessageBuffer(&messageBuffer);
isbd.begin();
wait(5);
isbd.setPowerProfile(1);
}
开发者ID:bharad6,项目名称:arm_hab_controller,代码行数:19,代码来源:main.cpp
示例10: CPPUNIT_ASSERT_NO_THROW
void SerialTest::SetDataBits() {
Serial *serial = NULL;
unsigned int data_bits[] = { 5, 6, 7, 8, 0};
// create serial object
CPPUNIT_ASSERT_NO_THROW(serial = new Serial("/dev/ttyS1"));
// perform data bit setting tests
for (unsigned int i=0; data_bits[i]!=0; i++) {
CPPUNIT_ASSERT_NO_THROW(serial->SetDataBits(data_bits[i]));
CPPUNIT_ASSERT_EQUAL(data_bits[i], serial->DataBits());
}
CPPUNIT_ASSERT_THROW(serial->SetDataBits(100), std::runtime_error);
// destroy serial object
delete serial;
CPPUNIT_ASSERT(signal_catcher.StringSignalsReceived(0));
}
开发者ID:ivannavarrete,项目名称:satori,代码行数:19,代码来源:serialtest.cpp
示例11: main
int main() {
Serial* port = new Serial("COM4");
if (port->IsConnected()) cout << "Connection established!!!" << endl;
int tempX = 1111;
int tempY = 1111;
bool automatic = true;
sendCommandToArduino(port, automatic, 'w', tempX, tempY);
//char data[256] = "";
//int datalength = 256;
//int readResult = 0;
//for (int i = 0; i < 256; ++i) { data[i] = 0; }
//string str;
//char command[] = "i";
/*char sendMe[1];
sendMe[0] = '1';
sendMe[0] = '0';
int msglen = strlen(sendMe);
while(true){
port->WriteData(sendMe, 2);
cout << "Please write two digit number (00 = turn off, 01 = turn on, 11 = blink): ";
cin >> sendMe[0];
cin >> sendMe[1];
system("pause");
if(sendMe[0] == '1')
sendMe[0] = '0';
else
sendMe[0] = '1';
}
//while (1) {
// while (port->ReadData(data, 256) != -1) {
// printf("%s", data);
// }
//} */
system("pause");
return 0;
}
开发者ID:lcheek3,项目名称:CS480-Project-2,代码行数:42,代码来源:main.cpp
示例12: 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
示例13: 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
示例14: 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
示例15: 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
示例16: 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
示例17: 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
示例18: 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
示例19: 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
示例20: send_empty_packet
void send_empty_packet()
{
memset(packet, 0, PACKET_MAX_SIZE);
packet[0] = PACKET_SYNC;
packet[1] = PACKET_VER;
serial_port.write(packet, 16);
}
开发者ID:SouzaJBR,项目名称:ets2_dashboard,代码行数:8,代码来源:plugin.cpp
注:本文中的Serial类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论