April 30, 2024, 09:46:55 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Serial & Parallel commands in EBASIC

Started by Techno, September 12, 2007, 01:30:59 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Techno

Paul

Can you please add to the commands set serial en parallel support buildin functions or commands for both compilers?
I look forwarded for this functions in the next update
I ask this because the PORT.DLL and RS232 of elektor doesn't work with EBASIC or Aurora. I try to compiled into static library but it doens'nt compatbible.

I have this serial en parallel functions need for my thesis

Thank you

Barney

September 12, 2007, 06:38:28 AM #1 Last Edit: September 12, 2007, 10:01:08 AM by Barney
I presume you are talking about this. Right?

According to the guy who created the DLL, he is using VB with it so there is no reason it can't be used with EBasic. First you need to create an Import library. At the end of import lib creation you'll see the message telling you there are 39 functions alltogether inside the DLL but the author did not explain all of them. Just those that are declared in the example program:


' First let's tell the EBasic we are using "Port.lib" import library
' This library is created by EBasic by examining "Port.dll" file
' Create it by selecting "Tools->Create Import Library" option on the main menu
$USE "Port.lib"

' Now we are declaring some of the functions we are going to use
' Those functions are stored inside "Port.dll" and declares are necessary
' in order for the compiler to know how to use them. Declares and import
' library are also necessary to inform the linker how to link in the final EXE
DECLARE IMPORT, OPENCOM(STRING A),INT
DECLARE IMPORT, CLOSECOM()
DECLARE IMPORT, SENDBYTE(INT b)
DECLARE IMPORT, READBYTE(),INT
DECLARE IMPORT, DTR(INT b)
DECLARE IMPORT, RTS(INT b)
DECLARE IMPORT, TXD(INT b)
DECLARE IMPORT, CTS(),INT
DECLARE IMPORT, DSR(),INT
DECLARE IMPORT, RI(),INT
DECLARE IMPORT, DCD(),INT
DECLARE IMPORT, DELAY(INT b)
DECLARE IMPORT, TIMEINIT()
DECLARE IMPORT, TIMEINITUS()
DECLARE IMPORT, TIMEREAD(),INT64
DECLARE IMPORT, TIMEREADUS(),INT64
DECLARE IMPORT, DELAYUS(INT64 l)
DECLARE IMPORT, REALTIME(INT i): 'Boolean in VB

' We are now ready to create our first program, which will only
' open the COM1 port. The result of the operation will be displayed
' in a message box and the program will terminate closing the COM1 port
' if it was opened.
IF OPENCOM("com1,9600,n,8,1")=0 THEN
MESSAGEBOX(NULL,"Opening COM1 failed","COM1 failure",@MB_OK)
ELSE
MESSAGEBOX(NULL,"COM1 opened successfuly!","COM1 success",@MB_OK)
CLOSECOM()
ENDIF
END


This example will try to open COM1 port and will show the result in the message box. Make sure "port.dll" is either in c:\windows\system32\ folder or in the same folder with the example program. Otherwise the example won't run.

Check Port.dll site for more VB examples and general description of how Port.dll is to be used.

As you can see, EBasic does have everything you  need. So start playing with COM ports now. You don't need to wait for Paul to add native COM port functionality. Also, you can use COM ports by using Windows API but I reckon that path is too hard for you at your present level.

Click here to download the complete Port.dll tutorial, which explains the rest of the available functions (Parallel port, Joysticks, Audio).

Docs and info found on the web do differ in the syntax for opening the COM ports. At some places the command string is given as "com1,9600,n,8,1" and on other places "com1:9600,n,8,1" was used. It seems both are working but further testing is needed to establish the exact syntax.

Barney

tbohon

Good information, Barney - thanks for sharing.

Is there by chance an English version of the port.dll tutorial/reference?  It's been 45+ years since my 1 semester German course and I'm a, shall we say, tad bit 'rusty' ... :)

Tnx.

Tom
"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)

Barney

September 12, 2007, 08:22:35 AM #3 Last Edit: September 12, 2007, 08:25:31 AM by Barney
I am just in the process of creating a proper include file, which will include all the declares for the functions inside Port.dll. Don't have time for the full translation of the PDF right now, but include file will be properly commented in English, so you'll be able to find your way through this interesting DLL.

Time permitting, I'll also try to create some OOP classes for Port.dll usage. Perhaps some people will find OOP approach easer than pure procedural function usage.

Barney

Techno

Barney

Can you please checked if my include file is CORRECT for using this DLL

DECLARE IMPORT, OUTPORT(WORD PortAddr, Datawoord AS CHAR)
DECLARE IMPORT, INPORT(WORD PortAddr), CHAR
DECLARE IMPORT, Inp32 (PortAddr AS WORD BYVAL),INT
DECLARE IMPORT, Out32 (PortAddr AS WORD BYVAL, Datawoord AS INT BYVAL)


DECLARE IMPORT, OPENCOM(STRING port),INT
DECLARE IMPORT, CLOSECOM()
DECLARE IMPORT, READBYTE(),INT
DECLARE IMPORT, SENDBYTE(INT databyte),INT
DECLARE IMPORT, DTR(INT status)
DECLARE IMPORT, RTS(INT status)
DECLARE IMPORT, TXD(INT status)
DECLARE IMPORT, CTS(),INT
DECLARE IMPORT, DSR(),INT
DECLARE IMPORT, RI(),INT
DECLARE IMPORT, DCD(),INT
DECLARE IMPORT, DELAY(INT iDelay)
DECLARE IMPORT, DELAYUS(INT64 lDelay)
DECLARE IMPORT, TIMEOUT(WORD PortWord), INT
DECLARE IMPORT, TIMEINIT()
DECLARE IMPORT, TIMEINITUS()
DECLARE IMPORT, TIMEREAD(), INT64
DECLARE IMPORT, TIMEREADUS(),INT64
DECLARE IMPORT, REALTIME(INT time)


DECLARE IMPORT, SOUNDIS(), INT
DECLARE IMPORT, SOUNDCAPIN()
DECLARE IMPORT, SOUNDCAPOUT()
DECLARE IMPORT, SOUNDIN(p AS STRING, Size AS  INT)
DECLARE IMPORT, SOUNDOUT(p AS STRING, Size AS INT)
DECLARE IMPORT, SOUNDGETRATE(), WORD
DECLARE IMPORT, SOUNDSETRATE(dwRate AS INT64), INT64
DECLARE IMPORT, SOUNDGETBYTES(), WORD
DECLARE IMPORT, SOUNDSETBYTES(iRate AS INT), INT
DECLARE IMPORT, SOUNDBUSY(), INT


'DECLARE IMPORT, JOYSTICKX(), INT
'DECLARE IMPORT, JOYSTICKY(), INT
'DECLARE IMPORT, JOYSTICKR(), INT
'DECLARE IMPORT, JOYSTICKU(), INT
'DECLARE IMPORT, JOYSTICKV(), INT
'DECLARE IMPORT, JOYBUTTON(), INT
'DECLARE IMPORT, JOYSTICK(X AS INT64, Y AS INT64, Z AS INT64, R AS INT64, U AS INT64, V AS INT64, B AS INT64), INT





Barney

September 12, 2007, 08:30:27 AM #5 Last Edit: September 12, 2007, 08:32:09 AM by Barney
Change WORD to INT and you don't need BYVAL specifier. Take a look at my code, posted above. I'll have the commented include file ready within next hour.

Barney

Techno

Barney

Can you give me some examples for using port.dll

Techno

Barney

Is my updated include file correct?



$USE "port.lib"
$USE "inpout32.lib"

'======================================================================================================================='
' Port.dll '
'======================================================================================================================='

'==============================================='
'1. Parallel port Control '
'This functions doesn't work to Win2k and WinXP '
'==============================================='
DECLARE IMPORT, OUTPORT(INT PortAddr, Datawoord AS CHAR)
DECLARE IMPORT, INPORT(INT PortAddr), CHAR

'======================='
'2. Control the UART '
'======================='
DECLARE IMPORT, OPENCOM(STRING port),INT
DECLARE IMPORT, CLOSECOM()
DECLARE IMPORT, READBYTE(),INT
DECLARE IMPORT, SENDBYTE(INT databyte),INT
DECLARE IMPORT, DTR(INT status)
DECLARE IMPORT, RTS(INT status)
DECLARE IMPORT, TXD(INT status)
DECLARE IMPORT, CTS(),INT
DECLARE IMPORT, DSR(),INT
DECLARE IMPORT, RI(),INT
DECLARE IMPORT, DCD(),INT

'======================='
'3. Software Timer '
'======================='
DECLARE IMPORT, DELAY(INT iDelay)
DECLARE IMPORT, DELAYUS(INT64 lDelay)
DECLARE IMPORT, TIMEOUT(INT PortWord), INT
DECLARE IMPORT, TIMEINIT()
DECLARE IMPORT, TIMEINITUS()
DECLARE IMPORT, TIMEREAD(), INT64
DECLARE IMPORT, TIMEREADUS(),INT64
DECLARE IMPORT, REALTIME(INT time)

'========================'
'4. Soundcard Control '
'========================'
DECLARE IMPORT, SOUNDIS(), INT
DECLARE IMPORT, SOUNDCAPIN()
DECLARE IMPORT, SOUNDCAPOUT()
DECLARE IMPORT, SOUNDIN(STRING p, INT Size)
DECLARE IMPORT, SOUNDOUT(STRING p, INT Size)
DECLARE IMPORT, SOUNDGETRATE(), INT
DECLARE IMPORT, SOUNDSETRATE(INT64 dwRate), INT64
DECLARE IMPORT, SOUNDGETBYTES(), INT
DECLARE IMPORT, SOUNDSETBYTES(INT iRate), INT
DECLARE IMPORT, SOUNDBUSY(), INT

'========================'
'5. Joystick Control '
'========================'
'DECLARE IMPORT, JOYSTICKX(), INT
'DECLARE IMPORT, JOYSTICKY(), INT
'DECLARE IMPORT, JOYSTICKR(), INT
'DECLARE IMPORT, JOYSTICKU(), INT
'DECLARE IMPORT, JOYSTICKV(), INT
'DECLARE IMPORT, JOYBUTTON(), INT
'DECLARE IMPORT, JOYSTICK(X AS INT64, Y AS INT64, Z AS INT64, R AS INT64, U AS INT64, V AS INT64, B AS INT64), INT

'======================================================================================================================='
' ImpOut32.dll '
'======================================================================================================================='
DECLARE IMPORT, Inp32 (INT PortAddr),INT
DECLARE IMPORT, Out32 (INT PortAddr, INT Datawoord)









Barney

Here's the new version of the include file, where all the functions available in Port.dll are declared. Code is heavily commented and I hope it will be of use to those who'd like to use Port.dll functions.


'------------------------------------------------------------------------------
' PortDLL.inc
' Created by Branko Spoljaric - Barney
' Version: 0.1
'------------------------------------------------------------------------------
' Port.dll is a DLL containing a very useful libary of comm functions
' It has been part of Elektor magazine project and can be found at many web
' sites. This include file is made in hope that it will make the usage of
' Port.dll easier for the users of Emergence Basic. A great free BASIC like
' language created by Paul Turley and available at www.ionicwind.com
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
' First let's tell the EBasic we are using "Port.lib" import library
' This library is created by EBasic by examining "Port.dll" file
' Create it by selecting "Tools->Create Import Library" option on the main menu
'------------------------------------------------------------------------------
$USE "Port.lib"

'------------------------------------------------------------------------------
' Now we are declaring some of the functions we are going to use
' Those functions are stored inside "Port.dll" and declares are necessary
' in order for the compiler to know how to use them. Declares and import
' library are also necessary to inform the linker how to link in the final EXE
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
' COM ports specific stuff
'------------------------------------------------------------------------------
' In order to do anything with the COM port we need to open it and after we are
' done with it, we have to close it properly. This is exactly what OPENCOM and
' CLOSECOM functions are doing.
' OPENCOM requires a string parameter which can be simple "com1" or complex.
' Most basic command will be OPENCOM("com1") and will open COM1 port with
' standard values for speed, parity and stop bits. More complex command allows
' us to set the comm speed, parity control and number of data and stop bits
' used. For example, "com1:9600,n,8,1" command will try to open a COM1 port and
' set the speed to 9600 bits/sec, no parity, 8-bits of data and one stop bit.
' For parity you can use N (no parity), O (odd parity) or E (even parity)
' Number of data bits is either 7 or 8
' Number of stop bits is the number of bits between two data bytes
' The return value of 0 indicates failure to open COM port
'------------------------------------------------------------------------------
DECLARE IMPORT, OPENCOM(STRING A),INT
DECLARE IMPORT, CLOSECOM()
'------------------------------------------------------------------------------
' COM ports specific stuff
'------------------------------------------------------------------------------
' There are four input lines at each COM port
'
' DCD - Data Carrier Detect
' DSR - Data Send Request
' CTS - Clear to Send
' RI  - Ring Indicator
'
' Functions are named exactly the same as the lines and they don't need any
' inpit parameters. The returning value is either 0 or 1 indicating line
' low (0) or high (1)
'------------------------------------------------------------------------------
DECLARE IMPORT, DCD(),INT
DECLARE IMPORT, DSR(),INT
DECLARE IMPORT, CTS(),INT
DECLARE IMPORT, RI(),INT
'------------------------------------------------------------------------------
' COM ports specific stuff
'------------------------------------------------------------------------------
' There are three output lines at each COM port
'
' TXD - Transmit Data
' DTR - Data Terminal Ready
' RTS - Request To Send
'
' Functions are named exactly the same as the lines and they all need one input
' parameter, which can be either 0 or 1. For example, if we want to tell the
' listener we want to send data we will use RTS(1) function and then wait for
' the answer via CTS() function
'------------------------------------------------------------------------------
DECLARE IMPORT, TXD(INT b)
DECLARE IMPORT, DTR(INT b)
DECLARE IMPORT, RTS(INT b)
'------------------------------------------------------------------------------
' LPT port specific stuff
'------------------------------------------------------------------------------
' We have two functions here. SENDBYTE is sending a byte of data to LPT port,
' while READBYTE is reading a byte of data from LPT port. Even though input
' and ooutput values are INT (32-bit) only the lowest 8-bits will be valid, so
' make sure you are only sending values between 0 and 255. Values received will
' also be inside 0-255 range
'------------------------------------------------------------------------------
DECLARE IMPORT, SENDBYTE(INT b)
DECLARE IMPORT, READBYTE(),INT
'------------------------------------------------------------------------------
' PRIORITY
'------------------------------------------------------------------------------
' Here we have just one function, which will give the program highest possible
' priority (parameter set to TRUE), or return it to normal priority processing
' (parameter set to FALSE)
'------------------------------------------------------------------------------
DECLARE IMPORT, REALTIME(INT i)
'------------------------------------------------------------------------------
' DELAY times
'------------------------------------------------------------------------------
' Following two functionw define the time a program will wait before continuing
' execution.
' DELAY will wait for a given number of milliseconds and
' DELAYUS will wait for a given number of microseconds, which gives us more
' precision, but we have to use 64-bit value instead of the usual 32-bit
'------------------------------------------------------------------------------
DECLARE IMPORT, DELAY(INT b)
DECLARE IMPORT, DELAYUS(INT64 l)
'------------------------------------------------------------------------------
' TIME functiona
'------------------------------------------------------------------------------
' This set of functions is important for various time measurements. Just as
' with DELAY functions, TIME functions also operate on millisecond or
' microsecond basis.
' TIMEINIT and TIMEINITUS will reset the timers to zero and start them again
' with ms or us precision
' TIMEREAD and TIMEREADUS functions will read the amount of time (in ms or us)
' since the last TIMEINIT or TIMEINITUS function was executed. Both functions
' return a 64-bit integer
'------------------------------------------------------------------------------
DECLARE IMPORT, TIMEINIT()
DECLARE IMPORT, TIMEINITUS()
DECLARE IMPORT, TIMEREAD(),INT64
DECLARE IMPORT, TIMEREADUS(),INT64
'------------------------------------------------------------------------------
' COM and LPT ports common stuff
'------------------------------------------------------------------------------
' These two functions are not tied up to Win API. They try to get to the
' hardware directly and are faster than the rest of the comm functions.
' The parameters passed to the OUTPORT function are the address of the COM or
' LPT port we want to send the data to, and an 8-bit (byte) data value.
' INPORT function accepts the address of the COM or LPT port only and returns
' an 8-bit data value. Due to their nature (direct hardware access) these
' functions should be used with care and are not guaranteed to always work
'------------------------------------------------------------------------------
DECLARE IMPORT, OUTPORT(INT a, INT b)
DECLARE IMPORT, INPORT(INT p),INT
'------------------------------------------------------------------------------
' Regardng JOYSTICK and AUDIO functions. I did not research much into them,
' so I am not 100% sure if the declarations are correct and I definitely
' cannot guarantee the functions will work. Try them at your own risk.
'------------------------------------------------------------------------------
' JOYSTICK functions - not guaranteed to be correct or working
'------------------------------------------------------------------------------
DECLARE IMPORT, PD_JOYX ALIAS JOYX(),INT64
DECLARE IMPORT, PD_JOYY ALIAS JOYY(),INT64
DECLARE IMPORT, PD_JOYZ ALIAS JOYZ(),INT64
DECLARE IMPORT, JOYW(),INT64
DECLARE IMPORT, JOYBUTTON(),INT
'------------------------------------------------------------------------------
' AUDIO functions - not guaranteed to be correct or working
'------------------------------------------------------------------------------
DECLARE IMPORT, SOUNDSETRATE(INT iRate),INT
DECLARE IMPORT, SOUNDGETRATE(),INT
DECLARE IMPORT, SOUNDBUSY(),INT
DECLARE IMPORT, SOUNDIS(),INT
DECLARE IMPORT, SOUNDIN(STRING sBuffer, INT iSize)
DECLARE IMPORT, SOUNDOUT(STRING sBuffer, INT iSize)
DECLARE IMPORT, SOUNDGETBYTES(),INT
DECLARE IMPORT, SOUNDSETBYTES(INT b),INT
DECLARE IMPORT, SOUNDCAPIN()
DECLARE IMPORT, SOUNDCAPDOUT()


@Techno: I don't have time to go through your code now. Compare it with my include file and see if your functions are declared correctly. Or just use my file. I glanced briefly at your code and it seems to be O.K., but check it again, nevertheless.

I cannot give you any examples because I am not interested in using COM or LPT ports at the moment. I only did this because you asked for help with initial declares, but I don't have the intention of writing a full blown communication program for you. Firstly, as I've said, I don't work with COM and LPT, and secondly, if you get everything served on a plate, how on earth will you learn to do something on your own? Also, I don't have the external (DB-9) RS-232 connection available on my computer and I don't fancy the idea of installing the virtual COM ports just so that I can write some examples. If I manage to put something together at the office computer, I'll post it, but don't expect it to happen any time soon.

The include file is also attached to this post.

Barney