S.N.A.K.E.: A Dynamically Reconfigurable Artificial Sensate Skin ...
S.N.A.K.E.: A Dynamically Reconfigurable Artificial Sensate Skin ...
S.N.A.K.E.: A Dynamically Reconfigurable Artificial Sensate Skin ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
10<br />
c:\Documents and Settings\Gerardo\My ... (MIT)\Thesis\Code\Example1\USBtestDlg.cpp<br />
9<br />
while (fscanf(codeFile, "%*1s %2x %2x %2x %*2x", &nBytes, &address[0],&address[1])<br />
!= EOF)<br />
{<br />
if (nBytes != 0)<br />
{<br />
fileBuf[index]=(char)nBytes;<br />
fileBuf[index+1]=(char)address[0];<br />
fileBuf[index+2]=(char)address[1];<br />
index+=3;<br />
for (i=0; i < nBytes; i++)<br />
{<br />
lBytesRead = fscanf(codeFile, "%2x", &data[i]);<br />
fileBuf[index+i]=(char)data[i];<br />
}<br />
lBytesRead = fscanf(codeFile, "%2x", &checkSum);<br />
fileBuf[index+i]=(char)checkSum;<br />
index+=i+1;<br />
}<br />
else lBytesRead = fscanf(codeFile, "%*x", &nBytes);<br />
}<br />
//Close file<br />
fclose(codeFile);<br />
c:\Documents and Settings\Gerardo\My ... (MIT)\Thesis\Code\Example1\USBtestDlg.cpp<br />
m_PortStatus = _T("-reset-");<br />
UpdateData(FALSE);<br />
UpdateWindow();<br />
Close();<br />
//open the device<br />
FT_STATUS status = OpenBy();<br />
if(status>0)<br />
{<br />
m_PortStatus = _T("Brain not found!");<br />
board_present=0;<br />
}<br />
else<br />
{<br />
status=ResetDevice();<br />
status=Purge(FT_PURGE_RX || FT_PURGE_TX);<br />
status=ResetDevice();<br />
SetTimeouts(3000, 3000);//extend timeout while board finishes reset<br />
Sleep(150);<br />
//Configure File Buffer<br />
if(m_Nodes) fileBuf[0]=REFLASH_DEV_INST;<br />
else fileBuf[0]=REFLASH_ALL_INST;<br />
//test for presence of board<br />
txbuf[0] = 0x80;<br />
Write(txbuf, 1, &ret_bytes);<br />
//Read(rxbuf, 1, &ret_bytes);<br />
//if(ret_bytes==0)//if no response maybe windows was busy... read it again<br />
// Read(rxbuf, 1, &ret_bytes);<br />
//Flush Buffer<br />
FT_STATUS status=Purge(FT_PURGE_RX || FT_PURGE_TX);<br />
m_PortStatus = _T("Brain Ready!");<br />
Buttons(ON);//turn em off till a port is active<br />
board_present=1;<br />
//Send frame<br />
Write(fileBuf, index, &ret_bytes);<br />
}<br />
}<br />
void CUSBtestDlg::OnButtonReset()<br />
{<br />
DWORD ret_bytes;<br />
unsigned char txBuf=RESET_BRAIN_INST;<br />
unsigned char* instnBuf=&txBuf;<br />
Purge(FT_PURGE_RX || FT_PURGE_TX);<br />
//Send Reset Instruction<br />
FT_STATUS status = Write(instnBuf, 1, &ret_bytes);<br />
if (status != FT_OK) MessageBox("Error Sending Instruction");<br />
}<br />
SetTimeouts(300, 300);<br />
UpdateData(FALSE);<br />
UpdateWindow();<br />
}<br />
void CUSBtestDlg::OnButtonSendFile()<br />
{<br />
DWORD ret_bytes;<br />
FILE *codeFile;<br />
CString FileName="";<br />
UINT lBytesRead=0, nBytes, address[2], data[16], checkSum, i, index=1;<br />
unsigned char fileBuf[1000];<br />
}<br />
void CUSBtestDlg::OnButtonRs()<br />
{<br />
DWORD ret_bytes;<br />
unsigned char txBuf[3];<br />
int txBytes=1;<br />
//Ask user for the code file<br />
CFileDialog FileOpenDlg(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,"MSP430 Compiled Code (*.<br />
a43)|*.a43|All Files (*.*)|*.*||");<br />
int iRet = FileOpenDlg.DoModal();<br />
FileName = FileOpenDlg.GetFileName();<br />
Purge(FT_PURGE_RX || FT_PURGE_TX);<br />
//Send Reset Instruction<br />
//if (m_Nodes)<br />
//{<br />
// txBuf[1]=(BYTE)R_Add;<br />
// txBuf[2]=*((char*)&R_Add+1);<br />
// txBuf[0]=RESET_DEV_INST;<br />
// txBytes = 3;<br />
//}<br />
//else<br />
txBuf[0]=RESET_SKIN_INST;<br />
FT_STATUS status = Write(txBuf, txBytes, &ret_bytes);<br />
if (status != FT_OK) MessageBox("Error Sending Instruction");<br />
// TODO: Add your control notification handler code here<br />
if(iRet == IDOK)<br />
{<br />
m_Received.ResetContent();<br />
//Open The File<br />
codeFile = fopen(FileOpenDlg.GetPathName(), "r");<br />
}<br />
if (m_Nodes)<br />
{<br />
fileBuf[1]=(BYTE)R_Add;<br />
fileBuf[2]=*((char*)&R_Add+1);<br />
index+=2;<br />
}<br />
//Parse text file