prjbrook

FreeBasic serial0

Jul 1st, 2014
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. 'Test Serial Port Access, display characters in a column
  2. 'December 31, 2005
  3.  
  4. 'A PIC14000 device is connected to serial port com2 and is known to work.
  5. 'It is set up for 9600 baud, 8 data bytes, no parity, and one stop bit. The data
  6. 'is in the form of words each 8 bytes long. Each word begins with a sign and
  7. 'ends with a CR and LF, and contains a number as high as 32727.
  8. 'An expected data example would be "-00034CRLF", each expressed as a ASCII
  9. 'hex number.
  10.  
  11. 'Program stratagy. Access the serial port and extract characters as bytes.
  12. 'Each byte will be extracted to an array (sized at 20 bytes for test
  13. 'purposes)
  14.  
  15. 'Each array byte will be displayed with a print statement.
  16. 'Each array byte will be compared to the previous byte, looking for a difference
  17. 'between bytes to ensure that the print statement does not miss unprintable
  18. 'characters.
  19.  
  20.  
  21. DIM buffer(20) AS BYTE
  22.  
  23. DIM anystring AS STRING
  24.  
  25.  
  26. 'OPEN COM PORT TWO
  27. OPEN COM "COM2:9600,N,8,1" FOR BINARY AS #1
  28. 'COM2, 9600 BAUD, NO PARITY BIT, EIGHT DATA BITS, ONE STOP BIT,
  29.  
  30.  
  31. GET #1,,buffer() 'Read the port as a file, place the characters in "buffer()"
  32.  
  33.  
  34. FOR I = 1 TO 19
  35.  
  36. print buffer(I)
  37. if (buffer(I) <> buffer(I - 1)) then print " Found a difference";
  38.  
  39. NEXT
  40.  
  41. CLOSE #1
  42.  
  43. input "Enter CR to end the test. ", anystring$
  44.  
  45. END 'program now terminates
Add Comment
Please, Sign In to add comment