¥³¥á¥ó¥È¤Ï¤¢¤ê¤Þ¤»¤ó¡£ Comments/takada

¤ªÌ¾Á°:

2013/12/8 RFM12B(Èù¼å̵Àþ¥â¥¸¥å¡¼¥ë)¤ò»È¤Ã¤Æ¤ß¤¿

  • ÀèÀ¸¤Ë夤¤¿¥é¥¤¥Ö¥é¥ê¤ò¤¤¤¸¤Ã¤Æ¤ß¤¿
  • ̤´°À®Éôʬ(Åž춯Å٤η׻»¡¦ironeÍѤ˴°Á´arduino UNOÈ´¤­¤Ç¤ÎÄÌ¿®¡¦ÄÌ¿®µ÷Υ¬Äê)
  • ´°À®Éôʬ(¥Ç¡¼¥¿¤ÎÁ÷¿®¡¦¼õ¿®)
  • SPIÄÌ¿®¤Ë¤è¤Ã¤ÆÀ©¸æ¤¹¤ë¡£

­¡½àÈ÷¡§

¥Ç¡¼¥¿¥·¡¼¥È

http://www.hoperf.com/upload/rf/rfm12b.pdf

¥³¥Þ¥ó¥É

http://www.hoperf.com/upload/rf/rfm12b.pdf

¥³¥Þ¥ó¥ÉÁḫɽ¡¡

http://tools.jeelabs.org/rfm12b.html

http://www.sevenwatt.com/main/

ÅÅÇȶ¯ÅÙ¡¡

http://eleclog.quitsq.com/2011/11/rfm12b-radio-act.html

Arduino cookbook

https://www.inkling.com/read/arduino-cookbook-michael-margolis-2nd/chapter-14/recipe-14-6

¥Ñ¥±¥Ã¥ÈÆâÍÆ¡¡

http://lowpowerlab.com/blog/2012/12/28/rfm12b-arduino-library/#more-109

http://lowpowerlab.com/blog/2013/06/20/rfm69-library/

http://jeelabs.org/2011/12/11/inside-the-rf12-driver-part-2/

2¿Ê¿ô·×»»¡¡

http://hogehoge.tk/tool/number.html

Arduino¥Ô¥óÇÛÃÖ¡¡

http://wiki.onakasuita.org/pukiwiki/?Arduino%2F%E3%83%94%E3%83%B3%E9%85%8D%E7%BD%AE

­¢²óÏ©¡§

rfm_1.png

º£²ó¤Ï¤³¤ì¤é¤Ë²Ã¤¨¤ÆnINT/VDI, FSK/DATA/nFFS, DCLK/CFIL/FFIT, nRES¥Ô¥ó¤ò¥Þ¥¤¥³¥ó¤È·Ò¤¤¤À¡£ Arduino UNO¤Ï5V¤ÇÆ°ºî¤¹¤ë¤Î¤Ç¡¢RFM12B¤ËÆþ¤ë¿®¹æ¤òʬ°µ¤¹¤ë¡£¤É¤Î¿®¹æ¤¬Æþ¤ë¤«¤Ï¥Ç¡¼¥¿¥·¡¼¥È¤ÎDI¤ò¸«¤ë¤Èʬ¤«¤ë¡£

­£¥é¥¤¥Ö¥é¥ê¡§

  • RF12.cpp
 /*useful command: http://tools.jeelabs.org/rfm12b.html
 arduino¤ò»ÈÍѤ¹¤ë¤È¤­¤Ï16MHz¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤Î¤Ç/4(¥Ç¥Õ¥©¥ë¥È)¤Ë²Ã¤¨¤Æ/2¤Î¤Ëʬ°µ¤·¤Æ»È¤¦¡£(RFM12B¤¬  2.5MHz¤Þ¤Ç¤·¤«¼õ¤±ÉÕ¤±¤Ê¤¤ÀßÄê¤Î¤¿¤á)
 #define arduino
 ÀèÀ¸¤Î¥é¥¤¥Ö¥é¥ê¤«¤éÊѹ¹¤·¤¿²Õ½ê */
 #define changed
 /*commands*/
 #define SET_TX 0x8279
 #define SET_RX 0x82D9
 #define RESET 0x0000
 #define STATUS_CHECK 0x0000
 #define TX_SEND 0xB800 //+ data
 #define RX_RECEIVE 0xB000
 #define CONFIGURATION 0x80D7 // el(enable tx regigter), ef(enable FIFO) 12.0pF, 433MHz
 #define SET_FREQUENCY 0xA4B0 // 433MHz
 #define SET_DATARATE 0xC623 // 9.6kbps
 #define SET_PLL 0xCC17 // CLK=2.5MHz, !ddy ddit, PLL BW=256k
 #define RX_CONTROL 0x94C2 // VDI,FAST,67kHz,LNA=0dBm,RSSI=-91dBm 
 #define Data_Filter_Clock_Recovery 0xC2AC // AL,!ml,DIG,DQD4 
 #define FIFO_RESET_MODE 0xCA83 // FIFO8,2byte-SYNC,!AL,ff,DR
 #define TX_CONTROL 0x9850 // !mp,90kHz,MAX OUT TXpower=0(max)
 #define AUTO_FREQUENCY_CONTROL 0xC483 // @PWR,NO RSTRIC,!st,!fi,OE,EN 
 #define SET_WAKEUP_TIMER 0xE000 // wake up timer / NOT USE 
 #define SET_LOW_DUTY_CYCLE 0xC800 // low duty cycle / NOT USE//status
 #define SET_LOW_BATTERY_DETECT_uC_CLK 0xC049 // 1.66MHz,3.1V 
 #define SET_SYNC_PATTERN 0xCED4 // SYNC=2DD4
 //status
 #define TX_READY 0x8000
 #define FIFO_REACHED 0x8000
 //pin
 #define SPI_MOSI 11
 #define SPI_MISO 12
 #define SPI_SCK 13
 #include <pins_arduino.h>
 #include <avr/interrupt.h>
 #include <Arduino.h>
 #include <RF12.h>
 int nIRQ_pin, SS_pin, RST_pin;
 int mode;
 uint8_t RF12::spi_byte(uint8_t out) {
   SPDR = out;
   while (!(SPSR & _BV(SPIF)));
   return SPDR;
 }
 uint16_t RF12::xfer_byte(uint16_t cmd)
 {
 uint16_t dat = 0;
 digitalWrite(SS_pin, 0);
 dat = spi_byte(cmd >> 8) << 8;
 dat |= spi_byte(cmd);
 digitalWrite(SS_pin, 1);
 return(dat);
 }
 void RF12::send_byte(byte data)
 {
 uint16_t d;
 //  while(!((d = xfer_byte(0x0000)) & 0x8000)) Serial.println(d, HEX);
 //send 0000(status check). when returned 8000 TX is ready
 while(!(xfer_byte(STATUS_CHECK) & TX_READY)); // wait for TX ready
 xfer_byte(TX_SEND + data);
 delay(1);
 }
 //sending 1bit per time
 //would I need this?
 void RF12::send_data(byte *data, byte len)
 {
 byte cksum = 0;
 for (int i = 0; i < len; i++){
   send_byte(data[i]);
   cksum += data[i];
 }
 send_byte(cksum);
 }
 //wait(blocks) until it receives -> it's okay cuz used only for speaker
 #ifdef changed
 byte RF12::receive_byte()
 {
 //interrupt request output(from RFM12B), active low
	while(digitalRead(nIRQ_pin) == 1); // wait for any data received
 //status check, reset functions
 //xfer_byte(0x0000);
 // while(!(xfer_byte(0x0000) & 0x8000))Serial.println(xfer_byte(0x0000), HEX); // wait for RX ready
 //read 8 bits from the receiver FIFO (even if FIFO not used it still shares the same pin with RX(pin6))
 xfer_byte(RESET);
 return(xfer_byte(RX_RECEIVE));
 }
 #else
 byte RF12::receive_byte()
 {
 //interrupt request output(from RFM12B), active low
 while(digitalRead(nIRQ_pin) == 1); // wait for any data received
 //status check, reset functions
 xfer_byte(0x0000);
 //read 8 bits from the receiver FIFO (even if FIFO not used it still shares the same pin with RX(pin6))
 return(xfer_byte(0xB000));
 }
 #endif
 //needed to recaive less than a byte?
 byte *RF12::receive_data(byte *data, byte len)
 {
 int i;
 for (i = 0; i < len; i++){
   data[i] = receive_byte();
 }
 return(data);
 }
 void RF12::begin(uint8_t nIRQ, uint8_t SS, uint8_t RST)
 {
 nIRQ_pin = nIRQ;
 SS_pin = SS;
 RST_pin = RST;
 pinMode(RST_pin, INPUT);
 //  digitalWrite(RST_pin, 0);
 digitalWrite(SS_pin, 1);
 pinMode(SS_pin, OUTPUT);
 //digital 11,12,13 is fixed
 //faster when set it directly?
 #ifdef changed
 DDRB |= ((1<<DDB3)|(1<<DDB4)|(1<<DDB5));
 #else
 pinMode(SPI_MOSI, OUTPUT);
 pinMode(SPI_MISO, INPUT);
 pinMode(SPI_SCK, OUTPUT);
 #endif
 //need to make this smaller than 2.5MHz? arduino is 16MHz
 SPCR = _BV(SPE) | _BV(MSTR); // SPI master enable, Mode0
 #ifdef arduino
 SPSR |= _BV(SPI2X);
 #endif
 pinMode(nIRQ_pin, INPUT);
 digitalWrite(nIRQ_pin, 1); // pull-up, active low
 //status check for return and initialization
 xfer_byte(RESET); // intitial SPI transfer added to avoid power-up problem
 // wait until RFM12B is out of power-up reset, this takes several *seconds*
 //empty Tx buffer
 xfer_byte(TX_SEND); // in case we're still in OOK mode
 //reset again and again
 while (digitalRead(nIRQ_pin) == 0) xfer_byte(RESET);
 //yes, commands start
 //enable internal register and FIFO mode ---> why? needed for real time and 1 byte transmission?
 xfer_byte(CONFIGURATION); // el, ef 12.0pF, 433MHz 
 //fastest way it might be: turning on the whole receiver chain, synthesizer, and oscillator
 //I don't understand here according to datasheet
 #ifdef changed
 xfer_byte(0x82d9); // RX mode -> in case didn't set the mode?
 xfer_byte(SET_FREQUENCY); // 433MHz
 xfer_byte(SET_DATARATE); // 9.6kbps
 xfer_byte(SET_PLL); // CLK=2.5MHz, !ddy ddit, PLL BW=256k
 //especially here
 //xfer_byte(TX_CONTROL); // !mp,90kHz,MAX OUT TXpower=0(max)
 xfer_byte(RX_CONTROL); // VDI,FAST,67kHz,LNA=0dBm,RSSI=-91dBm 
 #else
 //receiver baseband circuite separately switched on
 xfer_byte(0x82d9); // RX mode -> in case didn't set the mode?
 xfer_byte(0xA640); // 437MHz (430+0.0025*(0x640)[MHz]) 
 xfer_byte(0xC647); // 4.8kbps
 xfer_byte(0xCC77); // CLK=2.5MHz, !ddy ddit, PLL BW=256k
 xfer_byte(0x94A2); // VDI,FAST,134kHz,LNA=0dBm,RSSI=-91dBm 
 #endif
 //Data Filter & Clock Recovery
 xfer_byte(Data_Filter_Clock_Recovery); // AL,!ml,DIG,DQD4 
 //FIFO and reset mode
 xfer_byte(FIFO_RESET_MODE); // FIFO8,2byte-SYNC,!AL,ff,DR 
 //Automatic Frequency Control
 xfer_byte(AUTO_FREQUENCY_CONTROL); // @PWR,NO RSTRIC,!st,!fi,OE,EN 
 //replaced----------------------------------------------------------------  
 //TX control
 xfer_byte(TX_CONTROL); // !mp,90kHz,MAX OUT TXpower=0(max)
 //------------------------------------------------------------------------
 xfer_byte(SET_WAKEUP_TIMER); // wake up timer / NOT USE 
 xfer_byte(SET_LOW_DUTY_CYCLE); // low duty cycle / NOT USE
 //Low Battery Detect and &#181;C Clock 
 xfer_byte(SET_LOW_BATTERY_DETECT_uC_CLK); // 1.66MHz,3.1V 
 //Synchronization Pattern
 xfer_byte(SET_SYNC_PATTERN); // SYNC=2DD4
 delay(1);
 }
 void RF12::set_tx_power(uint8_t pow)
 {
 //just setting the power on TX Configuration Command
 xfer_byte(TX_CONTROL + (pow & 0x07));
 }
 uint16_t RF12::read_status(void)
 {
 return(xfer_byte(STATUS_CHECK));
 }
 RF12::RF12(void)
 {
 }
 void RF12::set_mode(uint8_t md)
 {
	mode = md;
 //  xfer_byte(0x8239); // !er, !ebb,  et, es, ex, !eb, !ew, dc (for tx)
 //  xfer_byte(0x82D9); //  er,  ebb, !et, es, ex, !eb, !ew, dc (for rx)
 //new-------------------------------------------------------------------
	//xfer_byte(0x8279); // !er, ebb,  et, es, ex, !eb, !ew, dc (for tx)
 //  xfer_byte(0x82D9); //  er, ebb, !et, es, ex, !eb, !ew, dc (for rx)
 #ifdef changed
 if (md == RF12_MODE_TX) xfer_byte(SET_TX);
 else if (md == RF12_MODE_RX) xfer_byte(SET_RX);
 #else
 if (md == RF12_MODE_TX) xfer_byte(0x8239);
 else if (md == RF12_MODE_RX) xfer_byte(0x82d9);
 #endif
 }
 int RF12::available(void)
 {
 if (digitalRead(nIRQ_pin) == 0) return(1);
 else return(0);
 }
 -Á÷¼õ¿®¤Îino¥Õ¥¡¥¤¥ë
 Rx:
 #include <RF12.h>
 int RF12_SS = 10;
 int RF12_nIRQ = 9;
 int RF12_RST = 8;
 uint8_t payload[16];
 uint16_t pckt;
 RF12 rf12 = RF12();
 byte data;
 byte packet[16];
 void setup()
 {
 Serial.begin(9600);
 rf12.begin(RF12_nIRQ, RF12_SS, RF12_RST);
 rf12.set_mode(RF12_MODE_RX);
 Serial.println("Ready Rx");
 }
 int header = 4;
 int tail = 6;
 int index = 0, check = 0;
 void loop()
 {
 //uint8_t c;
	if (rf12.available()){
		data = rf12.receive_byte();
		if((data == 0xAA) || (data == 0x55)) ; else Serial.write(data);
	}
	//Serial.println();
 }
 Tx:
 #include <RF12.h>
 int RF12_SS = 10;
 int RF12_nIRQ = 9;
 int RF12_RST = 8;
 uint16_t payload[16];
 uint16_t c;
 RF12 rf12 = RF12();
 void setup()
 {
 Serial.begin(9600);
 pinMode(4, OUTPUT);
 rf12.begin(RF12_nIRQ, RF12_SS, RF12_RST);
 rf12.set_mode(RF12_MODE_TX);
 Serial.println("TX ready");
  c = '!'; 
 }
 void loop()
 {
	//packet format - only activating necessary parts for just 1 byte transmission
	//see http://jeelabs.org/2011/12/11/inside-the-rf12-driver-part-2/
	//or http://lowpowerlab.com/blog/2012/12/28/rfm12b-arduino-library/#more-109
	//for full packet information	
	//necessary part(5 bytes)
	//preamble
   rf12.send_byte(0xAA);
   rf12.send_byte(0xAA);
   rf12.send_byte(0xAA);
	//SYN-ox2d
   rf12.send_byte(0x2D);
	//SYN-network ID (network group (can be in the range 1-255) -> 212)
   rf12.send_byte(0xD4);
	//header
	//CTLflag + DestID(unique node ID of receiver (1 through 30) -> 85)
	//0 + 55
	//rf12.send_byte(c);
   rf12.send_byte(0x55);
	//ACK + SourceID(unique node ID of receiver (1 through 30))
	//1 + 42?
   rf12.send_byte(0xaa);
	//DataLength
   rf12.send_byte(0x55);
	//Data
   rf12.send_byte(0xaa);
   rf12.send_byte(c);	//CRC
	rf12.send_byte(c+1);
	rf12.send_byte(c+2);
   rf12.send_byte(0x55);
	//CRC
   rf12.send_byte(0xaa);
   rf12.send_byte(0x55);
   rf12.send_byte(0xaa);
   rf12.send_byte(0xaa);
   rf12.send_byte(0xaa);
   //Serial.println("Sent.");
	digitalWrite(4, HIGH);
	delay(250);
	digitalWrite(4, LOW);
	delay(250);
 //}
 }

Ãí°Õ¡§Serial.print¤ò»È¤¦¤ÈSerial¤¬¥Ï¥¤¤Ë¤Ê¤Ã¤Æ¤¤¤ë»þ¤Ë²¿¸Î¤«0¤òÆɤࡣ¤¹¤ë¤È¥Ó¥Ã¥È¤¬¤º¤ì¤ÆÃͤ¬¤ª¤«¤·¤¯¤Ê¤ë¤Î¤ÇSerial.write¤ò»È¤¦Êý¤¬Îɤ«¤Ã¤¿¡£(1byte¤ÎÄÌ¿®¤Ï¤³¤Á¤é¤ÎÊý¤¬¤¤¤¤¤È¤¤¤¦¤³¤È¤â½ñ¤¤¤Æ¤¢¤Ã¤¿) 100²ó¤Ë1²ó¤°¤é¤¤Ãͤò´Ö°ã¤¨¤ë¤³¤È¤¬¤¢¤ë¡£ ¾åµ­¥×¥í¥°¥é¥à¤ÎºÙ¤«¤¤ÆâÍƤˤĤ¤¤Æ¤Ï¸å¤Û¤É¹¹¿·Í½Äê

2013/12/8 Serial.print¤ÈSerial.write

  • »²¹Í: http://arduino.cc/en/Serial/write 1byte¤¢¤ë¤¤¤Ï¤½¤ì°Ê¾å¤Î¥Ð¥¤¥Èñ°ÌËè¤Ë¡¢Serial.write¤Ï¥Ð¥¤¥Ê¥ê¡¼¥Ç¡¼¥¿¤½¤Î¤Þ¤Þ¤ò¥·¥ê¥¢¥ë¥Ý¡¼¥È¤ËÁ÷¤ë¤é¤·¤¤¡£¢ª1byteËè¤Î¥Ç¡¼¥¿ÄÌ¿®¤Ë¤Ïwrite¤ÎÊý¤¬¤¤¤¤¤Î¤«¤â

2013/9/30 unsigned¤Ëµ¤¤ò¤Ä¤±¤ë

  • ¤¿¤À¤Îint¤Ç-¤¬¤Ä¤¯¤Î¤ÏÃͤ¬Â礭¤¤¾ì¹ç

2013/9/26 ATmega3238P¥Ö¡¼¥È¥í¡¼¥À¸å¤Î¥¹¥±¥Ã¥Á½ñ¤­¹þ¤ß¥á¥â

  • ¥ê¥»¥Ã¥È¥¹¥¤¥Ã¥Á¤Ë¤Ä¤±¤ë¥³¥ó¥Ç¥ó¥µ¤Ï0.1¦ÌF¤À¤È¾å¼ê¤¯¤¤¤¯¤±¤ì¤É¤â22pF¤À¤È½ñ¤­¹þ¤ß¤Ç¤­¤Ê¤¤(ÍÆÎ̤¬¾®¤µ¤¹¤®¤Æ¾å¼ê¤¯¥ê¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¤Î¤«¤â?)

2013/9/24 ATmega328P¤Î¥Ö¡¼¥È¥í¡¼¥À¡¼½ñ¤­¹þ¤ß¥á¥â(PU)

2013/9/23 ˺È÷Ï¿-Sparkfun.com MP3 Player Shield¤ò»È¤¦»þ¤Î¥Á¥å¡¼¥È¥ê¥¢¥ë»ØÄê¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Ê¤¤

  • Sparkfun.com MP3 Player Shield¤òUNO¤Ç»È¤¦»þ¤Ë¥¤¥ó¥¹¥È¡¼¥ë¤¹¤ë¥é¥¤¥Ö¥é¥ê¤Î¥Ô¥ó(SS¤ò10¢ª9)¤ËÊѹ¹¤·¤Ê¤¤¤È¤¤¤±¤Ê¤¤¡£
  • https://www.sparkfun.com/tutorials/295 ¤Î
    2_1.png
    ¡¡¤¬Â¸ºß¤·¤Ê¤¤¤Î¤Ç¤¹¤¬¡¢Arduino/libraries/SdFat/SdFatConfig.h¤Î°ìÈÖ²¼
    2_2.png
    ¡¡¤Ë¤¢¤ê¤Þ¤·¤¿¡£¤³¤³¤ÎCS¤ò10¢ª9¤ËÊѤ¨¤ë¤ÈÆ°¤­¤Þ¤·¤¿¡£

Eclipse¤ò»È¤Ã¤ÆJava¤Ç¥·¥ê¥¢¥ëÄÌ¿®

  • Æ°ºî´Ä¶­¡§Windows7 64bit
  • ¼ê½ç
 ­¡¥·¥ê¥¢¥ëÄÌ¿®¤ò¹Ô¤¤¤¿¤¤Eclipse¤Îpackage²¼¤ËÄɲå饤¥Ö¥é¥êÍѤΥե©¥ë¥À¤òºî¤ë¡Ê̾Á°¤Ï²¿¤Ç¤â¤¤¤¤¤±¤É¼Ì¿¿¤Ç¤Ïlib¡Ë
1.png
 ­¢ÄɲÃÍѤΥ饤¥Ö¥é¥ê¤ò¥¤¥ó¥¹¥È¡¼¥ë

¡¡¡¡¤³¤Î¥Õ¥©¥ë¥À¤ò²òÅष¤¿Ãæ¤Î¡¢

¡¡¡¡¡¡rxtxParallel.dll

¡¡¡¡¡¡rxtxSerial.dll

¡¡¡¡¡¡RXTXcomm.jar

¡¡¡¡¤ò¥³¥Ô¡¼¤·¤Æ¡¢­¡¤Î¥Õ¥©¥ë¥ÀÆâ¤Ë¥Ú¡¼¥¹¥È

  • ¤â¤·¤â¥Ñ¥½¥³¥ó¼«ÂΤ˥¤¥ó¥¹¥È¡¼¥ë¤·¤¿¤¤¾ì¹ç¤Ï¡¢Program FilesÆâ¤ÎJava¥Õ¥¡¥¤¥ë¤Î¥é¥¤¥Ö¥é¥ê¤ËÆþ¤ì¤ë¡Ê¤ä¤Ã¤Æ¤Ê¤¤¤Î¤ÇÆ°¤¯¤«¤ÏÉÔÌÀ¡Ë
 ­£Eclipse¤ÇLibrary  Path¤òÄɲ乤ë
  • Eclipse¤òµ¯Æ°
  • ¤Þ¤º¡¢¿·¤·¤¯ºî¤Ã¤¿¥Õ¥©¥ë¥À¤¬Æþ¤Ã¤Æ¤¤¤ëPackage̾¤ò±¦¥¯¥ê¥Ã¥¯¤·¤Æ¡¢Refresh¤òÁªÂò¡£¡Ê¤Þ¤¿¤Ï¡¢Package̾¤òÁªÂò¸å¡¢F5¤ò²¡¤¹¡£¡Ë ¡¡¡¡ ¤³¤ì¤Ç¡¢¿·¥Õ¥©¥ë¥À¤¬Package¤ËÃç´ÖÆþ¤ê¡£ ¡¡
  • Project¥¿¥Ö¤ÎProperties¤ò¥¯¥ê¥Ã¥¯¤¹¤ë¡£Properties¤Îº¸¤ËJava Build Path¤¬¤¢¤ë¤Î¤Ç¥¯¥ê¥Ã¥¯¡£
  • Libraries¥¿¥Ö¤ò¥¯¥ê¥Ã¥¯¡£Add Jars...¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¡¢­¡¤Çºî¤Ã¤¿¥Õ¥©¥ë¥ÀÆâ¤ÎRXTXcomm.jar¤òÁªÂò¡£
    2.png
  • ¤³¤ì¤ÇÀßÄê¤Ï´°Î»¡£¤¢¤È¤Ï¥×¥í¥°¥é¥à¤ò½ñ¤¯¤Î¤ß¡£
 ­¤¥×¥í¥°¥é¥àºîÀ®
  • CommLight.java¡Ê¥á¥¤¥ó¤¬¤¢¤ë¥Õ¥¡¥¤¥ë¡Ë
     //port check
     //JDK check
     import java.io.*;
     public class CommLight{
    	static File sharedText;
    	
    	public static void main(String[] args){
           
           SerialComm serialcomm = new SerialComm();
           serialcomm.open();
           int i = 10;
           while(i>0){
           	serialcomm.write((byte)0x34);
           	try{
               	Thread.sleep(500);
               }catch(Exception e){
               	
               }
               serialcomm.write((byte)0x20);
               try{
               	Thread.sleep(500);
               }catch(Exception e){
               	
               }
               serialcomm.write((byte)0x78);
               try{
               	Thread.sleep(500);
               }catch(Exception e){
               	
               }
               i--;
           }
    		System.out.println("Hello, World");
    	}
    }
  • SerialComm.java
     import gnu.io.*;
     import java.io.*;
     import java.util.*;
     public class SerialComm implements SerialPortEventListener{
    	private SerialPort port;
     //	private static BufferedReader reader;
    	private InputStream in;
    	private OutputStream out;
    	SerialComm(){
    		super();
    	}
    	public void open(){
    		try {
    			// Serial port initialize
    			CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier("COM6");
    			port = (SerialPort)portId.open("USB Serial Port", 2000);
    			port.setSerialPortParams(
    					9600,					 // &#237;&#160;&#234;M&#235;¡¯&#236;x[bps]
    					SerialPort.DATABITS_8,   // &#201;f&#197;[&#201;^&#201;r&#201;b&#201;g&#234;&#238;
    					SerialPort.STOPBITS_1,   // &#201;X&#201;g&#201;b&#201;v&#201;r&#201;b&#201;g
    					SerialPort.PARITY_NONE   // &#201;p&#201;&#228;&#201;e&#201;B
    					);
    			port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
    			try{
    				port.addEventListener(this);
    				port.notifyOnDataAvailable(true);
    				
    				in = port.getInputStream();
    				out = port.getOutputStream();
    			}catch(TooManyListenersException ex){
    				System.out.println("Error1: "+ex);
    			}
    		} catch (Exception e) {
    			System.out.println("Error2: " + e);
    			System.exit(1);
    		}
    	}
    	public void close(){
    		try{
    			in.close();
    			out.close();
    			port.close();
    		}catch(Exception e){
    			System.out.println("close: "+e);
    		}
    	}
    	public void read(){
    		try{
    			byte[] buffer;
    			int temp = in.available();
    			if(temp>0){
    				System.out.println("temp: "+temp);
    				buffer = new byte[temp];
    				temp = in.read(buffer);
    				int num = 0;
    				while(num<temp){
    					System.out.println("b "+num+": "+Integer.toHexString((byte)buffer[num]));
    					num++;
    				}
    			}
    			in.close();
    		}catch(Exception e){
    			System.out.println("error4: "+e);
    		}
    	}
    	public static String toHex(byte[] digest) {
    		StringBuilder sb = new StringBuilder();
    		for (byte b : digest) {
    			sb.append(String.format("%1$02X", b));
    		}
    		return sb.toString();
    	}
    	public void write(byte data){
    		try{
    			out.write((byte)data);   
    			out.flush();
    			//&#201;X&#201;g&#201;&#228;&#197;[&#201;&#196;&#199;&#8710;COM&#201;|&#197;[&#201;g&#199;&#63743;&#239;¢Ì&#199;¢ß&#199;&#200;&#232;&#224;&#243;&#249;
    		}catch(Exception e){
    			System.out.println("port exception: "+e);
    		}
    	}
    	public void run() {
    		try {
    			InputStreamReader isr = new InputStreamReader(System.in);
    			BufferedReader br = new BufferedReader(isr);
    			OutputStream out = port.getOutputStream();
    			boolean flagQuit = false;
    			while (!flagQuit) {
    				String input = br.readLine();
    				if (input.length() > 0) {
    					if (input.equals(":quit"))
    						break;
    					input += "\r";
    					out.write(input.getBytes("US-ASCII"));
    				}
    			}
    			port.close();
    		} catch (Exception e) {
    			System.out.println("Error3: " + e);
    		}
    	}
    	public void serialEvent(SerialPortEvent event) {
    		if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
    			read();
    		}
    	}
     }
 ­¥´°À®