I have just started to use EBasic and have just joined this forum.
Have been trying to get the SerialPorts.dll to function as mentioned in this thread.
http://www.ionicwind.com/forums/index.php/topic,3404.msg27290/topicseen.html#msg27290
I have had some success in doing this , using the EBasic ready headers supplied in the other thread.
Here is some test code that i am try to get working.
$MAIN
$use "SerialPorts.lib"
declare cdecl import, ser_GetDllVersion(),string 'This works
declare cdecl import, ser_GetDllCopyright(),string 'This works
declare cdecl import, ser_GetDllDate(),string 'This works
declare cdecl import, ser_GetDllName(),string 'This works
declare cdecl import, ser_CloseComPort( HANDLE hPort ),bool
declare cdecl import, ser_OpenComPort( pointer tInfo ),HANDLE
declare cdecl import, ser_SetDataLenght( HANDLE hPort, eDataLenght eLenght ),bool
declare cdecl import, ser_SetDtrControl( HANDLE hPort, eDTRConfig eDtr ),bool
declare cdecl import, ser_SetParityBit( HANDLE hPort, eParityBit eParity ),bool
declare cdecl import, ser_SetRtsControl( HANDLE hPort, eRTSConfig eRts ),bool
declare cdecl import, ser_SetBaudRate( HANDLE hPort, eBaudRate eBaud ),bool
declare cdecl import, ser_SetStopBits( HANDLE hPort, eStopBits eStop ),bool
declare cdecl import, ser_SetTimeouts( HANDLE hPort, pointer tTimeOuts ),bool
CONST RICHEDIT_1 = 1
CONST RICHEDIT_2 = 2
CONST RICHEDIT_3 = 3
CONST RICHEDIT_4 = 4
CONST RICHEDIT_5 = 5
CONST STATIC_6 = 6
CONST STATIC_7 = 7
CONST STATIC_8 = 8
CONST STATIC_9 = 9
CONST STATIC_10 = 10
DIALOG d1
CREATEDIALOG d1,0,0,450,202,0x80C80080,0,"SerialPorts.Lib",&d1_handler
CONTROL d1,@RICHEDIT,"",80,10,350,20,0x50800000,RICHEDIT_1
CONTROL d1,@RICHEDIT,"",80,40,350,20,0x50800000,RICHEDIT_2
CONTROL d1,@RICHEDIT,"",80,70,350,20,0x50800000,RICHEDIT_3
CONTROL d1,@RICHEDIT,"",80,100,350,20,0x50800000,RICHEDIT_4
CONTROL d1,@RICHEDIT,"",80,130,350,20,0x50800000,RICHEDIT_5
CONTROL d1,@STATIC,"Name",20,13,50,20,0x5000010B,STATIC_6
CONTROL d1,@STATIC,"Version",20,43,50,20,0x5000010B,STATIC_7
CONTROL d1,@STATIC,"Date",20,73,50,20,0x5000010B,STATIC_8
CONTROL d1,@STATIC,"Copyright",20,104,50,20,0x5000010B,STATIC_9
CONTROL d1,@STATIC,"ComPort",20,132,50,20,0x5000010B,STATIC_10
DOMODAL d1
SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
SETCONTROLTEXT(d1,RICHEDIT_1,ser_GetDllName())
SETCONTROLTEXT(d1,RICHEDIT_2,ser_GetDllVersion())
SETCONTROLTEXT(d1,RICHEDIT_3,ser_GetDllDate())
SETCONTROLTEXT(d1,RICHEDIT_4,ser_GetDllCopyright())
/* Initialize any controls here */
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE RICHEDIT_1
/* respond to control notifications here */
CASE RICHEDIT_2
/* respond to control notifications here */
CASE RICHEDIT_3
/* respond to control notifications here */
CASE RICHEDIT_4
/* respond to control notifications here */
CASE RICHEDIT_5
/* respond to control notifications here */
ENDSELECT
ENDSELECT
RETURN
ENDSUB
Now the first 4 lines of imports work fine and i can display the results of these functions.
As to the rest , if I try to use them I cannot compile them as always get errors.
Take this line for an example
ser_CloseComPort( HANDLE hPort ),bool
How do i set the HANDLE and hPort Parts of this , or do I have to define them some How?
Kym
Hi Kym,
A HANDLE is Microsoft specific data type, not known by Ebasic by default. It is defined somewhere in windowssdk.inc.
You can also define it by hand, before the first "declare import":
typedef HANDLE int
The SerialPorts.inc header handles it for you:
$use "SerialPorts.lib"
$ifndef __windowssdk_inc__
typedef HANDLE UINT
...
Wow Sapero ,quick reply.
Ok , where am i going wrong, as I have used the header files that you supplied but,
If i do this i get syntax errors.
ser_CloseComPort( HANDLE hPort ),bool
and some how i have to pass say com1 to the Handle or hPort
then set the baudrate etc.
As I thought the headers already defined these things.
Kym
That's not how you call subroutines/functions
See the section in the help file on "Using Subroutines"
Larry
Ok ,Larry read the instructions ,but still making no sensse of this
we have here:
ser_CloseComPort( HANDLE hPort ),bool
what i need to know is how to pass the correct Values for the (Handle hPort)
part of this.
Kym .
The "HANDLE hport" is the handle returned with the comport was opened.
You have these 2 declares
declare cdecl import, ser_OpenComPort( pointer tInfo ),HANDLE
declare cdecl import, ser_CloseComPort( HANDLE hPort ),bool
the proper syntax would look like:
tInfo MyInfo
MyInfo.blah=...
MyInfo.blah=...
MyInfo.blah=...
MyInfo.blah=...
int myPort
myPort=ser_OpenComPort( &MyInfo )
whatever.....
ser_CloseComPort(myPort)
Something along those lines.
Larry
Well it was something along those lines.
here is what i just tried
def A:int
A = 0 :
DEF COM1 as POINTER
COM1 = A :
ser_OpenComPort(COM1)
ser_CloseComPort(COM1)
and this will open the port and then close it.
if A = 1 then Com2 is set.
Kym
But that still isn't correct.
type tPortInfo
eComPort ePort
eBaudRate eBaud
eStopBits eStop
eDataLenght eLenght
eParityBit eParity
eDTRConfig eDtr
eRTSConfig eRts
endtype
def tInfo as tPortInfo
what you are doing is sending it just the com port and the baud/stop/len/parity/dtr/rts are just picking up whatever garbage is in memory after where the port is stored.
Larry
Maybe this is more to your liking
A = 0 :
DEF COM1 as POINTER
COM1 = A :
ser_OpenComPort(COM1)
ser_SetBaudRate(COM1, 9600)
ser_SetStopBits( COM1, 1 )
ser_SetDataLenght( COM1, 8)
ser_SetParityBit( COM1,0 )
ser_SetDtrControl( COM1, 0 )
ser_SetRtsControl( COM1,0)
ser_CloseComPort(COM1)
yeah still working on it , What would be best is something like this,
ser_OpenComPort(COM1,9600,1,8,1,0,0,0)
But a least I can Open the Com ports now.
the rest will follow, I hope.
Kym
Whatever floats your boat; ;)
I was just going by the .inc referenced at the beginning for the dll.
Glad you got it working.
Larry
Well Water usually Floats my Boat ;D
Thanks For the help.
Kym
Quote from: Kym on January 14, 2010, 10:59:14 PM
, What would be best is something like this,
ser_OpenComPort(COM1,9600,1,8,1,0,0,0)
But a least I can Open the Com ports now.
the rest will follow, I hope.
Kym
D.I.Y - (not tested)
OpenComPort(COM1,9600,1,8,1,0,0,0)
sub openComPort(int port,int BaudRate,int StopBits,int DataLen,int Parity, int Dtr,int Rts)
ser_OpenComPort(port)
ser_SetBaudRate(port, BaudRate)
ser_SetStopBits( port, StopBits )
ser_SetDataLenght( port, DataLen)
ser_SetParityBit( port,Parity )
ser_SetDtrControl( port, Dtr)
ser_SetRtsControl( port,Rts)
endsub
QuoteD.I.Y - (not tested)
Changed this line.
openComPort(Port,9600,1,8,0,0,0)Tester name Kym
Thoughts = Works great , exactly what i was after.
Still only sets 1 bit at a time , but thats how the DLL was written.
Kym