📄 demo.c
字号:
#ifdef S7_300
buffer_byte[i+1] = (unsigned char)((value >> 8) & 0xff);
buffer_byte[i+0] = (unsigned char)(value & 0xff);
i = i+2;
#endif
}
if ((char)datatype == 'z')
{
#ifdef S7_200
buffer_byte[i+0] = 0;
buffer_byte[i+1] = (unsigned char)((value >> 8) & 0xff);
buffer_byte[i+2] = (unsigned char)(value & 0xff);
i = i+3;
#endif
#ifdef S7_300
buffer_byte[i+1] = (unsigned char)((value >> 8) & 0xff);
buffer_byte[i+0] = (unsigned char)(value & 0xff);
i = i+2;
#endif
}
} // end of for (k=0;...
} // end of if (wParam == ID_WRITE)
// set connection no
if (IsDlgButtonChecked(hDlg, IDC_VERB1)) i=0;
if (IsDlgButtonChecked(hDlg, IDC_VERB2)) i=1;
if (IsDlgButtonChecked(hDlg, IDC_VERB3)) i=2;
if (IsDlgButtonChecked(hDlg, IDC_VERB4)) i=3;
res = new_ss((char)(i+1));
if (res == 0)
{
#ifdef S7_200
if (wParam == ID_READ) res = as200_mix_read((char*)mix_tab,buffer);
if (wParam == ID_WRITE) res = as200_mix_write((char*)mix_tab,buffer);
#endif
#ifdef S7_300
if (wParam == ID_READ) res = mix_read((char*)mix_tab,buffer);
if (wParam == ID_WRITE) res = mix_write((char*)mix_tab,buffer);
#endif
}
if (res != 0)
{
KillTimer(hDlg,MYTIMER);
DialogBox(hInst,MAKEINTRESOURCE(IDD_ERROR),hDlg,ERRORBOX);
// EndDialog(hDlg, TRUE);
return (TRUE);
}
if ((message == WM_TIMER) && (wParam == MYTIMER))
SetTimer(hDlg,MYTIMER,800,NULL);
show = 1;
break;
}
if (wParam == ID_CYCLE)
{
SetTimer(hDlg,MYTIMER,800,NULL);
return (TRUE);
}
if (wParam == IDCANCEL)
{
KillTimer(hDlg,MYTIMER);
EndDialog(hDlg, TRUE);
return (TRUE);
}
default:
return(FALSE);
}
if (show == 1)
{
if (IsDlgButtonChecked(hDlg, IDC_HEX)) output='h';
if (IsDlgButtonChecked(hDlg, IDC_DECIMAL)) output='d';
if (IsDlgButtonChecked(hDlg, IDC_BINARY)) output='b';
i=0;
for (k=0;k<MAX_MIX;k++)
{
str[0] = 0;
if (((char)mix_tab[k].type == 'e') ||
((char)mix_tab[k].type == 'a') ||
((char)mix_tab[k].type == 'm') ||
((char)mix_tab[k].type == 's') ||
((char)mix_tab[k].type == 'd') ||
((char)mix_tab[k].type == 'v'))
{
if (output == 'h')
if (buffer_byte[i] < 16)
wsprintf(str1,"0%x",buffer_byte[i]);
else
wsprintf(str1,"%2x",buffer_byte[i]);
if (output == 'd')
wsprintf(str1,"%3d",buffer_byte[i]);
if (output == 'b')
{
j = 0x01;
str1[0] = 0;
while (j!=0x100)
{
if (j & buffer_byte[i])
strcat(str1,"1");
else
strcat(str1,"0");
j=j<<1;
}
}
i++;
} //datatype e,a,m,d,v,s
if (mix_tab[k].type == 't')
{
#ifdef S7_200
//as200 timer value -> 2 bytes long, but 5 bytes are received!!
value = (unsigned long)buffer_byte[i+4] << 0 |
(unsigned long)buffer_byte[i+3] << 8;
i=i+5;
#endif
#ifdef S7_300
// timer value -> 2 bytes long !!
value = (unsigned long)buffer_byte[i+1] << 0 |
(unsigned long)buffer_byte[i+0] << 8;
i=i+2;
#endif
if (output == 'h')
{
wsprintf(str, "0000");
wsprintf(str1,"%x",value);
str[4-(strlen(str1))] = 0;
}
if (output == 'd')
wsprintf(str1,"%5d",value);
if (output == 'b')
{
j = 0x0001;
str1[0] = 0;
while (j!=0x00010000)
{
if (j & value)
strcat(str1,"1");
else
strcat(str1,"0");
j=j<<1;
}
}
} // end of datatype 't'
if (mix_tab[k].type == 'z')
{
#ifdef S7_200
//as200 counter value -> 2 bytes long, but 3 bytes are received !!
value = (unsigned long)buffer_byte[i+2] << 0 |
(unsigned long)buffer_byte[i+1] << 8;
i=i+3;
#endif
#ifdef S7_300
//as300 counter value -> 2 bytes long !!
value = (unsigned long)buffer_byte[i+1] << 0 |
(unsigned long)buffer_byte[i+0] << 8;
i=i+2;
#endif
if (output == 'h')
{
wsprintf(str, "0000");
wsprintf(str1,"%x",value);
str[4-(strlen(str1))] = 0;
}
if (output == 'd')
wsprintf(str1,"%5d",value);
if (output == 'b')
{
str1[0] = 0;
j = 0x00000001;
while (j!=0x00010000)
{
if (j & value)
strcat(str1,"1");
else
strcat(str1,"0");
j=j<<1;
}
}
}
strcat(str,str1);
if (k==0) SetDlgItemText(hDlg, IDC_VALUE1,str);
if (k==1) SetDlgItemText(hDlg, IDC_VALUE2,str);
if (k==2) SetDlgItemText(hDlg, IDC_VALUE3,str);
if (k==3) SetDlgItemText(hDlg, IDC_VALUE4,str);
} // end of for
UpdateWindow(hDlg);
} // end of show
return (TRUE);
} /* end of MIXBOX */
/*************************************************************************/
BOOL WINAPI FLAGBOX(hDlg, message, wParam, lParam)
HWND hDlg;
UINT message;
WPARAM wParam;
LPARAM lParam;
{
BOOL result;
int show = 0;
switch (message) {
case WM_INITDIALOG:
i = 0;
CheckDlgButton(hDlg, IDC_VERB1, 1);
SetDlgItemInt (hDlg,IDC_FROMNO,no,0);
SetDlgItemInt (hDlg,IDC_BITNO,bitno,0);
SetDlgItemText(hDlg,IDC_EDIT_VALUE," ");
memset( buffer,0,sizeof(buffer));
break;
case WM_COMMAND:
if ((wParam == IDC_VERB1) ||
(wParam == IDC_VERB2) ||
(wParam == IDC_VERB3) ||
(wParam == IDC_VERB4))
{
show = 1;
break;
}
if ((wParam == ID_BITTEST) ||
(wParam == ID_SETBIT) ||
(wParam == ID_RESETBIT))
{
no = GetDlgItemInt(hDlg, IDC_FROMNO, &result,0);
SetDlgItemInt(hDlg, IDC_FROMNO, no,0);
bitno = GetDlgItemInt(hDlg, IDC_BITNO, &result,0);
SetDlgItemInt(hDlg, IDC_BITNO, bitno,0);
// set connection no
if (IsDlgButtonChecked(hDlg, IDC_VERB1)) i=0;
if (IsDlgButtonChecked(hDlg, IDC_VERB2)) i=1;
if (IsDlgButtonChecked(hDlg, IDC_VERB3)) i=2;
if (IsDlgButtonChecked(hDlg, IDC_VERB4)) i=3;
res = new_ss((char)(i+1));
if (res == 0)
{
#ifdef S7_200
if (wParam == ID_SETBIT) res = as200_mb_setbit(no,bitno);
if (wParam == ID_RESETBIT) res = as200_mb_resetbit(no,bitno);
#endif
#ifdef S7_300
if (wParam == ID_SETBIT) res = mb_setbit(no,bitno);
if (wParam == ID_RESETBIT) res = mb_resetbit(no,bitno);
#endif
}
if (res != 0)
{
DialogBox(hInst,MAKEINTRESOURCE(IDD_ERROR),hDlg,ERRORBOX);
EndDialog(hDlg, TRUE);
return (TRUE);
}
#ifdef S7_200
res = as200_mb_bittest(no,bitno,buffer);
#endif
#ifdef S7_300
res = mb_bittest(no,bitno,buffer);
#endif
if (res != 0)
{
DialogBox(hInst,MAKEINTRESOURCE(IDD_ERROR),hDlg,ERRORBOX);
EndDialog(hDlg, TRUE);
return (TRUE);
}
show = 1;
break;
}
if (wParam == IDCANCEL)
{
EndDialog(hDlg, TRUE);
return (TRUE);
}
default:
return(FALSE);
}
if (show == 1)
{
if (buffer[0] == 0)
SetDlgItemInt(hDlg, IDC_EDIT_VALUE,0,0);
else
SetDlgItemInt(hDlg, IDC_EDIT_VALUE,1,0);
UpdateWindow(hDlg);
}
return (TRUE);
} /* end of FLAGBOX */
/*************************************************************************/
BOOL WINAPI TSBOX(hDlg, message, wParam, lParam)
HWND hDlg;
UINT message;
WPARAM wParam;
LPARAM lParam;
{
#ifdef S7_300
char s1[256];
HWND ModemName_hDlg;
static char Data[11][80];
int result,len;
switch (message) {
case WM_INITDIALOG:
SetDlgItemText(hDlg,IDC_TELNO,sTelNo);
SetDlgItemText(hDlg,IDC_USERNAME,sUserName);
SetDlgItemText(hDlg,IDC_PASSWORD,sPassword);
SetDlgItemText(hDlg,IDC_STANDORTNAME,sStandortName);
// get handles of combobox
ModemName_hDlg = GetDlgItem(hDlg,IDC_COMBO_MODEM);
//CB_INITSTORAGE
//wParam = (WPARAM) (int) cItems; // number of items to add
//lParam = (LPARAM) (DWORD) cb; // amount of memory to allocate, in bytes
SendMessage(ModemName_hDlg,CB_INITSTORAGE,11,1100);
// fill comboxes with datatype identifier
i=0;
result = 0;
while ((i<10) && (result == 0))
{
len = 80;
result = ts_get_modem_name(i,Data[i],&len);
if (result == 0) SendMessage(ModemName_hDlg,CB_ADDSTRING,0,(LPARAM)Data[i]);
i++;
}
// strcpy(Data[i],"Standardmodem");
// SendMessage(ModemName_hDlg,CB_ADDSTRING,0,(LPARAM)Data[i]);
SendMessage(ModemName_hDlg,CB_SETCURSEL,0,0);
break;
case WM_COMMAND:
if ((wParam == IDC_DIAL_SYNC)||(wParam == IDC_DIAL_ASYNC))
{
ModemName_hDlg = GetDlgItem(hDlg,IDC_COMBO_MODEM);
i = SendMessage(ModemName_hDlg,CB_GETCURSEL,0,0);
strcpy(sModemName,Data[i]);
GetDlgItemText(hDlg, IDC_STANDORTNAME, sStandortName,sizeof(sStandortName));
GetDlgItemText(hDlg, IDC_TELNO, sTelNo,sizeof(sTelNo));
GetDlgItemText(hDlg, IDC_USERNAME, sUserName,sizeof(sUserName));
GetDlgItemText(hDlg, IDC_PASSWORD, sPassword,sizeof(sPassword));
if (wParam == IDC_DIAL_SYNC)
{
res = ts_dial(sModemName,sStandortName,sTelNo,sUserName,sPassword,NULL,0,0,NULL);
strcpy(s1,"sync dial -> ");
if (res == 0)
MessageBox(hDlg,"sync dial -> connected","TELESERVICE MESSAGE",MB_OK);
}
if (wParam == IDC_DIAL_ASYNC)
res = ts_dial(sModemName,sStandortName,sTelNo,sUserName,sPassword,ProgHandle,WM_TELESERVICE,MSG_DIAL,NULL);
if (res != 0)
{
DialogBox(hInst,MAKEINTRESOURCE(IDD_ERROR),hDlg,ERRORBOX);
EndDialog(hDlg, TRUE);
return (TRUE);
}
break;
}
if (wParam == IDC_HANGUP_DIAL)
{
res = ts_hang_up_dial();
if (res != 0)
{
DialogBox(hInst,MAKEINTRESOURCE(IDD_ERROR),hDlg,ERRORBOX);
EndDialog(hDlg, TRUE);
return (TRUE);
}
break;
}
/**********/
if (wParam == IDC_SETRINGINDICATOR)
{
ModemName_hDlg = GetDlgItem(hDlg,IDC_COMBO_MODEM);
i = SendMessage(ModemName_hDlg,CB_GETCURSEL,0,0);
strcpy(sModemName,Data[i]);
/* modem name, no of rings, windhow handel, message, wparam */
res = ts_set_ringindicator(sModemName,3,ProgHandle,WM_TELESERVICE,MSG_RING,NULL);
if (res != 0)
{
DialogBox(hInst,MAKEINTRESOURCE(IDD_ERROR),hDlg,ERRORBOX);
EndDialog(hDlg, TRUE);
return (TRUE);
}
break;
}
if (wParam == IDC_RESETRINGINDICATOR)
{
/* modem name, no of rings, windhow handel, message, wparam */
res = ts_set_ringindicator(NULL,0,NULL,0,0,NULL);
break;
}
if (wParam == IDC_HANGUP_RING)
{
res = ts_hang_up_ring();
if (res != 0)
{
DialogBox(hInst,MAKEINTRESOURCE(IDD_ERROR),hDlg,ERRORBOX);
EndDialog(hDlg, TRUE);
return (TRUE);
}
break;
}
if (wParam == IDCANCEL)
{
GetDlgItemText(hDlg, IDC_STANDORTNAME, sStandortName,sizeof(sStandortName));
GetDlgItemText(hDlg, IDC_TELNO, sTelNo,sizeof(sTelNo));
GetDlgItemText(hDlg, IDC_USERNAME, sUserName,sizeof(sUserName));
GetDlgItemText(hDlg, IDC_PASSWORD, sPassword,sizeof(sPassword));
EndDialog(hDlg, TRUE);
return (TRUE);
}
default:
return(FALSE);
}
#else
EndDialog(hDlg, TRUE);
#endif
return (TRUE);
} /* end of TSBOX */
/*************************************************************************/
/*************************************************************************/
BOOL WINAPI ERRORBOX(hDlg, message, wParam, lParam)
HWND hDlg;
UINT message;
WPARAM wParam;
LPARAM lParam;
{
char error_txt[256];
switch (message) {
case WM_INITDIALOG:
error_message(res,error_txt);
SetDlgItemText(hDlg, IDC_ERROR1, error_txt);
break;
case WM_COMMAND:
if (wParam == IDOK)
{
EndDialog(hDlg, TRUE);
break;
}
if (wParam == IDCANCEL)
{
EndDialog(hDlg, TRUE);
break;
}
default:
return(FALSE);
}
return (TRUE);
} /* end of ERRORBOX */
/*************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -