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 );

    
    
    
}
示例#2
0
void at_sockwrite_wnc(const char * s)
{
  string * pRespStr;
  char num2str[6];
  size_t sLen = strlen(s);
  if (sLen <= 99999)
  {
    string cmd_str("AT@SOCKWRITE=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");
}
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
示例#4
0
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");
}
示例#5
0
void sendRollCommand(char ch,int pre)
{
    rollComm.preamble = pre;
    //command.info_byte = 0b00000000;
    rollComm.ch = ch;
    sPort.Write(&rollComm, sizeof(rollCommand));
}
示例#6
0
/* 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);
    }

}
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;
}
示例#8
0
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]);
        }
    }
}
示例#9
0
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();
	}
}
示例#10
0
/** 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);
    }
}
示例#11
0
/*
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;
}
示例#12
0
BOOL APIENTRY DllMain(HMODULE /*module*/, DWORD reason_for_call, LPVOID /*reseved*/)
{
  if (reason_for_call == DLL_PROCESS_DETACH)
  {
		serial_port.close();
	}
	return TRUE;
}
示例#13
0
void send_empty_packet()
{
  memset(packet, 0, PACKET_MAX_SIZE); 
  packet[0] = PACKET_SYNC;
  packet[1] = PACKET_VER;
  
  serial_port.write(packet, 16);
}
示例#14
0
void sendCommand(Robot_Config myRobot,int pre)
{
    command.preamble = pre;
    command.info_byte = 0b00000000;
    command.myRobot = myRobot;

    sPort.Write(&command, sizeof(botPacket));
}
示例#15
0
SCSAPI_VOID scs_telemetry_shutdown(void)
{
  send_empty_packet();
  serial_port.close();

  game_log(SCS_LOG_TYPE_message, "Plugin shutdown");
	game_log = NULL;
}
示例#16
0
void node::sensorVccOff(int sensorNum)
{
    if (sensorNum <= 5) {
        return mySensors[sensorNum - 1]->sensorOff();
    } else {
        pc.printf("Sensor number %d is invalid", sensorNum);        
    }
}
示例#17
0
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();
}
示例#18
0
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;
}
示例#19
0
void SDHandler::_dirTest() {
#if DEBUG_LOGGING
  std::string path = "/sd/";
  _filenames = _read_directory(path);
  for(vector<std::string>::iterator it = _filenames.begin(); it < _filenames.end(); it++) {
    BT.printf("%s\n", (*it).c_str());
  }
#endif
}
/**
 * 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;
}
示例#21
0
文件: main.cpp 项目: DavidUser/BEmbed
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
		}
	}
}
示例#22
0
/* 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);
}
示例#23
0
int node::sensorVccState(int sensorNum)
{
    if (sensorNum <= 5) {
        return mySensors[sensorNum - 1]->sensorState();
    } else {
        pc.printf("Sensor number %d is invalid", sensorNum);
        return 10000;
    }
}
int read(char addr, char reg, char *buf, int n)
{
    i2c.start();
    if (set_i2c_pointer(addr, reg) == 0)
    {
        if (DEBUG)
            pc.printf("Could not set i2c pointer (read)\r\n");
        return 0;
    }
    if (i2c.read(addr|1, buf, n, true) != 0)
    {
        if (DEBUG)
            pc.printf("Could not execute read sequence (read)\r\n");
        return 0;
    }
    i2c.stop();
    return n;
}
示例#25
0
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));
}
/*The main loop*/
void draw()
{      
  //write X pixel data to serial
  //for (int y=0;y<48;y++) {   ***Don't actually need to increment y right now b/c it is incremented
  //                              the correct amount below in the fullR loop -- which is convenient!   
  if (ack) {
    myPort.write(101);
    for (int x=0;x<cols;x++) {
      //get pixel, extract rgb vals from pixel using bit shifting (faster)
      color rgb = img.pixels[y*cols + x];
      int r = rgb >> 16 & 0xFF; //Equivalent to, but faster than red(rgb)
      int g = rgb >> 8 & 0xFF;
      int b = rgb & 0xFF;
      myPort.write(r);
      myPort.write(g);
      myPort.write(b);
      println("Sent " + x);
      //delay(50);
    }
    // for (int x=0;x<10;x++)
    //      myPort.write(255);
    //set this to wait for another request 
    ack = false;
  }
  //if a full packet has been received, print to screen
  if (fullR)
  { 
    for (int i=1; i<dataIn.length; i++)
    {    
      System.out.println("R " + dataIn[i][0] + " G " + dataIn[i][1] + " B" + dataIn[i][2]);
    }  
    fullR = false;
    for (int x=1; x<dataIn.length; x++)
    {
      fill(dataIn[x][0], dataIn[x][1], dataIn[x][2]);
      //stroke(255);
      rect((x-1)*5, y*5, 5, 5);
    }
    y+=1;
    System.out.println(y);
  }
}//end loop
示例#27
0
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;
}
// disable accelerometer to save power
int accelerometer_standby()
{
    char power_ctl;
    int ret = read(accel_w, ACCEL_POWER_CTL, &power_ctl, 1);
    if (ret == 0)
    {
        if (DEBUG)
            pc.printf("Error putting accelerometer in standby (accelerometer_standby)\r\n");
        return 0;
    }
    power_ctl &= 0xF7 ;
    ret = write(accel_w, ACCEL_POWER_CTL, &power_ctl, 1);
    if (ret == 0)
    {
        if (DEBUG)
            pc.printf("Error putting accelerometer in standby (accelerometer_standby)\r\n");
        return 0;
    }
    return 1;
}
// enable accelerometer for measurements
int accelerometer_measure()
{
    char power_ctl;
    int ret = read(accel_w, ACCEL_POWER_CTL, &power_ctl, 1);
    if (ret == 0)
    {
        if (DEBUG)
            pc.printf("Error putting accelerometer in measure mode (accelerometer_measure)\r\n");
        return 0;
    }
    power_ctl |= 0x8 ;
    ret = write(accel_w, ACCEL_POWER_CTL, &power_ctl, 1);
    if (ret == 0)
    {
        if (DEBUG)
            pc.printf("Error putting accelerometer in measure mode (accelerometer_measure)\r\n");
        return 0;
    }
    return 1;
}
int gyro_turnoff()
{
    char power_ctl;
    int ret = read(gyro_w, GYRO_CTRL_REG1, &power_ctl, 1);
    if (ret == 0)
    {
        if (DEBUG)
            pc.printf("Error turning off gyro (gyro_turnoff)\r\n");
        return 0;
    }
    power_ctl &= 0xF7 ;
    ret = write(gyro_w, GYRO_CTRL_REG1, &power_ctl, 1);
    if (ret == 0)
    {
        if (DEBUG)
            pc.printf("Error turning off gyro (gyro_turnoff)\r\n");
        return 0;
    }
    return 1;
}