Serial IO Module

BlitzMax Forums/BlitzMax Module Tweaks/Serial IO Module

Nigel Brown(Posted 2005) [#1]
Posted a Serial IO module on the website, with docs and example.


TeaVirus(Posted 2005) [#2]
Nigel,
Have you experimented with using overlapped mode? My app requires continuously streaming data from the comm port and ReadFile causes too long of a delay. Currently, I'm doing the readfile in a seperate thread but I'm wondering if overlapped mode would eliminate the need to do this?


Nigel Brown(Posted 2007) [#3]
@TeaVirus, the short answer is no. Will have a look at it when I get a chance. Need to make this cross platform as a matter of urgency.

Anyhow the reason I looked for this thread again was to announce that I have updated the module hopefully it is as stable as it was now had WriteString() and ReadString() methods. and uses type defined banks so should be a little faster.


Nigel Brown(Posted 2007) [#4]
an example:

Strict

Framework brl.blitz

Import brl.max2d
Import brown.comm

Const comDevice:Int=6

Global port:TComm	

' Create a TComm object
port = New TComm
		
If port.open(comDevice) <> INVALID_HANDLE_VALUE
	' Set baudrate etc..
	port.set( "baud=57600 parity=N data=8 stop=1" )
	' Timeout read 10ms write 10ms
	port.timeout(10,10)
Else
	DebugLog( "Unable to open comm port" + port.LastError() )
EndIf

' A Left
port.WriteString( "sine-wave 0 3000 0~n" )
' B Left
port.WriteString( "sine-wave 2 3000 0~n" )


Global bdelay:Int
Global count:Int

While Not KeyDown( KEY_ESCAPE )
	
	'
	bdelay = bdelay + 1
	If bdelay = 100000

		count :+ 1
		If count > 10 Then count = 0

		Local command:String = "sine-wave 0 3000 " + -count + "~n"
		command :+ "sine-wave 2 3000 " + -count + "~n"

		port.WriteString(command)
		bdelay = 0

	EndIf

Wend

port.WriteString( "silence 0~n" )
port.WriteString( "silence 2~n" )

port.Close()
port = Null



LAB[au](Posted 2007) [#5]
Would this work with a LPT (parallel) port, or could it be adapted?


Nigel Brown(Posted 2007) [#6]
LAB[au] could try changing the COM to LPT and give it a whirl. Its hardcoded in the module.

Another option is google 'dlportio' and use these functions:

.lib "dlportio.dll"

DlPortReadPortUchar%( port% )
DlPortReadPortUshort%( port% )
DlPortReadPortUlong%( port% )

DlPortReadPortBufferUchar( port%, buffer*, count% )
DlPortReadPortBufferUshort( port%, buffer*, count% )
DlPortReadPortBufferUlong( port%, buffer*, count% )

DlPortWritePortUchar( port%, value% )
DlPortWritePortUshort( port%, value% )
DlPortWritePortUlong( port%, value% )

DlPortWritePortBufferUchar( port%, buffer*, count% )
DlPortWritePortBufferUshort( port%, buffer*, count% )
DlPortWritePortBufferUlong( port%, buffer*, count% )