April 25, 2024, 05:42:43 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Serial port drive : Blinking LED

Started by Techno, September 21, 2008, 01:23:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Techno

Dear Support

I use the library "inpout32.dll" for control the serial port because EBASIC doesn"t have this functions.
The website of the vendor is :
http://logix4u.net/Legacy_Ports/Parallel_Port/How_Inpout32.dll_works_.html
http://logix4u.net/inpout32_source_and_bins.zip

The original include file from Visual C++
========================

/* ----Prototypes of Inp and Outp--- */

short _stdcall Inp32(short PortAddress);
void _stdcall Out32(short PortAddress, short data);

I have got the next error linking



DECLARE "inpout32", Inp32(PortAddr : WORD), CHAR
DECLARE "inpout32", Out32(PortAddr : WORD, PortData : WORD)
CONST BASE_ADDRESS = 0x3E8
OPENCONSOLE
Out32 (BASE_ADDRESS + 4, 1)

DEF n : INT
FOR n = 1 TO 1000 : NEXT n
Out32 (BASE_ADDRESS + 4, 0)
FOR n = 1 TO 1000 : NEXT n
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE

Error:
===

No compile time errors !

Compiling...
EBASIC1.eba
No Errors

Linking...
Emergence Linker v1.11 Copyright ÂÃ,© 2006 Ionic Wind Software
Unresolved external __imp_Out32
Error: Unresolved extern __imp_Out32
Error(s) in linking C:\EBASIC1.exe



Can somebody help me what is wrong in miy program

With kind regards
Stephane

Ionic Wind Support Team

You need to create an import library for the DLL using the tools menu from the emergence IDE.

And then:

$use "inpout32.lib"
DECLARE import, Inp32(PortAddr : WORD), word
DECLARE import, Out32(PortAddr : WORD, PortData : WORD)

See:  Users Guide->Language->Using DLL's and the Windows API

FYI most likely Vista would prevent use of the DLL, so you'll need to use the API to read/write to com ports, examples of usages are included with Emergence.

Paul.
Ionic Wind Support Team

Techno

Paul Thanks for you quickly request

I have now an other question:

I try to port VB6 code into EBASIC but I will this application for EBASIC

I try this:

VB60 code:
=======

Text2.Text = Str(Inp(Val("&H" + Text1.Text)))

Into EBASIC code
===========
IF @NOTIFYCODE = 0
      /*button clicked Input*/
      DEF text : CHAR
      '===============================
      ' Text2.Text = Str(Inp(Val("&H" + Text1.Text)))
      '===============================
     text = GETCONTROLTEXT (d1, BUTTON_1)
     text = Str(Inp32(Val("h" + SETCONTROLTEXT (d1, BUTTON_1, text)
.....

Is that correct?

I don't know it doesn"t works

Stephane


sapero

declare extern _sscanf(string buf,string format,...),int

int port
' read hexadecimal port number
_sscanf(GetControlText(d1, IDC_PORT), "%x", &port) /* Text1.Text */
' format I/O data as hex
SetControlText(d1, IDC_DATABUS, hex$(Inp32(port))) /* Text2.Text */


Change %x to %d if you entered decimal string.

Techno

Thanks for help me but how can I this ported into EBASIC ?

VB60 code
=======

1ste Question
=========


Out Val("&H" + Text1.Text), Val(Text2.Text)


Can you this ported into EBASIC but I don't know how do that.

2e Question
========

I will run my GUI application it compile en linking fine but where is show my dialog?
I doesn't show my application and I use ShowDialog statement


CONST BUTTON_1 = 1
CONST BUTTON_2 = 2
CONST EDIT_3 = 3
CONST EDIT_4 = 4
CONST STATIC_5 = 5
CONST STATIC_6 = 6

$USE "inpout32.lib"
DECLARE IMPORT, Inp32(PortAddr : WORD), WORD
DECLARE IMPORT, Out32(PortAddr : WORD, PortData : WORD)
DECLARE EXTERN _sscanf(STRING buf, STRING format,...),INT
DECLARE EXTERN sprintf(POINTER p, POINTER p, ...), INT

DIALOG d1, hDlg

CREATEDIALOG d1,0,0,277,125,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@SYSBUTTON,"Input",33,77,105,32,0x50000000,BUTTON_1
CONTROL d1,@SYSBUTTON,"Output",168,77,94,31,0x50000000,BUTTON_2
CONTROL d1,@EDIT,"Edit1",34,46,101,23,0x50800000,EDIT_3
CONTROL d1,@EDIT,"Edit2",170,47,91,21,0x50800000,EDIT_4
CONTROL d1,@STATIC,"Address",37,14,97,20,0x5000010B,STATIC_5
CONTROL d1,@STATIC,"Data",168,15,92,22,0x5000010B,STATIC_6
INT run

/*run = 1
WAITUNTIL run = 0 */
SHOWDIALOG hDlg, d1
END

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
CASE @IDCLOSEWINDOW
run = 0
CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_1 /* Input */
IF @NOTIFYCODE = 0
/*button clicked*/
/* VB60 code */
/* Text2.Text = Str(Inp(Val("&H" + Text1.Text))) */
/* Read hexadecimal port number */
INT PortAddress
_sscanf(GETCONTROLTEXT(d1, EDIT_3), "%x", PortAddress) /* Text1.Text */
/* format I/O data as hex */
SETCONTROLTEXT(d1, EDIT_4, HEX$(INP32(PortAddress)))   /* Text2.Text */
ENDIF
CASE BUTTON_2 /* Output */
IF @NOTIFYCODE = 0
/*button clicked*/
/* VB60 code */
/* Out Val("&H" + Text1.Text), Val(Text2.Text) */
/* How can do this port into EBASIC */
ENDIF
CASE EDIT_3 /* Text1 */
/* respond to edit notifications here */
CASE EDIT_4 /* Text2 */
/* respond to edit notifications here */
ENDSELECT
ENDSELECT
RETURN
ENDSUB


Can someone help my for this 2 problems
Is there an other manner without using sscanf() but only SETCONTROLTEXT en GETCONTROLTEXT ?

sapero

September 21, 2008, 09:22:32 AM #5 Last Edit: September 21, 2008, 09:24:12 AM by sapero
If you don't like sscanf, you must type port address in decimal notation, for example 888 for LPT1, and use the standard VAL function to convert it from a string to integer. Note that EB's VAL does not handle hexadecimal strigs.
If you want to set all bits to 1, type 255 instead FF into EDIT_4
CASE BUTTON_1 /* Input */
IF @NOTIFYCODE = 0
/*button clicked
EDIT_4 = Inp32(EDIT_3)*/
SETCONTROLTEXT(d1, EDIT_4, STR$(Inp32(VAL(GETCONTROLTEXT(d1, EDIT_3)))))
ENDIF
CASE BUTTON_2 /* Output */
IF @NOTIFYCODE = 0
/*button clicked
Out32(EDIT_3, EDIT_4)*/
Out32(VAL(GETCONTROLTEXT(d1, EDIT_3)), VAL(GETCONTROLTEXT(d1, EDIT_4)))
ENDIF

LarryMc

You need to swao these 2 statements in order to show your dialog:

WAITUNTIL run = 0 */
SHOWDIALOG hDlg, d1


to this
SHOWDIALOG hDlg, d1
WAITUNTIL run = 0 */


Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Techno

Hi Sapero

Thanks for your requests but there are a few errors. I implement your solutions and hints.



CONST BUTTON_1 = 1
CONST BUTTON_2 = 2
CONST EDIT_3 = 3
CONST EDIT_4 = 4
CONST STATIC_5 = 5
CONST STATIC_6 = 6

$USE "inpout32.lib"
DECLARE IMPORT, Inp32(PortAddr : WORD), WORD
DECLARE IMPORT, Out32(PortAddr : WORD, PortData : WORD)
DECLARE EXTERN _sscanf(STRING buf, STRING format,...),INT
DECLARE EXTERN sprintf(POINTER p, POINTER p, ...), INT

DIALOG d1
CREATEDIALOG d1,0,0,277,125,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@SYSBUTTON,"Input",33,77,105,32,0x50000000,BUTTON_1
CONTROL d1,@SYSBUTTON,"Output",168,77,94,31,0x50000000,BUTTON_2
CONTROL d1,@EDIT,"Edit1",34,46,101,23,0x50800000,EDIT_3
CONTROL d1,@EDIT,"Edit2",170,47,91,21,0x50800000,EDIT_4
CONTROL d1,@STATIC,"Address",37,14,97,20,0x5000010B,STATIC_5
CONTROL d1,@STATIC,"Data",168,15,92,22,0x5000010B,STATIC_6
INT run, hDlg

run = 1
WAITUNTIL run = 0
END

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
CASE @IDCLOSEWINDOW
run = 0
CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_1 /* Input */
IF @NOTIFYCODE = 0
/*button clicked*/
/* VB60 code */
/* Text2.Text = Str(Inp(Val("&H" + Text1.Text))) */
/* Read hexadecimal port number */
INT Port
_sscanf(GETCONTROLTEXT(d1, EDIT_3), "%x", Port) /* Text1.Text */
/* format I/O data as hex */
SETCONTROLTEXT(d1, EDIT_4, HEX$(INP32(Port)))   /* Text2.Text */
/* Second manner */
/* EDIT_4 = Inp32(EDIT_3) */
/* SETCONTROLTEXT(d1, EDIT_4, STR$(Inp32(VAL(GETCONTROLTEXT)))) */
ENDIF
CASE BUTTON_2 /* Output */
IF @NOTIFYCODE = 0
/*button clicked*/
/* Out Val("&H" + Text1.Text), Val(Text2.Text) */
EDIT_4 = Inp32(EDIT_3)
SETCONTROLTEXT(d1, EDIT_4, STR$(Inp32(VAL(GETCONTROLTEXT)))
ENDIF
CASE EDIT_3 /* Text1 */
/* respond to edit notifications here */
CASE EDIT_4 /* Text2 */
/* respond to edit notifications here */
ENDSELECT
ENDSELECT
RETURN
ENDSUB



Error Report
========

Compiling...
Example1.eba
File: E:\Documents and Settings\id760126\Mijn documenten\Emergence BASIC\projects\Example1.eba (44) Warning: Uninitialized variable: Port - )
File: E:\Documents and Settings\id760126\Mijn documenten\Emergence BASIC\projects\Example1.eba (55) constant definition cannot be assigned
File: E:\Documents and Settings\id760126\Mijn documenten\Emergence BASIC\projects\Example1.eba (56) syntax error
File: E:\Documents and Settings\id760126\Mijn documenten\Emergence BASIC\projects\Example1.eba (62) wrong number of parameters - ENDSELECT
Error(s) in compiling "E:\Documents and Settings\id760126\Mijn documenten\Emergence BASIC\projects\Example1.eba"

What wrong here?

Stephane

LarryMc

September 21, 2008, 10:30:21 AM #8 Last Edit: September 21, 2008, 10:33:29 AM by Larry McCaughn
EDIT_4 = Inp32(EDIT_3)
SETCONTROLTEXT(d1, EDIT_4, STR$(Inp32(VAL(GETCONTROLTEXT)))


EDIT_4 is a constant that you can't assign a variable to
GETCONTROLTEXT by itself is an incomplete command.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Techno

Larry

I don't understand what you main.

EDIT_4 = Inp32(EDIT_3)
SETCONTROLTEXT(d1, EDIT_4, STR$(Inp32(VAL(GETCONTROLTEXT)))

How can I this program this is correct code?

I try this:
SETCONTROLTEXT(d1, EDIT_4, STR$(Inp32(VAL(GETCONTROLTEXT(d1, EDIT_3)))))

Is that correct?

sapero

September 21, 2008, 10:49:34 AM #10 Last Edit: September 21, 2008, 10:53:15 AM by sapero
Stephane, I think you need a complete example! (attached)
QuoteIF @NOTIFYCODE = 0
                  /*button clicked
                  EDIT_4 = Inp32(EDIT_3)*/
This was a remark, not real code.

Techno

Sapero

Thanks for your big help
I'm going how this code works for other applications

Thanks
Stephane