📄 ds2wdlg.cpp
字号:
int dc = 0;
char buf[80];
m_EDIT_ADDR.GetWindowText(buf,3);
for(int count=0; count <=80; count++)
{
if((buf[count]>=48) && (buf[count]<=57))
data[dc] = (buf[count] - 48)*16;
else if(buf[count]>=65 && buf[count]<=70)
data[dc] = (buf[count]-55)*16;
else if(buf[count]>=97 && buf[count]<=102)
data[dc] = (buf[count]-87)*16;
else if(buf[count] == 0)
{
bytecount = dc;
break;
}
else
{
error = true;
break;
}
count++;
if(buf[count]>=48 && buf[count]<=57)
data[dc] += (buf[count] - 48);
else if(buf[count]>=65 && buf[count]<=70)
data[dc] += (buf[count]-55);
else if(buf[count]>=97 && buf[count]<=102)
data[dc] += (buf[count]-87);
else
{
error = true;
break;
}
dc++;
}
if(error == true)
{
MessageBox("Address Invalid");
}
else
{
for(int count = 0; count < bytecount; count++)
{
if(data[count]% 2 == 0)
{
success = Pic.WriteSlave2W(data[count]);
if (success == false)
{
m_EDIT_STATUS.SetWindowText("Write Address Failed");
MessageBox("Data TX Failed", "Error");
}
else
m_EDIT_STATUS.SetWindowText("Write Address");
}
else
MessageBox("Write Addresses Must Be Even Numbers", "Address Error");
}
}
}
void CDS2WDlg::OnWbyte1()
{ // writes the bytes out that are lised in the Wbyte1 edit box
CWaitCursor wait; // Scope of Wait Cursor Entire Function
bool success = false, error = false;
UCHAR data[8] = "GHIJKLM";
UCHAR bytecount = 0;
int dc = 0;
char buf[80];
m_EDIT_WBYTE1.GetWindowText(buf,17);
for(int count=0; count <=80; count++)
{
if((buf[count]>=48) && (buf[count]<=57))
data[dc] = (buf[count] - 48)*16;
else if(buf[count]>=65 && buf[count]<=70)
data[dc] = (buf[count]-55)*16;
else if(buf[count]>=97 && buf[count]<=102)
data[dc] = (buf[count]-87)*16;
else if(buf[count] == 0)
{
bytecount = dc;
break;
}
else
{
error = true;
break;
}
count++;
if(buf[count]>=48 && buf[count]<=57)
data[dc] += (buf[count] - 48);
else if(buf[count]>=65 && buf[count]<=70)
data[dc] += (buf[count]-55);
else if(buf[count]>=97 && buf[count]<=102)
data[dc] += (buf[count]-87);
else
{
error = true;
break;
}
dc++;
}
if(error == true)
{
MessageBox("Write Data Invalid");
}
else
{
for(int count = 0; count < bytecount; count++)
{
success = Pic.WriteSlave2W(data[count]);
if (success == false)
{
m_EDIT_STATUS.SetWindowText("Write Data Failed");
MessageBox("Data TX Failed", "Error");
}
else
m_EDIT_STATUS.SetWindowText("Write Data");
}
}
}
void CDS2WDlg::OnWbyte2()
{ // writes the bytes listed in wbyte2 edit box.
CWaitCursor wait; // Scope of Wait Cursor Entire Function
bool success = false, error = false;
UCHAR data[8] = "GHIJKLM";
UCHAR bytecount = 0;
int dc = 0;
char buf[80];
m_EDIT_WBYTE2.GetWindowText(buf,17);
for(int count=0; count <=80; count++)
{
if((buf[count]>=48) && (buf[count]<=57))
data[dc] = (buf[count] - 48)*16;
else if(buf[count]>=65 && buf[count]<=70)
data[dc] = (buf[count]-55)*16;
else if(buf[count]>=97 && buf[count]<=102)
data[dc] = (buf[count]-87)*16;
else if(buf[count] == 0)
{
bytecount = dc;
break;
}
else
{
error = true;
break;
}
count++;
if(buf[count]>=48 && buf[count]<=57)
data[dc] += (buf[count] - 48);
else if(buf[count]>=65 && buf[count]<=70)
data[dc] += (buf[count]-55);
else if(buf[count]>=97 && buf[count]<=102)
data[dc] += (buf[count]-87);
else
{
error = true;
break;
}
dc++;
}
if(error == true)
{
MessageBox("Write Data Invalid");
}
else
{
for(int count = 0; count < bytecount; count++)
{
success = Pic.WriteSlave2W(data[count]);
if (success == false)
{
m_EDIT_STATUS.SetWindowText("Write Data Failed");
MessageBox("Data TX Failed", "Error");
}
else
m_EDIT_STATUS.SetWindowText("Write Data");
}
}
}
void CDS2WDlg::OnCancel()
{ // exits program
CDialog::OnCancel();
}
void CDS2WDlg::OnStart()
{ // performs a 2-wire start
CWaitCursor wait; // Scope of Wait Cursor Entire Function
bool success = false;
success = Pic.Start2W();
if (success == false)
{
m_EDIT_STATUS.SetWindowText("Start Failed");
MessageBox("Start Failed", "Error");
}
else
m_EDIT_STATUS.SetWindowText("Start");
}
void CDS2WDlg::OnStop()
{ // performs a 2-wire stop
CWaitCursor wait; // Scope of Wait Cursor Entire Function
bool success = false;
bool state = true;
success = Pic.Stop2W();
if (success == false)
{
m_EDIT_STATUS.SetWindowText("Stop Failed");
MessageBox("Stop Failed", "Error");
}
else
m_EDIT_STATUS.SetWindowText("Stop");
}
void CDS2WDlg::OnRaddr()
{ // writes the 2-wire read address ADDR edit box + 1
CWaitCursor wait; // Scope of Wait Cursor Entire Function
bool success = false, error = false;
UCHAR data[8] = "GHIJKLM";
UCHAR bytecount = 0;
int dc = 0;
char buf[80];
m_EDIT_ADDR.GetWindowText(buf,3);
for(int count=0; count <=80; count++)
{
if((buf[count]>=48) && (buf[count]<=57))
data[dc] = (buf[count] - 48)*16;
else if(buf[count]>=65 && buf[count]<=70)
data[dc] = (buf[count]-55)*16;
else if(buf[count]>=97 && buf[count]<=102)
data[dc] = (buf[count]-87)*16;
else if(buf[count] == 0)
{
bytecount = dc;
break;
}
else
{
error = true;
break;
}
count++;
if(buf[count]>=48 && buf[count]<=57)
data[dc] += (buf[count] - 48);
else if(buf[count]>=65 && buf[count]<=70)
data[dc] += (buf[count]-55);
else if(buf[count]>=97 && buf[count]<=102)
data[dc] += (buf[count]-87);
else
{
error = true;
break;
}
dc++;
}
if(error == true)
{
MessageBox("Address Invalid");
}
else
{
for(int count = 0; count < bytecount; count++)
{
if(data[count] % 2 == 0)
{
success = Pic.WriteSlave2W(data[count]+1);
if (success == false)
{
m_EDIT_STATUS.SetWindowText("Read Address Failed");
MessageBox("Data TX Failed", "Error");
}
else
{
m_EDIT_STATUS.SetWindowText("Read Address");
}
}
else
MessageBox("Write Addresses Must Be Even Numbers", "Address Error");
}
}
}
void CDS2WDlg::OnFindAddress()
{ // Finds all responding 2-wire address, sets read/write address to last device found
CWaitCursor wait; // provide wait cursor for this function, scope is entire function
bool success;
CString Addresses = "The Following Addresses Were Found: ";
char temp[10];
UCHAR count = 0x00;
while(1)
{
Pic.Start2W();
success = Pic.WriteSlave2W(count);
if(success)
{
_itoa(count,temp,16);
if(temp[1]==0)
{
temp[2] = 0;
temp[1] = temp[0];
temp[0] = '0';
}
m_EDIT_ADDR.SetWindowText(temp);
Addresses = Addresses + temp;
Addresses = Addresses + "h ";
}
Pic.Stop2W();
if(count ==0xFE)
break;
else count+=2;
}
if(Addresses == "The Following Addresses Were Found: ")
Addresses = "No Addresses Found";
m_EDIT_STATUS.SetWindowText(Addresses);
}
void CDS2WDlg::OnResetBus()
{ // attempts to resets the 2-wire bus in the event
// that devices on the bus become confused.
CWaitCursor wait; // provide wait cursor for this function, scope is entire function
int success = 0;
success += Pic.ToggleSCL9x();
success += Pic.Stop2W();
if (success == 2)
m_EDIT_STATUS.SetWindowText("2-Wire Bus Reset");
else
MessageBox("2-Wire bus could not be reset","ERROR");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -