April 26, 2024, 11:56:05 AM

News:

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


Simple console mode program using the Serial Comms Library.

Started by Egil, October 19, 2014, 07:02:12 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Egil

This code was made to demonstrate a simple way to use the Serial Comms Library. Also attach a zip archive containing the compiled code. The image show program startup and what happens when I start a TNC (a radio modem using modified X-25 protocol), and connect to the TNC's built in BBS.

Have fun!



'
' Cterm.iwb   -  using the Ionic Wind Serial Communications Library
' Simple console test program for serial port communications
' Author: Egil - LA2PJ
'
int COMPORT, BAUD
string key$, rxd$
rxd$=""

OPENCONSOLE
ConsoleTitle("Cterm.iwb  -  Simple Comms Terminal")
FindComPorts()
print
input "ENTER ComPort number..: ",COMPORT
input "ENTER a valid BaudRate: ",BAUD
print
if IWOpenPort(COMPORT,BAUD)
print"COM",COMPORT, "READY at ",BAUD,"baud    -    Press ESCAPE to stop     "
print
else
print "Unable to open COM",COMPORT
print
print "Press any key to end"
do:until inkey$<>""
end
endif

' Loop until ESC is presed
DO
' Rxd:
rxd$ = GetRxD(COMPORT)
if rxd$<>""
print rxd$,
rxd$=""
endif

' Txd:
key$=""
key$ = INKEY$
IF key$ <> ""
IWSendPort(COMPORT,key$,1)
if key$ = chr$(13) then print
print key$,
ENDIF
UNTIL GETKEYSTATE(0x1B)

IWClosePort(COMPORT)
WAITCON
END

'
' Reads whatever arrives at the comport
'----------------------------------------------------------------------------------------
SUB GetRxD(cport:int),string
dim ret[512]:istring
dim pRet:pointer
dim cnt,buf:int
pRet = ret
if IWGetBytesWaiting(cport)
buf = IWGetBytesWaiting(cport)
cnt = IWReadPort(cport,pRet,buf)
ret[cnt] = ""
else
ret=""
endif
RETURN ret
ENDSUB

'
'----------------------------------------------------------------------------------------
' Tries to open all the 256 possible Windows ComPorts at 115200 baud.
' Any port that opens, is reported on the screen.
'
SUB FindComPorts()
dim pp:int
print"Searching for ComPorts - Please wait......"
print
color 14,0
for pp = 1 to 20
if IWOpenPort(pp,115200)
print "ComPort number ",pp , " available"
IWClosePort(pp)
endif
next pp

color 7,0
ENDSUB

'
' Set Console Title
'----------------------------------------------------------------------------------------
'
SUB ConsoleTitle(title:string)
DECLARE "Kernel32.dll",SetConsoleTitle Alias SetConsoleTitleA(lpConsoleTitle:String)
SetConsoleTitle(title)
ENDSUB



Support Amateur Radio  -  Have a ham  for dinner!