Please see TEP 113 ( http://www.tinyos.net/tinyos-2.x/doc/html/tep113.html ) on mote-to-PC serial communication. You're trying to send the raw tos message structure over the serial link, which will not work. You will need to comply with the protocol and framing described in TEP 113.
Janos 2010/2/6 LiGang <[email protected]>: > Hi all, > > I am trying to send control command from PC to mote by UART. The program run > on PC was written in C#, but it seems that my note cannot switch to case > CMD_TYPE_GETSAMPLE. > Maybe this because my CRC field is 0? > Thanks in advance!!! > > According to TOS_Msg struct, my C# code is: > > //GetSample Command (struct) is encapsulated in TOS_Msg struct. > > //TOS_Msg struct: > > > //|<---addr--->|<---type--->|<---group--->|<---Len--->|<---data[TOSH_DATA_LENGTH]--->|<---CRC--->| > > // 2 bytes 1 byte 1 byte 1 > byte Byte array up to 29 bytes 2 bytes > // 0x007e > (126) 08 0x7d (125) 09 GetSample > Command (9 bytes) 00 > > //GetSample Command (struct): > > > //|<---wSrcAddr--->|<---wDesAddr--->|<---wSenderAddr--->|<---wNextIoAddr--->|<---bCmdType--->| > > // 2 bytes 2 bytes 2 > bytes 2 bytes 1 byte > // 0x007e > 1 1 > 0 2 > > Byte[] TOS_Msg_ = new Byte[16] { 00, 126, 08, 125, 09, 00, 126, 00, > 01, 00, 00, 00, 00, 02, 00, 00 }; > ........ > private void Form1_Load(object sender, EventArgs e) > { > serialPort1.PortName = "COM3"; > serialPort1.BaudRate = 115200; > serialPort1.DataBits = 8; > serialPort1.StopBits =System.IO .Ports .StopBits .One; > serialPort1.Parity =System.IO.Ports .Parity .None; > } > ...... > serialPort1.Write (TOS_Msg_,0,16); > > My main Mote code is: > // Msg type ID > enum > { > AM_MOTE_MSG =8, > }; > // CMD types > enum > { > CMD_TYPE_GETSAMPLE =2, > }; > // CMD structs > typedef struct _CMDGETSAMPLE > { > uint16_t wSrcAddr; > uint16_t wDestAddr; > uint16_t wSenderAddr; > uint16_t wNextIoAddr; > uint8_t bCmdType; > } CMDGETSAMPLE, *LPCMDGETSAMPLE; > > /******************************************** > * Task to evaluate a command and execute it if it is a supported command. > * @return Return: None > ********************************************/ > TOS_MsgPtr m_pCurrentMsg; > task void cmdInterpret() > { > LPCMDGETSAMPLE pCmdGetSample; > // Check > if(m_pCurrentMsg==NULL) > return; > > pCmdGetSample=(LPCMDGETSAMPLE)(m_pCurrentMsg->data); > switch(pCmdGetSample->bCmdType) > { > ....... > case CMD_TYPE_GETSAMPLE: > call Leds.greenOn(); > break; > > } > > // Inform CommRecv to free m_pCurrentMsg > call CommRecv.recvDone(m_pCurrentMsg, SUCCESS); > } > > /******************************************** > * Called upon message reception > * @return Returns a pointer to a TOS_Msg buffer > ********************************************/ > event result_t CommRecv.recv(TOS_MsgPtr pMsg) > { > m_pCurrentMsg=pMsg; > post cmdInterpret(); > > return SUCCESS; > } > } // end of implementation > > > > > _______________________________________________ > Tinyos-help mailing list > [email protected] > https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help > _______________________________________________ Tinyos-help mailing list [email protected] https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
