Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
26
Erster Beitrag:
vor 8 Jahren, 2 Monaten
Letzter Beitrag:
vor 8 Jahren, 2 Monaten
Beteiligte Autoren:
Mitchell, BLS, Udo, christoph, Piet van Zanten, King, Fabrice Harari

unsigned char equivalent in Windev

Startbeitrag von Mitchell am 03.05.2010 09:03

Please help,
I tried many times, but i could get it exactly . below is the C++ assignment of variable type :

int (__stdcall * API_SetBaudrate)(HANDLE commHandle, int DeviceAddress, unsigned char newBaud,unsigned char *buffer);

int DeviceAddress
unsigned char newBaud
unsigned char *buffer

what is the equivalent assignment in Windev 14 ?
I tried this but now work :
DeviceAddress is int; // this is ok
newBaud is character // this is ok

but this line "unsigned char *buffer" ??? how to make it in windev?

Antworten:

Hi Mitchell

MyBuffer is buffer

and then you use &MyBuffer

That should do it

Best regards


von Fabrice Harari - am 03.05.2010 09:37
Dear Fabrice,
Thanks for reply, I tried it but doesn't give expected results:

hInst is int
hInst = LoadDLL("ALL.DLL")
IF hInst = 0 THEN
Error("Error while loading")
ELSE
nOpncom= CallDLL32("ALL", "API_OpenComm",2,9600)
//trace(nOpncom)
IF nOpncom 0 THEN
Info("Success...",nOpncom)
nSetdevadd is int;
nDeviceadd is int =0;
nCNewaddr is 1-byte unsigned int =1;
bufNSCNewbuff is Buffer
nSetdevadd = CallDLL32("ALL", "API_SetDeviceAddress",nDeviceadd,nCNewaddr,&bufNSCNewbuff)
IF nSetdevadd=0 THEN Info("Device Address SET SUCCESSFULLY")
Info("Success...",nSetdevadd)
end
end
end

this line still gives me wrong data type error "nSetdevadd = CallDLL32("ALL", "API_SetDeviceAddress",nDeviceadd,nCNewaddr,&bufNSCNewbuff)"



von Mitchell - am 03.05.2010 11:07
hello Fabrice,
What is the equivalent assignment for this Visual Basic code into Windev code ?

"Private Sub Command3_Click()
Dim ret As Integer
Dim blkAddr, dataLen As Integer
Dim mode, devAddr, blkNum As Byte

Dim aKeyA(20) As Byte
Dim aCardNo(10) As Byte
Dim aRecvBuffer(2048) As Byte

Dim strRet As String


mode = &O0
devAddr = &O0
keyA = ""
cardNo = ""
recvBuffer = ""
Text4.Text = ""
Text5.Text = ""

blkNum = Val(Combo1.Text)
blkAddr = Val(Text1.Text)


ret = hexToBin(Text2.Text, aKeyA)
ret = API_MF_Read(hComm, devAddr, mode, blkAddr, blkNum, aKeyA(0), aRecvBuffer(0))



Thanks



von Mitchell - am 03.05.2010 11:13
Hi Mitchell,
in C++
signed char, which gives you the -128 to 127 range.
unsigned char, which gives you the 0 to 255 range.

so the in WD you should use

x is unsigned int on 1 byte // for unsigned char.

Your :
newBaud is character // this is NOT ok

this is made for character literals like "a" and is like the C++ char type.
hth,
Bjoern




von BLS - am 03.05.2010 22:16
Thanks Bjoern
do you have idea what is the equiavalent in Windev for this line :
in C++:

unsigned char *buffer

in Windev : ?


von Mitchell - am 04.05.2010 06:00
Hallo Mitchell,

test : is string ASCIIZ on xxx

Christoph

von christoph - am 04.05.2010 06:27
Hi Christoph,
what this means " test : is string ASCIIZ on xxx " , what is the meaning of it?

regards

von Mitchell - am 04.05.2010 06:48
Hi
In VB allocate aRecvBuffer(2048) memory

Perhaps you must do follow in windev

aRecvBuffer is buffer

aRecvBuffer = repeatstring(" ",2048)

Udo



Quote
Mitchell
hello Fabrice,
What is the equivalent assignment for this Visual Basic code into Windev code ?

"Private Sub Command3_Click()
Dim ret As Integer
Dim blkAddr, dataLen As Integer
Dim mode, devAddr, blkNum As Byte

Dim aKeyA(20) As Byte
Dim aCardNo(10) As Byte
Dim aRecvBuffer(2048) As Byte

Dim strRet As String


mode = &O0
devAddr = &O0
keyA = ""
cardNo = ""
recvBuffer = ""
Text4.Text = ""
Text5.Text = ""

blkNum = Val(Combo1.Text)
blkAddr = Val(Text1.Text)


ret = hexToBin(Text2.Text, aKeyA)
ret = API_MF_Read(hComm, devAddr, mode, blkAddr, blkNum, aKeyA(0), aRecvBuffer(0))



Thanks





Edited 1 times. Last edit at 05/03/10 01:14PM by Mitchell.


von Udo - am 04.05.2010 07:03
Quote
Mitchell
Thanks Bjoern
do you have idea what is the equiavalent in Windev for this line :
in C++:

unsigned char *buffer

in Windev : ?


Hi Mitch
I would give this a try :

bufferContent is unsigned int on 1 byte = whateverYouNeed
_buffer is int = &bufferContent
//Not tested of course.

Next, make sure that HANFLE is an integer 'cause sometimes HANDLE is unsigned integer.
HTH,
Bjoern

von BLS - am 04.05.2010 07:56
Sorry I mean :


bufNSCNewbuff is string ASCIIZ on 250

nSetdevadd = CallDLL32("ALL", "API_SetDeviceAddress",nDeviceadd,nCNewaddr,&bufNSCNewbuff)

Christoph

von christoph - am 04.05.2010 08:06
thank you guys for kind support, i really tried all but still doesn't give me expected results :-(

below is my trials code :
=======================================
nOpncom is int;
hInst is int;
hInst = LoadDLL("ALL.DLL")
IF hInst = 0 THEN
Error("Error while loading")
ELSE
nOpncom= CallDLL32("ALL", "API_OpenComm",2,9600)
//trace(nOpncom)
IF nOpncom 0 THEN
Info("Success...",nOpncom) // this is okay till here
nRet is int;
nBlkAddr, nDataLen is int;
nMode, nDevAddr, nBlkNum are int;
// arrNAKeyA is array of 1-byte unsigned int;
arrNAKeyA is array of 20 character;
bufMybuffer is Buffer
// arrNAKeyA = "";
// nAKeyA = [[0]];
nArrNARecvBuffer is 1-byte unsigned int;
arrCMybuff is array of 1 unsigned int;
arrCMybuff[1] = "";
nDeviceadd is int;
nDeviceadd=0;
// x is unsigned int on 1 byte // for unsigned char.
nDeviceadd2 is unsigned int on 1 byte;
nDeviceadd2 =0;


nBuffer3 is unsigned int on 1 byte;
nBuffer3[0] = "";

bufBuffer4 is Buffer
// buffer4 = "";
bufBuffer5 is Buffer on 9;
//bufBuffer5="the quick brown fox jump over the window"
// Info(bufBuffer5[[1 to 9]])
// bufBuffer5[[1]] ="";

MyBuffer is Buffer
MyBuffer[[1]] = 65 // MyBuffer contains "A"
// info(mybuffer)


// nret = api("ALL","API_GetSerNum",nOpncom,nDeviceadd2,&bufBuffer5)

mode1 is unsigned int on 1 byte
nBlkadd1 is unsigned int on 1 byte
nNumblk1 is unsigned int on 1 byte
bufSnr1 is Buffer on 128
bufBuffer7 is Buffer on 1028
mode1=0x00;
// info(mode1)
// test is string ASCIIZ on xxx
szSnr2 is string ASCIIZ on 128
szBuffer8 is string ASCIIZ on 1028

bufSnr1 = "FF FF FF FF FF FF";
nBlkadd1=0;
nNumblk1=2;
//trace(bufSnr1,bufBuffer7)
MyBuffer9 is Buffer
MyBuffer9 = "WinDev is great"
// Info(MyBuffer9[[1 to 15]])

bufSnr3 is Buffer
bufSnr3 = RepeatString(" ",20)
bufSnr3= "FF FF FF FF FF FF";

bufBuffer10 is Buffer
bufBuffer10 = "";

aRecvBuffer is Buffer
aRecvBuffer = RepeatString(" ",2048)
nMybuffer2 is unsigned int on 1 byte
bufferContent is unsigned int on 1 byte = 1024

n_buffer is int = &bufferContent
bufNSCNewbuff is string ASCIIZ on 250
szSnr5 is string ASCIIZ on 20
szSnr5 = Val("FF FF FF FF FF FF");

nRet = API("ALL","API_MF_Read",nOpncom,0,0x00,1,1,&szSnr5,&bufNSCNewbuff)
// nret = api("ALL","API_GetSerNum",nOpncom,0,&bufNSCNewbuff)
// Trace(nRet,bufBuffer5[[1]],bufBuffer5[[2 to 9]])

// Trace(nRet,nArrNARecvBuffer,nArrNARecvBuffer[0])

IF nRet = 0 THEN
Info("API_GetSerNum",&bufNSCNewbuff)

nOpncom = CallDLL32("ALL", "API_CloseComm",nOpncom)
// Info("API MF READ",nRet,&bufSnr3,&aRecvBuffer)
//,&bufSnr3,&bufBuffer10,bufBuffer10[[1]])
ELSE
Trace("failed",nRet,bufNSCNewbuff)

//,&bufSnr3,&bufBuffer10,bufBuffer10[[1]])
nOpncom = CallDLL32("ALL", "API_CloseComm",nOpncom)
END

// nOpncom = CallDLL32("ALL", "API_CloseComm",nOpncom)
ELSE
nOpncom = CallDLL32("ALL", "API_CloseComm",nOpncom)

END

FreeDLL(hInst)
END
====================

von Mitchell - am 04.05.2010 09:13
Hi Mitch,
I guess one of the problems is that you are asking too many different API questions at once.
So I would like to suggest that you take one API call, show the C header and, if possible a C sample.

So here a general advice on how to translate C?WINDOWS API calls.

Whenever you see a "CType *varname ", the WD Translation is exactly like the one I have described before.
(The trick in reading C code is that you have to read it from right to left.)
I.E.
unsigned char *buffer;
means buffer is pointer to (*) unsigned char.

The general valid translation into WD is

ptr is int // pointer to WhatDaHeck datatype

datatype is in our case :
_buffer is unsigned int on 1 byte

ptr = &_buffer // save the address of _buffer into ptr

Now when you call your API function use :
x is int = API("APIName", "APIFunc", ptr)

and NOT
x is int = API("APIName", "APIFunc", &ptr)

because ptr already contains the address of _buffer.
In other words : if you use &ptr than your are defining a pointer to pointer,
( in C f.e. :int **ptrptr;)

Ergo ; Whenever you find a C pointer you should follow this pattern.
Define an integer and assign the address of the variable by using &

There is indeed one exception
//C
char* x;
Here you should use a buffer
//WD
x is buffer.

Finally.
I think UDO is wrong. Instead of ::
aRecvBuffer is buffer = repeatstring(" ",2048)
You should use ;
aRecvBuffer is buffer = repeatstring(0, 2048)
HTH, Bjoern





von BLS - am 04.05.2010 10:58
Thanks Bjoern, I tried again, and again, why still not giving the expected results, i really don't know.... below is the API Description I tried :

Name API_GetSerNum
Delcaration int API_GetSerNum (HANDLE commHandle, int DeviceAddress,unsigned char *buffer)Description Read one byte of the reader address and 8 byte serial number which be used by manufactory.
Input Parameter:
commHandle - the serial port handle
DeviceAddress - Reader Address
Range of Reader Address is from 0 to 255

Output Parameter:
buffer
succeed:
buffer[0]: Reader Address,
buffer[1-8]: 8 byte serial number
failed:
buffer[0] value is status words.As for the exact meaning, please refere to the APPENDIX 。
Return value If function run successfully, then return value is 0;Other else it is not 0, As for the exact meaning, please refere to the APPENDIX 。
==================
in my WD Code: I have this line
nOpncom is int;
hInst is int;
hInst = LoadDLL("ALL.DLL")
IF hInst = 0 THEN
Error("Error while loading")
ELSE
nOpncom= CallDLL32("ALL", "API_OpenComm",2,9600)
//trace(nOpncom)
IF nOpncom 0 THEN
Info("Success...",nOpncom) // this is okay till here
nRet is int;

nPtr is int;
_buffer is unsigned int on 1 byte
nPtr = &_buffer // save the address of _buffer into ptr

nRet = API("ALL","API_GetSerNum",nOpncom,0,nPtr)

IF nRet = 0 THEN
Info("API_GetSerNum","SUCCESS")
=============

below is the code in ALL.H C++ API for API_GetSerNum

int (__stdcall * API_GetSerNum)(
HANDLE commHandle, int DeviceAddress,unsigned char *buffer);




von Mitchell - am 04.05.2010 11:50
Hi Mitch,
your code looks reasonable.
What comes into mind is :

Are you sure that 0 is the correct deviceAddress ?
-In case that 0 is correct try Null instead
Are you sure that HANDLE is integer ?
-maybe it is an unsigned integer.

and finally, what you can try is :

_buffer is buffer = repeatstring(0, 8)

pass _buffer by reference.. &_buffer.
Sorry this is all I can say atm.
Bjoern

PS : In case that you have Visual C++ Express installed, move the cursor over HANDLE, right click and choose Goto definition..

von BLS - am 04.05.2010 12:36
Are you sure that 0 is the correct deviceAddress and handle is integer? yes because it is "connected"
the return value of "nRet = API("ALL","API_GetSerNum",nOpncom,0,nPtr) " is equal to zero, which is correct, but the value of nPtr is 121945 which is not correct,the correct value must be "5CD216BF" as per DEMO.Exe supplied by SDK provider.
I don't know how to read exactly the value of nPtr[0] , nPtr[1 to 8]

any other idea? i really thanks for your effort and time.

Quote
BLS
Hi Mitch,
your code looks reasonable.
What comes into mind is :

Are you sure that 0 is the correct deviceAddress ?
-In case that 0 is correct try Null instead
Are you sure that HANDLE is integer ?
-maybe it is an unsigned integer.

and finally, what you can try is :

_buffer is buffer = repeatstring(0, 8)

pass _buffer by reference.. &_buffer.
Sorry this is all I can say atm.
Bjoern

PS : In case that you have Visual C++ Express installed, move the cursor over HANDLE, right click and choose Goto definition..


von Mitchell - am 04.05.2010 12:46
Quote
Mitchell
..., but the value of nPtr is 121945 which is not correct,the correct value must be "5CD216BF" as per DEMO.Exe supplied by SDK provider.
I don't know how to read exactly the value of nPtr[0] , nPtr[1 to 8]

nPtr contains just the ADRESS of nPtr not the VALUE !
See Transfer function Online Help.

just out of my head, see online help please
b is buffer on 8
Transfer(nPtr, &b, 8)
Finally you can slice the buffer
bSlice is buffer = b [ [ 1 ] ]

Sorry I run out of time,
HTH Bjoern


von BLS - am 04.05.2010 13:02

Perhaps you need StringRetrieve.

look into the help.


nStringAddress is system int
API(, , &nStringAddress)
sString is string
sString = StringRetrieve(nStringAddress, srASCIIZAddress)



Udo


von Udo - am 04.05.2010 13:09
:( pls. elaborate how to get the value.

von Mitchell - am 04.05.2010 13:54
And the question is dedicated to ?

In case that you are asking me

regarding the last snippet .. here the correct implementation.

b is buffer = repeatstring(0, 8)
Transfer( &p, nPtr, 8 )
b1 is buffer = b[[ 1 ]] // in C++ this will be b[0] .. remove space inside [[ ]]

Bjoern
PS I am just a lurker, and not an active WD developer..




von BLS - am 04.05.2010 15:18
Hi

Pls see my code as below as it works out very well since 2002 but
I am not sure it works out for you.

//OraMsg(4ByteInt, sBuffer, 240)
//Ok develeped on 2002.06.27
hInst is long int // you have to change it to int
nErrMsg is long int = 1552 //for windev 7, declare int instead of long int
sBuffer is fixed string on 250 // you may CHANGE IT to 8
hInst = LoadDLL("c:\oracle\msgdll.dll")
If hInst = 0 then
Error("Error during loading")
else //submit it directly
info(CallDLL32("msgdll","OraMsg",nErrMsg,&sBuffer, 250))
FreeDLL(hInst)
end
info(sBuffer)
message(length(sBuffer))
//at least my code was working here.

Let me know whether it works out for you.

Cheers

King



von King - am 05.05.2010 03:48
Hi Mitchell,

Lot's of info is to be found in Tools, WDtool, WDapi.
You can do simple C to wLanguage conversions there and look at the provided API calls to learn from.

Regards,
Piet

von Piet van Zanten - am 05.05.2010 08:16
Thanks Piet,King,Bjoern, I tried those options but i am still stuck. :-(
a simple C++ code why it is very hard to code in WD :-(
==============================================
int CReader::ReadBLOCK(int add,BYTE *pData)
{
if(!hComm)
return 1;
if(add64)
return 10;
BYTE buf[128];
int result = 0;
memset(buf,0,128);
if((result = GetCardByteSerial(buf)) != 0x00)
return result;
BYTE dataBuf[1024];
memset(buf,0xff,6);
memset(dataBuf,0,128);
if((result = API_MF_Read(hComm,DeviceAddress,0x00,add,1,buf,dataBuf)) != 0x00)
return 6;
memcpy(pData,dataBuf,16);
Buzzer(2,1);
return 0;

}
===========================================


von Mitchell - am 05.05.2010 10:24
Jeez Mitch :)

Let us reduce it a bit..

int CReader::ReadBLOCK(int add,BYTE *pData)

CReader is part(a method) of a C++ class.
Though you can't call this method via an direct DLL call. trom WD
However, I guess that your C++ DLL is offering a plain vanilla C wrapper.

In this case both parameters are integers..
.
add is int = 1
BYTE_PTR is int
BYTE_PTR _= &pData // BYTE *pData in your C++ sample


API("WTF", "Func", a, b)

memcpy ... IE
-------------------
sourceVal_ is int = 1000
targetVal_ is int
nSource_adr_ is system int = &sourceVal_

Transfer( &targetVal_, nSource_adr_, Dimension( sourceVal_ ) )
Trace( targetVal_ )

memset.
-----------
Out of the box I would say that WD does not support this stuff, ( I can be wrong) I guess. vou have to use RTL_Mem??? API from USER32.DLL but maybe somebody else has an idea...

HTH
Bjoern

von BLS - am 06.05.2010 01:13
It is NOT that simple cause nobody knows what BYTE really is. We just can make a guess, and thats it..

however, whithout having information, give buffer a try, Use slicing..

// C++ BYTE buf[128];
buffer is BYTE on 128

// C++memset(buf,0,128);
buffer = repeatstring(0, 128)

//C++ if((result = GetCardByteSerial
result is int = API()
IF result
END

//C++memcpy(pData,dataBuf,16);
buffer pData = dataBuf[[ 1 TO 16 ] // bytes to copy.


Bjoern Give up now.. ..C knoff hoff is rusty.. Good luck




von BLS - am 06.05.2010 02:49
Quote
BLS
// C++ BYTE buf[128];
buffer is BYTE on 128

damned :angry:

BYTE is buffer on 128

von BLS - am 06.05.2010 02:52
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.