Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "windows.bi"
- #include "vbcompat.bi"
- #include "crt.bi"
- #include "fbgfx.bi"
- enum ComModes 'COM Port Read/Write Mode
- cmRead = 1
- cmWrite = 2
- cmReadWrite = 3
- end enum
- function OpenCOM(sPORT as string="COM1:",sConfig as string="",iMode as integer=3,iFile as integer) as integer
- dim as DCB SerialConfig = type(sizeof(DCB))
- dim as string sPortB = !"\\\\.\\"+sPORT
- if len(sConfig) then
- if BuildCommDCB(sConfig,@SerialConfig)=0 then return 1 'Illegal Function Call
- end if
- dim as integer iResu,iModeWin
- select case (iMode and 3)
- case 0: return 1 'Illegal Function Call
- case 1
- iModeWin = GENERIC_READ
- iResu = open("NUL" for binary access read as #iFile)
- case 2
- iModeWin = GENERIC_WRITE
- iResu = open("NUL" for binary access write as #iFile)
- case 3
- iModeWin = GENERIC_READ or GENERIC_WRITE
- iResu = open("NUL" for binary as #iFile)
- end select
- if iResu then return iResu
- var pTemp = cast(FILE ptr,fileattr(iFile,2))
- if pTemp = 0 then close #iFile: return -1
- setvbuf(pTemp,null,_IONBF,0)
- var hComm = CreateFile(sPortB,iModeWin,null,null,OPEN_EXISTING,null,null)
- if hComm = INVALID_HANDLE_VALUE then close #iFile: return 2 'File Not Found
- if len(sConfig) andalso SetCommState(hComm,@SerialConfig) = 0 then
- close #iFile: return 3 'File I/O error '
- end if
- fflush(pTemp): _close(pTemp->_file)
- pTemp->_file = _open_osfhandle(cast(long,hComm),null)
- var dwFlags = EV_BREAK or EV_CTS or EV_DSR or EV_ERR or EV_RING or _
- EV_RLSD or EV_RXCHAR or EV_RXFLAG or EV_TXEMPTY
- if SetCommMask(hComm, dwFlags)=0 then
- close #iFile: return 3 'File I/O error
- end if
- PurgeComm(hComm,PURGE_RXCLEAR)
- WaitCommEvent(hComm,@dwFlags,null)
- return 0 'No Error
- end function
- var fArduino = freefile()
- var iResu = OpenCOM("COM25","9600,n,8,1",cmReadWrite,fArduino) 'sim eu sei... ta falhando a trasnferencia denovo ;p aff foi o delay la sim mas coloca 9600 denovo ou 11k vamos ver
- if iResu then
- print "Failed to open... (" & iResu & ")"
- sleep: end
- end if
- print "Port Opened: " & fArduino
- dim as string sLine 'vo tentar manualmente direto no winapi vamos ver...
- dim as integer iAmount
- screenres 640,480
- ' C ,L
- line (10,10)-(10,450), 4
- line (10,450)-(600,450), 4
- 'coluna = 590
- 'linha = 440
- 'ponto 0,0 -> 10,450
- dim as integer c, l, a, colunaA, colunaB, linhaA, linhaB, i
- dim as fb.image ptr BufferScroll
- BufferScroll = imagecreate(600-10+1,450-10)
- c = 10
- l = 450
- a = 200
- colunaA = 20
- linhaA = 230
- do
- sLine = input$(1,fArduino)
- loop until sLine[0]=asc(!"\n")
- do
- input #fArduino, sLine
- linhaB = valint(sLine)
- printf(!"%s ",sLine)
- 'linhaB = sin(i*3.141/180)*a + 230
- line (colunaA, linhaA)-(colunaA+1,LinhaB)
- linhaA = linhaB
- if ColunaA < 600 then
- colunaA = colunaA + 1
- else
- get (11+1,10)-(601+1,449),BufferScroll
- put (11,10),BufferScroll,pset
- end if
- sleep 10,1
- if multikey(fb.SC_ESCAPE) then exit do
- var sKey = inkey$
- if len(sKey) then
- dim as integer iTemp = sKey[0]
- if sKey[0]=255 then iTemp = -cint(sKey[1])
- select case iTemp
- case -asc("k"): exit do 'X button
- case 13 'enter
- var sFile = date$+"-"+time$
- for CNT as integer = 0 to len(sFile)-1
- select case sFile[CNT]
- case asc("0") to asc("9")
- 'nothing
- case else
- sFile[CNT] = asc("_")
- end select
- next CNT
- bsave sFile+"_sshot.bmp",0
- printf(!"\nsaved: %s\n",sFile+"_sshot.bmp")'
- end select
- end if
- loop
- close #fArduino
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement