News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Undocumented? Unstable? or Undiscovered?

Started by dexter, July 10, 2005, 10:52:54 AM

Previous topic - Next topic

dexter

QuoteNo worries, what are you working on anyway ?  Im just a little curious !

I keep missing your posts while I'm typing replies  :lol:

I'm making a gps track editor/map maker culminating in a freely available in car navigation/entertainment system. (thought I'd start small  :D)

I was looking at using a number of other basic's but what swung it for PlayBasic was the shape/collision commands.

kevin

Well that's honestly something I would have never imagined PB being used for.  

 Although, I'm glad you like the collision stuff.  As there's some more (at least one) to come :)

dexter

QuoteWell that's honestly something I would have never imagined PB being used for. 

  Although, I'm glad you like the collision stuff.  As there's some more (at least one) to come :)

The measure of a great language.....versatility!

more collision stuff, great, can't wait  :)

Now if only I could RotateCamera  :blink:

kevin

Rotating the scene through a camera is something we've been think about for while, but it's not easily achieved.  Most vector stuff can be translated easy enough, but it's image buffers in vid memory that cause the drama.      

 Something for PBFX later on  :)

empty

There was an error in the code I posted. :unsure:

new version

; Load Dll
Global kernel32 = GetFreeDll()
LoadDll "kernel32.dll", kernel32

; Time-Out Struct
Type COMMTIMEOUTS
 ReadIntervalTimeout, ReadTotalTimeoutMultiplier
 ReadTotalTimeoutConstant, WriteTotalTimeoutMultiplier
 WriteTotalTimeoutConstant
EndType



Psub OpenCom(Comport$)
; Open a com port
Local hcom = CallDll(kernel32, "CreateFileA", Comport$, $C0000000, 0, 0, 3, $80, 0)

; set the default time out
Dim timeout As COMMTIMEOUTS
timeout.ReadIntervalTimeout = 0
timeout.ReadTotalTimeoutMultiplier = 0
timeout.ReadTotalTimeoutConstant = 1000
timeout.WriteTotalTimeoutMultiplier = 0
timeout.WriteTotalTimeoutConstant = 1000
CallDll(kernel32, "SetCommTimeouts", hcom, timeout.COMMTIMEOUTS)
EndPsub hcom

Psub ConfigureCom(Handle, ConfigString$)
 ; set the config string (baud rate, parity etc)
  Local DCB = GetFreeBank()
  CreateBank DCB, 28
  CallDll(kernel32, "GetCommState", Handle, GetBankPtr(DCB))
  CallDll(kernel32, "BuildCommDCBA", ConfigString$, GetBankPtr(DCB))
  CallDll(kernel32, "SetCommState", Handle, GetBankPtr(DCB))
  DeleteBank DCB
EndPsub

Psub ComBufferSize(Handle, InBuffer, OutBuffer)
 ; buffer size of the rx and tx data (256 bytes is common value)
 ; depending on the data size and the "poll" speed you need
 ; you can increase (or more likely) decrease this value.
  CallDll(kernel32, "SetupComm", Handle, InBuffer, OutBuffer)
EndPsub

Psub ReadCom(Handle)
 ; read the string
  Local result$ = Make$(" ", 256)
  BytesRead = GetFreeBank()
  CreateBank BytesRead, 4
  CallDll(kernel32, "ReadFile", Handle, result$, 256, GetBankPtr(BytesRead), 0)
  Local i = PeekBankInt(BytesRead, 0)
  DeleteBank BytesRead
EndPsub result$, i

Psub CloseCom(Handle)
  CallDll(kernel32, "CloseHandle", Handle)
EndPsub



; TEST

; Open the port
handle = OpenCom("COM2")
; Set the Buffer sizes
ComBufferSize(Handle, 256, 256)
; configure the port (modify the string to your needs)
ConfigureCom(Handle, "baud=19200 parity=n data=8 stop=1")
; read a string and the number of bytes that were actually read
; you can repeat that function call in a loop
For i = 1 To 10
  s$, bytesread = ReadCom(handle)
  Print "Result String       : " + s$
  Print "Number of Bytes read: " + Str$(bytesread)
  Sync
Next i

Print "10 values read. Press any key"
WaitKey

; close the port
CloseCom(Handle)

DeleteDll(kernel32)

dexter

brilliant, thanks empty, works fine! (apart from a missing sync command)

Print "10 values read. Press any key"
Sync
WaitKey


Leave me all the hard work why don't you  :lol:

Just tried to attach a jpg to show the output but it doesn't seem to attach?

empty

Glad it works. :)
Will need your assistance when I write a complete library for it. ;)

QuoteJust tried to attach a jpg to show the output but it doesn't seem to attach?
Yeah, attachments don't work for me either....