Ma ho capito male o tu hai i sorgenti della OWLIB?
Grazie Antonio, si, ho i sorgenti di OWLIB ( iButton - Contact Memory, Digital Temperature Data Loggers, Java-powered and Secure eCash Tokens - Maxim/Dallas, file: multiVC300.zip).
mi fa piacere che tu abbia letto il mio articolo ma forse c'e' qualcosa che non va.
Niente affatto. Nel senso che l'articolo è talmente ben documentato che sono riuscito, con mia meraviglia e senza troppe difficoltà, a trasformare il tuo esempio da C++ a C (gli esempi di Dallas sono in C).
L'unico problema è stato il passaggio di parametri di tipo UDT contenenti elementi boolean (nell'articolo fatti corrispondere a long anziché a short).
Non ha senso "inserire" una libreria .lib in una DLL (e fa bene il VC ad arrabbiarsi)
Sono un principiante, misero me! Tieni conto che mi sono arrabbiato anch'io e parecchio (insensibile VC!).
Provengo dal mondo VB e non ho potuto evitare l'ingenuità di applicare una evidentemente erronea deduzione da 'vubbista'.
Però dovresti spiegarmi perché VC si arrabbia. In realtà l'ho molestato per dargli lavoro (programmazione 'creativa', ma anche per risparmiarmi la traduzione a VB, per me proibitiva: spero però che non finisca come la finanza creativa!).
Fammi capire bene cosa vuoi fare, magari con un esempio di codice, e ne parliamo.
Si, grazie: ma ti basterà un solo post per correggere il copia e maleincolla dal tuo articolo?
Esempio di funzione nella DLL il cui scopo è quello di interrogare la rete 1-Wire e riempire un array di stringhe per VB contenenti ciascuna l'identificativo in esadecimale di ciascun dispositivo rilevato (C3081 è la mia/tua dll):
Codice:
DWORD _stdcall GetDevicesList(SAFEARRAY **par)
{
int rslt,cnt,ret=1;
int portnum=0;
uchar SNum[8];
//char *port_zstr="{1,5}";
unsigned char buffer[16];
long l=1;
BSTR bstrElement;
__try
{
char *port_zstr=*m_InitString;
SAFEARRAYBOUND sab[] = { 0, 1 };
SAFEARRAY *psa = SafeArrayCreate(VT_BSTR, 1, sab);
if (!m_Initialized) RaiseException(C3081_ERR_NOT_INITIALIZED,0,0,NULL);
if (!psa) RaiseException(C3081_ERR_INTERNAL,0,0,NULL);
if((portnum = owAcquireEx(port_zstr)) < 0)
RaiseException(C3081_ERR_TMEX,0,0,NULL);
cnt = 0;
bstrElement = SysAllocStringByteLen("ZZZZZZZZZZZZZZZZ", 16);
// find the first device (all devices not just alarming)
rslt = owFirst(portnum, TRUE, FALSE);
while (rslt)
{
owSerialNum(portnum,&SNum[0],TRUE);
PrintSerialNum(&SNum[0]);
ROMToHexString(SNum,buffer);
strcpy((char *)bstrElement,buffer);
sab->cElements++;
SafeArrayRedim(psa,sab);
SafeArrayPutElement(psa, &l, bstrElement);
l++;
// find the next device
rslt = owNext(portnum, TRUE, FALSE);
}
SysFreeString(bstrElement);
// release the 1-Wire Net
owRelease(portnum);
*par=psa;
return C3081_ERR_SUCCESS;
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
return GetExceptionCode();
}
}
owAcquireEx è una funzione presente nella libreria OWLIB che, dopo vari passaggi, giunge al sodo nel modo seguente:
Codice:
SMALLINT OpenCOM(int portnum, char *port_zstr)
{
char tempstr[80];
short fRetVal;
COMMTIMEOUTS CommTimeOuts;
DCB dcb;
if(!ComID_init)
{
int i;
for(i=0; i<MAX_PORTNUM; i++)
ComID[i] = 0;
ComID_init = 1;
}
OWASSERT( portnum<MAX_PORTNUM && portnum>=0 && !ComID[portnum],
OWERROR_PORTNUM_ERROR, FALSE );
// open COMM device
if ((ComID[portnum] =
CreateFile( port_zstr, GENERIC_READ | GENERIC_WRITE,
0,
NULL, // no security attrs
OPEN_EXISTIN G,
FILE_FLAG_OV ERLAPPED, // overlapped I/O
NULL )) == (HANDLE) -1 )
{
ComID[portnum] = 0;
OWERROR(OWERROR_GET_SYST EM_RESOURCE_FAILED);
return (FALSE) ;
}
else
{
// create events for detection of reading and write to com port
sprintf(tempstr,"COMM_RE AD_OVERLAPPED_EVENT_FOR_%s",port_zstr);
osRead[portnum].hEvent = CreateEvent(NULL,TRUE,FALSE,tempstr);
sprintf(tempstr,"COMM_WR ITE_OVERLAPPED_EVENT_FOR_%s",port_zstr);
osWrite[portnum].hEvent = CreateEvent(NULL,TRUE,FALSE,tempstr);
// get any early notifications
SetCommMask(ComID[portnum], EV_RXCHAR | EV_TXEMPTY | EV_ERR | EV_BREAK);
// setup device buffers
SetupComm(ComID[portnum], 2048, 2048);
// purge any information in the buffer
PurgeComm(ComID[portnum], PURGE_TXABORT | PURGE_RXABORT |
PURGE_TXCLEAR | PURGE_RXCLEAR );
// set up for overlapped non-blocking I/O
CommTimeOuts.ReadInterva lTimeout = 0;
CommTimeOuts.ReadTotalTi meoutMultiplier = 20;
CommTimeOuts.ReadTotalTi meoutConstant = 40;
CommTimeOuts.WriteTotalT imeoutMultiplier = 20;
CommTimeOuts.WriteTotalT imeoutConstant = 40;
SetCommTimeouts(ComID[portnum], &CommTimeOuts);
// setup the com port
GetCommState(ComID[portnum], &dcb);
dcb.BaudRate = CBR_9600; // current baud rate
dcb.fBinary = TRUE; // binary mode, no EOF check
dcb.fParity = FALSE; // enable parity checking
dcb.fOutxCtsFlow = FALSE; // CTS output flow control
dcb.fOutxDsrFlow = FALSE; // DSR output flow control
dcb.fDtrControl = DTR_CONTROL_ENABLE; // DTR flow control type
dcb.fDsrSensitivity = FALSE; // DSR sensitivity
dcb.fTXContinueOnXoff = TRUE; // XOFF continues Tx
dcb.fOutX = FALSE; // XON/XOFF out flow control
dcb.fInX = FALSE; // XON/XOFF in flow control
dcb.fErrorChar = FALSE; // enable error replacement
dcb.fNull = FALSE; // enable null stripping
dcb.fRtsControl = RTS_CONTROL_ENABLE; // RTS flow control
dcb.fAbortOnError = FALSE; // abort reads/writes on error
dcb.XonLim = 0; // transmit XON threshold
dcb.XoffLim = 0; // transmit XOFF threshold
dcb.ByteSize = 8; // number of bits/byte, 4-8
dcb.Parity = NOPARITY; // 0-4=no,odd,even,mark,space
dcb.StopBits = ONESTOPBIT; // 0,1,2 = 1, 1.5, 2
dcb.XonChar = 0; // Tx and Rx XON character
dcb.XoffChar = 1; // Tx and Rx XOFF character
dcb.ErrorChar = 0; // error replacement character
dcb.EofChar = 0; // end of input character
dcb.EvtChar = 0; // received event character
fRetVal = SetCommState(ComID[portnum], &dcb);
}
// check if successfull
if (!fRetVal)
{
CloseHandle(ComID[portnum]);
CloseHandle(osRead[portnum].hEvent);
CloseHandle(osWrite[portnum].hEvent);
ComID[portnum] = 0;
OWERROR(OWERROR_SYSTEM_R ESOURCE_INIT_FAILED);
}
return (fRetVal);
}
Mi scuso per la lunghezza del post, sono comunque disponibile ad inviarti il malloppo.
Grazie
Ma che ore sono? Accidenti...