コード例 #1
0
ファイル: SerialReader.cpp プロジェクト: boblucas/Miller
void parseRequest(const char* line)
{
	readingRequest = false;
	int code = parseNumber(line);
	switch(code)
	{
	case POSITION: //return position
		Serial.write('X');
		Serial.write( ((double)axis[0].position) / PULSES_PER_MM);
		Serial.write('Y');
		Serial.write( ((double)axis[1].position) / PULSES_PER_MM);
		Serial.write('Z');
		Serial.println( ((double)axis[2].position) / PULSES_PER_MM);
		break;
	case DESTINATION: //return destination
		Serial.write('X');
		Serial.write( ((double)axis[0].expected) / PULSES_PER_MM);
		Serial.write('Y');
		Serial.write( ((double)axis[1].expected) / PULSES_PER_MM);
		Serial.write('Z');
		Serial.println( ((double)axis[2].expected) / PULSES_PER_MM);
		break;
	case PAUSE:
		serialSleepDelegate();
		break;
	case CONTINUE:
		serialWakeDelegate();
		break;
	}
}
コード例 #2
0
template<class T> int writeObject(HardwareSerial ser, T& value, char name) {
	unsigned char* p = (unsigned char*) (void*) &value;
	unsigned int i;
	char checksum = '0';
	ser.write('@');
	ser.write(name);
	for (i = 0; i < sizeof(value); i++) {
		ser.write(*p++);
		checksum = checksum ^ *p;
	}
	ser.write(checksum);
	ser.write('\n');
	return i;

}
コード例 #3
0
ファイル: usb_to_serial.cpp プロジェクト: ve3wwg/teensy3_lib
int
main(int argc,char **argv) {

	pinMode(led_pin, OUTPUT);
	digitalWrite(led_pin, led_off);
	digitalWrite(reset_pin, HIGH);
	pinMode(reset_pin, OUTPUT);
	Serial.begin(baud);	// USB, communication to PC or Mac
	Uart.begin(baud);	// UART, communication to Dorkboard

	for (;;) {
		unsigned char c, dtr;
		static unsigned char prev_dtr = 0;

		if (Serial.available()) {
			c = Serial.read();
			Uart.write(c);
			digitalWrite(led_pin, led_on);
			led_on_time = millis();
			continue;
		}
		if (Uart.available()) {
			c = Uart.read();
			Serial.write(c);
			digitalWrite(led_pin, led_on);
			led_on_time = millis();
			continue;
		}
		dtr = Serial.dtr();
		if (dtr && !prev_dtr) {
			digitalWrite(reset_pin, LOW);
			delayMicroseconds(250);
			digitalWrite(reset_pin, HIGH);
		}
		prev_dtr = dtr;
		if (millis() - led_on_time > 3) {
			digitalWrite(led_pin, led_off);
		}
		if (Serial.baud() != baud) {
			baud = Serial.baud();
			if (baud == 57600) {
				// This ugly hack is necessary for talking
				// to the arduino bootloader, which actually
				// communicates at 58824 baud (+2.1% error).
				// Teensyduino will configure the UART for
				// the closest baud rate, which is 57143
				// baud (-0.8% error).  Serial communication
				// can tolerate about 2.5% error, so the
				// combined error is too large.  Simply
				// setting the baud rate to the same as
				// arduino's actual baud rate works.
				Uart.begin(58824);
			} else {
				Uart.begin(baud);
			}
		}
	}
}
コード例 #4
0
ファイル: controlino.cpp プロジェクト: FatihZor/instrumentino
/***
 * SerReceive [hard | soft] [port]
 *
 * Empty the RX buffer of a serial port to the control serial port
 */
void cmdSerReceive(char **argV) {
	boolean isSoftSerial = (strcasecmp(argV[1], "soft") == 0);
	int currPort = strtol(argV[2], NULL, 10);

	if (currPort < 1 || currPort > (isSoftSerial)? SOFT_SER_MAX_PORTS : HARD_SER_MAX_PORTS) {
		return;
	}

	if (isSoftSerial) {
#ifdef USE_SOFTWARE_SERIAL
		for (int i = 0; i < softSerDescs[currPort-1].rxMsgLen && i < SOFT_SER_MSG_SIZE; i++) {
			Serial.write(softSerDescs[currPort-1].rxMsg[i]);
		}
#endif
	} else {
#if HARD_SER_MAX_PORTS > 0
		while (hardSerHandler[currPort-1]->available()) {
			Serial.write(hardSerHandler[currPort-1]->read());
		}
#endif
	}
}