
naoem
|
voila la fonction :
char DP_OutSlvProc (HWND hDlg, UINT message, WPARAM wParam, LONG lParam)
{ char result; static HWND hComb,CyclicHwnd; static unsigned int OutLen; WORD i; char CharBuf[1000]; long SlvAdr_l; char *achHlp;
result = 1; /* Default value */
switch (message) { case WM_INITDIALOG: {
/* set default output length */
OutLen = 255; wsprintf (CharBuf,"1 "); SendMessage ( GetDlgItem(hDlg,IDC_LENGTH), WM_SETTEXT, 0, (LPARAM)(LPSTR) CharBuf);
/* Set Focus */
hComb = GetDlgItem (hDlg, IDC_COMBO_WR_ADDR_SLV); SetFocus (hComb);
for (i=0;i<126;i++) { wsprintf (CharBuf,"Slv %d",i);
if (Init_SlvBuff[i] == DPR_SLV_READY) { SendMessage (hComb, CB_ADDSTRING, 0, (LPARAM)(LPSTR)CharBuf); } }
/* Default in edit control */
wsprintf (CharBuf,"00 "); SendMessage ( GetDlgItem(hDlg,IDC_DATA_WR), WM_SETTEXT, 0, (LPARAM)(LPSTR) CharBuf);
result = 0; break; }
case WM_COMMAND: { switch (LOWORD(wParam)) {
case IDC_LENGTH: { unsigned int k;
/* Get output bytes from edit control */ SendMessage (GetDlgItem(hDlg,IDC_LENGTH), WM_GETTEXT, 10, /* max. text length */ (LPARAM)(LPSTR) CharBuf); OutLen = atoi (CharBuf);
if (OutLen > 246) { OutLen = 246; } if (OutLen == 0) { OutLen = 1; }
/* Show Default Values in edit control */
wsprintf (CharBuf,"00 "); for (k=1;k<OutLen;k++) { lstrcat (CharBuf, "00 "); } SendMessage ( GetDlgItem(hDlg,IDC_DATA_WR), WM_SETTEXT, 0, (LPARAM)(LPSTR) CharBuf); break; }
case IDC_COMBO_WR_ADDR_SLV: { char Index; if (HIWORD (wParam) == LBN_DBLCLK) { /* the same as IDOK */ PostMessage (hDlg, WM_COMMAND, IDOK, (LPARAM) 0); break; }
if (HIWORD(lParam) == LBN_SELCHANGE) { Index = (char)SendMessage (hComb, CB_GETCURSEL, 10, (LPARAM)(LPSTR) CharBuf); if (Index == CB_ERR) { break; } SendMessage (hComb, CB_GETLBTEXT, Index, (LPARAM)(LPSTR) CharBuf); } break; }
case IDC_BUTTON_WRITE: { /* Get actual string of the edit control */ SendMessage (hComb, WM_GETTEXT, 10, /* max. text length */ (LPARAM)(LPSTR) CharBuf);
/* Slave address valid ? */
if ( strnicmp((const char far *)CharBuf, (const char far *)"Slv ", (size_t) 4 ) != 0) { /* invalid string */ MessageBox(hDlg, (LPSTR) "address is out of range or unknown", (LPSTR)"wrong slave address!", MB_OK );
return (result); }
achHlp = &CharBuf[3]; SlvAdr_l = strtoul ((char far *)&CharBuf[4],&achHlp,10); if ( ((SlvAdr_l == 0) && (achHlp == &CharBuf[4])) || (SlvAdr_l > 125) ) { /* invalid string */ MessageBox(hDlg, (LPSTR) "address is out of range or unknown", (LPSTR)"wrong slave address!", MB_OK ); return (result); }
Slave_add_g = (char)SlvAdr_l;
/* Get output bytes from edit control */ SendMessage (GetDlgItem(hDlg,IDC_DATA_WR), WM_GETTEXT, 900, /* max. text length */ (LPARAM)(LPSTR) CharBuf); if (GetStringValue ((char *)Slv_Module[Slave_add_g].buf_2_write ,(char *)CharBuf, (char)OutLen) == 0) { MessageBox( hDlg, (LPSTR) "default value (0) is assumed for all output bytes", (LPSTR)"Wrong syntax for output bytes!", MB_OK ); for (i = 0; i < OutLen;i++) { Slv_Module[Slave_add_g].buf_2_write[i] = 0; } }
Slv_Module[Slave_add_g].nb_octets = OutLen; /* Set the data to the adressed slave */ Send_Data ();
break; }
case IDCANCEL: case IDOK: { EndDialog(hDlg,IDOK); break; }
default: { result = 0; break; } } }
default: { result = 0; } } return (result); }
je reessaie demain..
|