Advertisement
Mysoft

Untitled

Jan 11th, 2016
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "windows.bi"
  2. #include "vbcompat.bi"
  3. #include "crt.bi"
  4. #include "fbgfx.bi"
  5.  
  6. enum ComModes 'COM Port Read/Write Mode
  7.   cmRead = 1
  8.   cmWrite = 2
  9.   cmReadWrite = 3
  10. end enum
  11.  
  12. function OpenCOM(sPORT as string="COM1:",sConfig as string="",iMode as integer=3,iFile as integer) as integer    
  13.  
  14.   dim as DCB SerialConfig = type(sizeof(DCB))
  15.   dim as string sPortB = !"\\\\.\\"+sPORT  
  16.   if len(sConfig) then
  17.     if BuildCommDCB(sConfig,@SerialConfig)=0 then return 1 'Illegal Function Call
  18.   end if
  19.  
  20.   dim as integer iResu,iModeWin
  21.   select case (iMode and 3)
  22.   case 0: return 1 'Illegal Function Call
  23.   case 1
  24.     iModeWin = GENERIC_READ
  25.     iResu = open("NUL" for binary access read as #iFile)
  26.   case 2
  27.     iModeWin = GENERIC_WRITE
  28.     iResu = open("NUL" for binary access write as #iFile)
  29.   case 3
  30.     iModeWin = GENERIC_READ or GENERIC_WRITE
  31.     iResu = open("NUL" for binary as #iFile)
  32.   end select
  33.   if iResu then return iResu
  34.   var pTemp = cast(FILE ptr,fileattr(iFile,2))
  35.   if pTemp = 0 then close #iFile: return -1
  36.   setvbuf(pTemp,null,_IONBF,0)
  37.   var hComm = CreateFile(sPortB,iModeWin,null,null,OPEN_EXISTING,null,null)
  38.   if hComm = INVALID_HANDLE_VALUE then close #iFile: return 2 'File Not Found  
  39.   if len(sConfig) andalso SetCommState(hComm,@SerialConfig) = 0 then
  40.     close #iFile: return 3 'File I/O error '
  41.   end if
  42.   fflush(pTemp): _close(pTemp->_file)
  43.   pTemp->_file = _open_osfhandle(cast(long,hComm),null)  
  44.   var dwFlags = EV_BREAK or EV_CTS or EV_DSR or EV_ERR or EV_RING or _
  45.   EV_RLSD or EV_RXCHAR or EV_RXFLAG or EV_TXEMPTY
  46.   if SetCommMask(hComm, dwFlags)=0 then
  47.     close #iFile: return 3 'File I/O error
  48.   end if
  49.   PurgeComm(hComm,PURGE_RXCLEAR)
  50.   WaitCommEvent(hComm,@dwFlags,null)
  51.   return 0 'No Error
  52.  
  53. end function
  54.  
  55. var fArduino = freefile()
  56. 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
  57. if iResu then
  58.   print "Failed to open... (" & iResu & ")"
  59.   sleep: end
  60. end if
  61.  
  62. print "Port Opened: " & fArduino
  63. dim as string sLine 'vo tentar manualmente direto no winapi vamos ver...
  64. dim as integer iAmount
  65.  
  66. screenres 640,480
  67. '     C ,L
  68. line (10,10)-(10,450), 4
  69. line (10,450)-(600,450), 4
  70. 'coluna = 590
  71. 'linha = 440
  72. 'ponto 0,0 -> 10,450
  73. dim as integer c, l, a, colunaA, colunaB, linhaA, linhaB, i
  74. dim as fb.image ptr BufferScroll
  75.  
  76. BufferScroll = imagecreate(600-10+1,450-10)
  77.  
  78. c = 10
  79. l = 450
  80. a = 200
  81. colunaA = 20
  82. linhaA = 230
  83.  
  84. do
  85.     sLine = input$(1,fArduino)
  86. loop until sLine[0]=asc(!"\n")
  87. do  
  88.     input #fArduino, sLine
  89.     linhaB = valint(sLine)
  90.     printf(!"%s ",sLine)
  91.     'linhaB = sin(i*3.141/180)*a + 230
  92.     line (colunaA, linhaA)-(colunaA+1,LinhaB)
  93.     linhaA = linhaB
  94.     if ColunaA < 600 then
  95.       colunaA = colunaA + 1
  96.     else
  97.       get (11+1,10)-(601+1,449),BufferScroll
  98.       put (11,10),BufferScroll,pset
  99.     end if
  100.      
  101.     sleep 10,1
  102.     if multikey(fb.SC_ESCAPE) then exit do
  103.     var sKey = inkey$
  104.     if len(sKey) then
  105.         dim as integer iTemp = sKey[0]
  106.         if sKey[0]=255 then iTemp = -cint(sKey[1])
  107.         select case iTemp
  108.         case -asc("k"): exit do 'X button
  109.         case 13 'enter
  110.             var sFile = date$+"-"+time$
  111.             for CNT as integer = 0 to len(sFile)-1
  112.                 select case sFile[CNT]
  113.                 case asc("0") to asc("9")
  114.                     'nothing
  115.                 case else
  116.                     sFile[CNT] = asc("_")
  117.                 end select
  118.             next CNT
  119.             bsave sFile+"_sshot.bmp",0
  120.             printf(!"\nsaved: %s\n",sFile+"_sshot.bmp")'
  121.         end select        
  122.     end if
  123. loop
  124.  
  125. close #fArduino
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement