// // Main Routine // int main(void) { #ifdef DEBUG CSerial ser; // declare a UART object ser.enable(); CDebug dbg(ser); // Debug stream use the UART object dbg.start(); #endif // // Your setup code here // swPWM pwm(TIMER_1); pwm.period(0.01); // set the period time of PWM to 10ms. pwm.enable(); // start the pwm int pins[] = {LED_PIN_0, LED_PIN_1, LED_PIN_2, LED_PIN_3}; float y; int x[4] = { 0, 10, 20, 30 }; // initialize all channels x degree // // Enter main loop. // while(1) { // // FireFly loop // for (int ch = 0; ch < 4; ch++) { x[ch] = (x[ch] + 10) % 360; // degree 0~360, step by 2 y = arm_sin_f32((x[ch] * M_PI) / 180.0f); // y = sine @x pwm.output(pins[ch], map(y, -1.0f, 1.0f, 0.0f, 1.0f)); // update the duty-cycle of channel } sleep(10); // speed } }
void SendQuadcopterData() { #ifdef ENABLE_SERIAL packet[0] = 'g'; packet[1] = lift; packet[2] = pitch; packet[3] = yaw; packet[4] = roll; packet[5] = gyroDiv; if (resetGyro) packet[6] = 'r'; else packet[6] = 's'; packet[7] = '\0'; resetGyro = false; //printf("%d %d %d %d\n", lift, yaw, pitch, roll); if (serial.IsOpened()) { serial.SendData((const char *)packet, length); } else { printf("Serial not opened!!!\n"); } #endif }
int main(int argc, char **argv) { const char serialBuffer[6] = "hello"; int serialOpen, nBytesRead; serialOpen=serial.Open(6,9600); cout<<serialOpen; if(serialOpen){ nBytesRead=serial.SendData(serialBuffer,strlen(serialBuffer)); //ASSERT(nBytesRead==strlen(serialBuffer)); //delete [] serialBuffer; } serial.Close(); cout << "\n"; cout << "=========================================================\n"; cout << "getTristarLog aborted. \n\n"; return 0; }
void SerialCheck( char * port ) { CSerial serial; short status; const char * str=""; status=serial.CheckPort(_T(str)); switch (status) { case -1: // Unknown error occurred DM::Result("Unknown error.\n"); break; case 0: // Port is available DM::Result("Com port available.\n"); break; case 1: // Port is not present DM::Result("No such com port.\n"); break; case 2: // Port is in use DM::Result("COM port is already in use.\n"); break; } }
int WINAPI _tWinMain (HINSTANCE /*hInst*/, HINSTANCE /*hInstPrev*/, LPTSTR /*lptszCmdLine*/, int /*nCmdShow*/) { CSerial serial; LONG lLastError = ERROR_SUCCESS; // Attempt to open the serial port (COM1) lLastError = serial.Open(_T("COM1"),0,0,false); if (lLastError != ERROR_SUCCESS) return ::ShowError(serial.GetLastError(), _T("Unable to open COM-port")); // Setup the serial port (9600,N81) using hardware handshaking lLastError = serial.Setup(CSerial::EBaud9600,CSerial::EData8,CSerial::EParNone,CSerial::EStop1); if (lLastError != ERROR_SUCCESS) return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port setting")); // Setup handshaking lLastError = serial.SetupHandshaking(CSerial::EHandshakeHardware); if (lLastError != ERROR_SUCCESS) return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port handshaking")); // The serial port is now ready and we can send/receive data. If // the following call blocks, then the other side doesn't support // hardware handshaking. lLastError = serial.Write("1\n"); if (lLastError != ERROR_SUCCESS) return ::ShowError(serial.GetLastError(), _T("Unable to send data")); // Close the port again serial.Close(); return 0; }
// // Main Routine // int main(void) { #ifdef DEBUG CSerial ser; // declare a UART object ser.enable(); CDebug dbg(ser); // Debug stream use the UART object dbg.start(); #endif // // Your setup code here // CThread t(tskBlink); t.start("blink"); // start the blink task CPin led0(LED_PIN_0); // declare led0 on p0.18 led0.output(); // // Enter main loop. // while(1) { // // Your loop code here // led0.toggle(); // toggle the led0 sleep(500); } }
void Programming::sendResetCmd(CSerial &serial) { if(!serial.IsOpened()) { std::cout << "Serial is not connected" << std::endl; return; } char resetChar = '#'; serial.SendData(&resetChar, 1); }
//------------------------------------------------------------------------------ // close debug log file //------------------------------------------------------------------------------ SQRESULT SQ_debugLog_close (HSQUIRRELVM v) { if (serial.IsOpen()) { //fclose(gpDebugLogFile); serial.Close(); } return SQ_OK; }
// // main task // int main(void) { /************************************************************************* * * your setup code here * **************************************************************************/ // // LED Demo (can be removed) // DBG("Hello I'm in debug mode\n"); CBus leds(LED1, LED2, LED3, LED4, END); leds.output(); // set all pins as output usbCDC usb; usb.enable(); // enable USB core CSerial uart; uart.enable(115200); // enable serial port int i = 0; uint8_t ch; while(1) { /********************************************************************** * * your loop code here * **********************************************************************/ // // check uart input // if ( uart.readable() ) { // // // show led scripts leds = led_scripts[i]; i = (i+1) < (int)sizeof(led_scripts) ? i+1 : 0; usb << uart; // use CStream operator << } // // check usb input // if ( usb.readable() ) { ch = usb; // use CStream operator uint8_t uart << ch; // use CStream operator << } } return 0 ; }
int SerialWrite (char* str) { // The serial port is now ready and we can send/receive data. If // the following call blocks, then the other side doesn't support // hardware handshaking. lLastError = serial.Write(str); if (lLastError != ERROR_SUCCESS) return ::ShowError(serial.GetLastError(), _T("Unable to send data")); // if no error return 0; }
void TxByte(short number) { PLUG_IN_ENTRY char msg[1]; msg[1]=(char)(number); CSerial serial; serial.Write(_T(msg)); DM::Result("Sent byte.\n"); //DM::Result( DM::StringAppend(DM::StringAppend(DM::String("Sent byte: "), msg[1]), ".\n" )); PLUG_IN_EXIT }
// // main task // int main(void) { #ifdef DEBUG #if __USE_USB usbCDC ser; ser.connect(); #else CSerial ser; ser.settings(115200); #endif CDebug dbg(ser); dbg.start(); #endif /************************************************************************* * * your setup code here * **************************************************************************/ myBLE ble; ble.enable(); bleTest test(ble); CPin led(LED1); while(1) { /********************************************************************** * * your loop code here * **********************************************************************/ led = !led; sleep(100); if ( dbg.available() ) { switch(dbg.parseInt()) { case 0: DBG("BLE TEST OFF\n"); test.interface(BLE_TEST_OFF); break; case 1: DBG("BLE TEST OVER UART\n"); test.interface(BLE_TEST_OVER_UART); break; case 2: DBG("BLE TEST OVER ACI\n"); test.interface(BLE_TEST_OVER_ACI); } } } return 0 ; }
// // Main Routine // int main(void) { #ifdef DEBUG CSerial ser; // declare a UART object ser.enable(); CDebug dbg(ser); // Debug stream use the UART object dbg.start(); #endif // // PWM (Using Timer1) // hwPWM pwm1(TIMER_1, 5, 6, 7); // set pwm1 pins on P0.5 (CH1), P0.6 (CH2) and P0.7 (CH3) pwm1.period(0.0002); // period time = 200us pwm1.enable(); // enable PWM module // update pwm2 channels duty-cycle (can be updated in any-time) pwm1.dutycycle(PWM_CH_1, 0.8f); // CH1 duty-cycle = 80% pwm1.dutycycle(PWM_CH_2, 0.6f); // CH2 duty-cycle = 60% pwm1.dutycycle(PWM_CH_3, 0.2f); // CH3 duty-cycle = 20% // // PWM (Using Timer2) // hwPWM pwm2(TIMER_2, LED_PIN_1, LED_PIN_2); // set pwm2 pins on LED1 (CH1) and LED2 pwm2.period(0.0005); // period time = 500us pwm2.enable(); // enable PWM module // update pwm2 channels duty-cycle (can be updated in any-time) pwm2.dutycycle(PWM_CH_1, 0.8f); // CH1 duty-cycle = 80% pwm2.dutycycle(PWM_CH_2, 0.1f); // CH2 duty-cycle = 10% // // LED // CPin led(LED_PIN_0); led.output(); CTimeout tmLED; // // Enter main loop. // while(1) { // // FireFly loop // if ( tmLED.isExpired(500) ) { tmLED.reset(); led.toggle(); } } }
virtual void run() { while (1) { if (m_serial) { if (m_serial->readable()) { pxMBFrameCBByteReceived(); } if (m_serial->writeable()) { pxMBFrameCBTransmitterEmpty(); } } } }
int main(int argc, char *argv[]) { filename = "myFile.txt"; port = 5; baudRate = 9600; if(argc == 1) { cout << "No parameters specified, using defaults." << endl; cout << "To specify use DantecTraverse.exe [port [filename [baudRate]]]" << endl; } else if(argc >= 2) { port = fromString<int>(argv[1]); } else if(argc >= 3) { filename = argv[2]; } else if(argc >= 4) { baudRate = fromString<int>(argv[3]); } cout << "Parameters are: COM " << port << "; filename: \"" << filename << "\"; Baud Rate: " << baudRate << endl; if(!serialPort.Open(port, baudRate)) { cout << "Cannot open serial port " << port << " with Baud Rate " << baudRate << endl; throw 1; } while(1) { //checks if the file ends with a full stop on a seperate line, this signifies that YAPP is finished writing to the file ifstream iFile(filename.c_str()); string content((istreambuf_iterator<char>(iFile)), istreambuf_iterator<char>()); if(content.rfind("\n.") != string::npos) { cout << content << endl; doCommand(content); ofstream oFile(filename.c_str(), fstream::trunc); } int waiting = serialPort.ReadDataWaiting(); if(waiting) { char* buffer = new char[waiting]; serialPort.ReadData(buffer, waiting); string incomming = buffer; cout << "Incoming: " << buffer << endl; delete buffer; } } }
// // Main Routine // int main(void) { #ifdef DEBUG CSerial ser; // declare a UART object ser.enable(); CDebug dbg(ser); // Debug stream use the UART object dbg.start(); #endif // // Optional: Enable tickless technology // #ifndef DEBUG CPowerSave::tickless(true); #endif // // Your setup code here // CButton btn(BUTTON_PIN_0); CBuzzer buz(15); // buzzer on P0.15 buz.enable(); CPin led(LED_PIN_0); led.output(); CTimeout tmLED; // // Enter main loop. // while(1) { // // Your loop code here // switch(btn.isPressed()) { case BTN_PRESSED: buz.post(3); // turn on buzzer x 3 break; case BTN_RELEASED: break; case BTN_NOTHING: break; } if ( tmLED.isExpired(500) ) { tmLED.reset(); led.toggle(); } } }
void FlashTool::enterBootloader() { CSerial serial; if(!serial.Open(ui->ucPortBox->itemData(ui->ucPortBox->currentIndex()).toString())) { QMessageBox::critical(this, "Error", "Could not open serial port."); return; } serial.Setup(CSerial::EBaud115200); serial.SetupHandshaking(CSerial::EHandshakeOff); serial.SetEventChar(0x0D); int version; proto::SimplePacket<proto::CMD_INIT> init; for(version = 0; version <= proto::VERSION+10; ++version) { init.header.version = version; init.checksum = proto::packetChecksum(init.header, 0); serial.write(&init, sizeof(init)); if(serial.WaitEvent(200) == ERROR_SUCCESS) break; } proto::Packet<proto::CMD_RESET, proto::Reset> reset; reset.header.version = version; memcpy(&reset.payload.key, proto::RESET_KEY, sizeof(proto::RESET_KEY)); reset.updateChecksum(); serial.write(&reset, sizeof(reset)); }
void serial_sent_double(double input){ cout << " " << "\r"; //Find the Amount of Integer int int_digits = numDigits((int)input); //Cast to int then find //convert to CONST CHAR * with fixing 6 precision of decimal char tempChar[50]; int digits = int_digits + 1 + 6; snprintf(tempChar,50,"%f",input); //Transfer via Serial cout << "[Serial] Sending (double ) : " << tempChar << "\r"; serial.SendData(tempChar,digits); //Ending Seperator serial.SendData(",",1); Sleep(40); }
void sentMapToMSP(){ cout << "[Serial] Opening Serial Port Comm. . . . " <<endl; if (serial.Open(4, 9600)){ cout << "[Serial] Port opened successfully" << endl; }else{ cout << "[Serial] Failed to open port!" << endl; return ; } // send SOM_MAP to MSP 430 for(int i = 0 ; i < ROW ; i++ ){ for(int j = 0 ; j < COL ; j++ ){ for(int e = 0 ; e < element_count ; e++){ cout << "["<<i<<"]["<<j<<"]["<<e<<"]"; serial_sent_double(som_map[i][j].weights[e]); } } } for(int i = 0 ; i < ROW ; i++ ){ for(int j = 0 ; j < COL ; j++ ){ cout << "["<<i<<"]["<<j<<"]"; serial_sent_int(plotter[i][j]); } } }
int main(char argc, char *argv[]) { int port = 3, baudRate = 9600, dispType = 0; if (argc >= 2) port = atoi(argv[2]); if (argc >= 3) baudRate = atoi(argv[3]); if (argc >= 4) dispType = atoi(argv[4]); CSerial serial; if (!serial.Open(port, baudRate)) return 0; int curT=0, oldT=0; while (1) { curT = GetTickCount(); if (curT - oldT > 10) { char buffer[256]; int nBytesRead = serial.ReadData(buffer, sizeof(buffer)); if (nBytesRead > 0) { for (int i = 0; i < nBytesRead; ++i) { switch (dispType) { case 0: printf("%c", buffer[i]); break; case 1: printf("%d", buffer[i]); break; case 2: printf("%x", buffer[i]); break; } } printf("\n"); } oldT = curT; } } serial.Close(); return 1; }
void setup() { MyStepper.DelayOptimization = false; MyStepper.UseSpeedSign = true; MyStepper.CacheSize = 50000; MyStepper.InitTest("iRobot.csv"); Serial.SetIdle(Idle); }
void serial_sent_int(int input){ cout << " " << "\r"; //Find The Amount Of Digits int digits = numDigits(input); if(input == 0) digits = 1; //Convert to CONST CHAR * For transfer stringstream temp_str; temp_str << (input); string str = temp_str.str(); const char * tempChar = str.c_str(); //Transfer via Serial cout << "[Serial] Sending (integer) : " << tempChar << "\r"; serial.SendData(tempChar,digits); //Ending Seperator serial.SendData(",",1); Sleep(40); }
// // Main Routine // int main(void) { #ifdef DEBUG CSerial ser; // declare a UART object ser.enable(); CDebug dbg(ser); // Debug stream use the UART object dbg.start(); #endif // // Optional: Enable tickless technology // #ifndef DEBUG CPowerSave::tickless(true); #endif // // task 1 // static const SENSE_PARAM_T sense_t1 = {BUTTON_PIN_0, FALLING, LED_PIN_0}; // task parameters, Sense=P0.16, LED=LED0 CThread t1(senseTask, (xHandle) &sense_t1); t1.start("t1", 62, PRI_HARDWARE); // // task 2 // static const SENSE_PARAM_T sense_t2 = {BUTTON_PIN_1, TOGGLE, LED_PIN_1}; // task parameters, Sense=P0.17, LED=LED1 CThread t2(senseTask, (xHandle) &sense_t2); t2.start("t2", 62, PRI_HARDWARE); // // test pin // CPin test(15); test.output(); // // Enter main loop. // while(1) { // // Your loop code here // test.toggle(); // Use wire to connect the test pin to sense pin for test. } }
short RxByte( void ) { PLUG_IN_ENTRY char str[3]; CSerial serial; DWORD dwBytesRead = 0; short byte[1]; serial.Read(byte,1,&dwBytesRead); sprintf(str, "3.0f", byte); DM::Result("Received byte.\n"); //DM::Result( DM::StringAppend(DM::StringAppend(DM::String("Received byte: "), DM::String(str)), ".\n" )); return byte[1]; PLUG_IN_EXIT }
int SendData() { int i = 0; int count = 0; char ioControlBuffer[3]; char ioControl[3]; int bytesRecieved = 0; SerialPort.SendData("hgl", 3); while (true) { bytesRecieved = SerialPort.ReadData(ioControlBuffer, 1); ioControl[0] = ioControlBuffer[0]; printf("%c\t%d\t", ioControlBuffer[0], bytesRecieved); if (ioControl[0] == 'r') { for (i = 0; i <= NUMBER_OF_BUTTONS; i++) SerialPort.SendData(Controller[i].passedValue, sizeof(Controller[i].passedValue)); count++; if (count > 5) { Sleep(750); return 0; } } else if (ioControl[0] == 'q') { return 1; } else { printf("Error: Unknown codeword passed from arduino [%c], aborting send\n", ioControl[0]); } } }
// // main task // int main(void) { #ifdef DEBUG #if __USE_USB usbCDC ser; ser.connect(); #else CSerial ser; ser.settings(115200); #endif CDebug dbg(ser); dbg.start(); #endif /************************************************************************* * * your setup code here * **************************************************************************/ // start the GC Test Thread gcLED gc; gc.start("gc", 48); // send Pin to mailbox send_mail_test(); while(1) { /********************************************************************** * * your loop code here * **********************************************************************/ switch(dbg.isAnyKey()) { // // in DEBUG mode, press 'a' to test the 'auto_release_test()' // case 'a': auto_release_test(); break; } } return 0 ; }
// // Main Routine // int main(void) { #ifdef DEBUG CSerial ser; // declare a UART object ser.enable(); CDebug dbg(ser); // Debug stream use the UART object dbg.start(); #endif // // Optional: Enable tickless technology // #ifndef DEBUG CPowerSave::tickless(true); #endif // // Your setup code here // // m_semButton.counting(2, 2); m_semButton.binary(); CThread t1(tskLED1); t1.start("t1"); CThread t2(tskLED2); t2.start("t2"); // button CButton btn(BUTTON_PIN_0); // // Enter main loop. // while(1) { // // Your loop code here // if ( btn.isPressed()==BTN_PRESSED ) { m_semButton.release(); // signal the semaphore } } }
// // main task // int main(void) { #ifdef DEBUG #if __USE_USB usbCDC ser; ser.connect(); #else CSerial ser; ser.settings(115200); #endif CDebug dbg(ser); dbg.start(); #endif /************************************************************************* * * your setup code here * **************************************************************************/ // // LED Demo (can be removed) // uint8_t i = 0; CBus port(LED1, LED2, LED3, LED4, END); port.output(); // set all pins as output while(1) { /********************************************************************** * * your loop code here * **********************************************************************/ // // LED Demo (can be removed) // port = led_scripts[i]; i = (i+1) < (int)sizeof(led_scripts) ? i+1 : 0; sleep(100); } return 0 ; }
void FlashTool::updatePorts() { CSerial serial; ui->progPortBox->clear(); ui->ucPortBox->clear(); for(int i = 1; i < 50; ++i) { QString path = "\\\\.\\COM" + QString::number(i); if(serial.Open(path)) { ui->progPortBox->addItem("COM" + QString::number(i), path); ui->ucPortBox->addItem("COM" + QString::number(i), path); serial.close(); } } ui->progPortBox->addItem("usb (e.g. AVRISP mkII)", "usb"); }
int main(int, char**) { setup(); for(;;) { if (_kbhit()) { Serial._append((char)_getch()); } loop(); } }