:cbAInScan call because if I commented it out everything else run OK.
BOARDNUM = 0
BUF_SIZE = 5000
NUM_SECS = 10
ADRANGE = 0
NOCONVERTDATA = 0x0000
CONVERTDATA = 0x0008
PRINTALL = 3
STOPALL = 2
LOWCHAN = 0
HIGHCHAN = 1
# HGLOBAL EXTCCONV cbWinBufAlloc (long NumPoints);
dll_handle=dlopen("cbw64.dll")
# int EXTCCONV cbErrHandling (int ErrReporting, int ErrHandling);
ccall((:cbErrHandling,"cbw64.dll"), Int16, (Uint16,Uint16), PRINTALL, STOPALL)
Buffer = ccall((:cbWinBufAlloc,"cbw64.dll"), Ptr{Int16}, (Int32,), BUF_SIZE)
Count = BUF_SIZE
Rate = int32(BUF_SIZE / NUM_SECS)
# int EXTCCONV cbAInScan (int BoardNum, int LowChan, int HighChan, long Count,
# long *Rate, int Gain, HGLOBAL MemHandle,
# int Options);
ret = ccall((:cbAInScan,"cbw64.dll"),
Int16, (Int16, Int16, Int16, Int32, Ptr{Int32}, Int16, Ptr{Int16}, Int16),
BOARDNUM, LOWCHAN, HIGHCHAN, Count, Rate, ADRANGE, Buffer, CONVERTDATA)
# int EXTCCONV cbWinBufFree (HGLOBAL MemHandle);
retbuffree = ccall((:cbWinBufFree,"cbw64.dll"), Int16, (Ptr{Int16},), Buffer)
dlclose(dll_handle)
ret
#retbuffree
2014-10-09 17:59:29.207 [NotebookApp] Saving notebook at /WINCAI02.C.ipynb
Please submit a bug report with steps to reproduce this fault, and any error mes
sages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x60837247 -- unknown function (ip: 161
9227207)
unknown function (ip: 1619227207)
unknown function (ip: 1620553756)
unknown function (ip: 1623011214)
anonymous at no file:0
Please submit a bug report with steps to reproduce this fault, and any error mes
sages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x60837247 -- unknown function (ip: 161
9227207)
anonymous at no file:0
Please submit a bug report with steps to reproduce this fault, and any error mes
sages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x60837247 -- unknown function (ip: 161
9227207)
anonymous at no file:0
Please submit a bug report with steps to reproduce this fault, and any error mes
sages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x60837247 -- unknown function (ip: 161
9227207)
anonymous at no file:0
Please submit a bug report with steps to reproduce this fault, and any error mes
sages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x60837247 -- unknown function (ip: 161
9227207)
anonymous at no file:0
Please submit a bug report with steps to reproduce this fault, and any error mes
sages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x60837247 -- unknown function (ip: 161
9227207)
anonymous at no file:0
2014-10-09 17:59:47.428 [NotebookApp] KernelRestarter: restarting kernel (1/5)
WARNING:root:kernel a335deec-1763-4cdc-93da-599f5bce3ff6 restarted
Starting kernel event loops.
2014-10-09 18:01:29.209 [NotebookApp] Saving notebook at /WINCAI02.C.ipynb
BOARDNUM = 0
BUF_SIZE = 5000
NUM_SECS = 10
ADRANGE = 0
NOCONVERTDATA = 0x0000
CONVERTDATA = 0x0008
PRINTALL = 3
STOPALL = 2
LOWCHAN = 0
HIGHCHAN = 1
dll_handle=dlopen("cbw64.dll")
# int EXTCCONV cbErrHandling (int ErrReporting, int ErrHandling);
ccall((:cbErrHandling,"cbw64.dll"), Cint, (Cint, Cint), PRINTALL, STOPALL)
# HGLOBAL EXTCCONV cbWinBufAlloc (long NumPoints);
Buffer = ccall((:cbWinBufAlloc,"cbw64.dll"), Ptr{Cint}, (Clong,), BUF_SIZE)
Count = BUF_SIZE
Rate = int32(BUF_SIZE / NUM_SECS)
# int EXTCCONV cbAInScan (int BoardNum, int LowChan, int HighChan, long Count,
# long *Rate, int Gain, HGLOBAL MemHandle,
# int Options);
ret = ccall((:cbAInScan,"cbw64.dll"),
Cint, (Cint, Cint, Cint, Clong, Ptr{Clong}, Cint, Ptr{Cint}, Cint),
BOARDNUM, LOWCHAN, HIGHCHAN, Count, Rate, ADRANGE, Buffer, NOCONVERTDATA)
# int EXTCCONV cbWinBufFree (HGLOBAL MemHandle);
retbuffree = ccall((:cbWinBufFree,"cbw64.dll"), Cint, (Ptr{Cint},), Buffer)
dlclose(dll_handle)
#ret
retbuffree
The documentation indicates that these should be stdcall, although if you are on 64-bit windows, that is a no-op
#define EXTCCONV __stdcall
But in this case, you are also passing a number (Rate) to a parameter expecting a pointer. Since pointers are just numbers, Julia doesn't complain, but that won't work so well when C tries to access the pointer. Try passing the address of the value instead `&Rate`The documentation indicates that these should be stdcall, although if you are on 64-bit windows, that is a no-op#define EXTCCONV __stdcall
But in this case, you are also passing a number (Rate) to a parameter expecting a pointer. Since pointers are just numbers, Julia doesn't complain, but that won't work so well when C tries to access the pointer. Try passing the address of the value instead `&Rate`
function gethostname()
hostname = Array(Uint8, 128)
ccall( (:gethostname, "libc"), Int32,
(Ptr{Uint8}, Uint),
hostname, length(hostname))
return bytestring(convert(Ptr{Uint8}, hostname))
end
BOARDNUM = 0
BUF_SIZE = 5000
NUM_SECS = 10
ADRANGE = 0
NOCONVERTDATA = 0x0000
CONVERTDATA = 0x0008
PRINTALL = 3
STOPALL = 2
LOWCHAN = 0
HIGHCHAN = 1
dll_handle=dlopen("cbw64.dll")
# define EXTCCONV __stdcall
# int EXTCCONV cbErrHandling (int ErrReporting, int ErrHandling);
ccall((:cbErrHandling,"cbw64.dll"), stdcall, Cint, (Cint, Cint), PRINTALL, STOPALL)
###ccall(dlsym(dll_handle, :cbErrHandling), stdcall, Cint, (Cint, Cint), PRINTALL, STOPALL)
# HGLOBAL EXTCCONV cbWinBufAlloc (long NumPoints);
Buffer = ccall((:cbWinBufAlloc,"cbw64.dll"), stdcall, Ptr{Cint}, (Clong,), BUF_SIZE)
##Buffer = ccall(dlsym(dll_handle,:cbWinBufAlloc), stdcall, Ptr{Cint}, (Clong,), BUF_SIZE)
Count = BUF_SIZE
Rate = int32(BUF_SIZE / NUM_SECS)
# int EXTCCONV cbAInScan (int BoardNum, int LowChan, int HighChan, long Count,
# long *Rate, int Gain, HGLOBAL MemHandle,
# int Options);
ret = ccall((:cbAInScan,"cbw64.dll"), stdcall,
Cint, (Cint, Cint, Cint, Clong, Ptr{Clong}, Cint, Ptr{Cint}, Cint),
BOARDNUM, LOWCHAN, HIGHCHAN, Count, Rate, ADRANGE, Buffer, NOCONVERTDATA)
###ret = ccall(dlsym(dll_handle,:cbAInScan), stdcall,
### Cint, (Cint, Cint, Cint, Clong, Ptr{Clong}, Cint, Ptr{Cint}, Cint),
### BOARDNUM, LOWCHAN, HIGHCHAN, Count, Rate, ADRANGE, Buffer, NOCONVERTDATA)
# int EXTCCONV cbWinBufFree (HGLOBAL MemHandle);
retbuffree = ccall((:cbWinBufFree,"cbw64.dll"), stdcall, Cint, (Ptr{Cint},), Buffer)
###retbuffree = ccall(dlsym(dll_handle,:cbWinBufFree), stdcall, Cint, (Ptr{Cint},), Buffer)
dlclose(dll_handle)
ret
#retbuffree
Il giorno martedì 14 ottobre 2014 09:44:20 UTC+2, Jameson ha scritto:The documentation indicates that these should be stdcall, although if you are on 64-bit windows, that is a no-op#define EXTCCONV __stdcallHow can I include stdcall library in julia kernel for function called by dll...
The error could be that the cbw64.dll call same stdcall function and julia cannot resolv it...
But in this case, you are also passing a number (Rate) to a parameter expecting a pointer. Since pointers are just numbers, Julia doesn't complain, but that won't work so well when C tries to access the pointer. Try passing the address of the value instead `&Rate`
How?I see this example code on julia on line manual:It seem that the "value" -> "pointer to type" conversion is done automatically by julia. When I declare a ptr{Cint} as function argument and pass the value with the ccall, julia convert it to the address of the value, I think reading the example...
function gethostname()
hostname = Array(Uint8, 128)
ccall( (:gethostname, "libc"), Int32,
(Ptr{Uint8}, Uint),
hostname, length(hostname))
return bytestring(convert(Ptr{Uint8}, hostname))
end
Ok. Thank you very much.
The "&rate" modification in ccall arguments solved everythings.
Bye.