View difference between Paste ID: edTQ1AHb and D48C1Nyu
SHOW: | | - or go back to the newest paste.
1
Try compiling the program with the -e switch to enable error checking. This way you can make sure that the OPEN COM statement is working. If error checking is off and the OPEN COM statement fails, the program will still run to completion and buffer() will be all zeroes. (i.e. no diffs between chars) 
2
3
Also, Get #1,,buffer() will wait for input. Does the program hang, or does it just quit? If it is hanging up then the OPEN COM statement is working but GET is not seeing any data from the device. 
4
5
You may want to check out the LOC() function to determine when there is data in the com buffer to be read. 
6
7
Also verify the connection between your PC and device. You may need to set flow control options in the OPEN COM string. See CS,DS,RS, etc under the OPEN COM topic in the wiki. 
8
9
I tried your program with a modem and after sending the "AT" command received data back in buffer(). (And it printed the diffs)
10
coderJeff
11
Site Admin
12
 
13
Posts: 2286
14
Joined: Nov 04, 2005 14:23
15
Location: Ontario, Canada
16
Has thanked: 1 time
17
Been thanked: 1 time
18
19
20
'Test Serial Port Access, display characters in a column
21
'December 31, 2005
22
23
'A PIC14000 device is connected to serial port com2 and is known to work.
24
'It is set up for 9600 baud, 8 data bytes, no parity, and one stop bit. The data
25
'is in the form of words each 8 bytes long.  Each word begins with a sign and
26
'ends with a CR and LF, and contains a number as high as 32727.
27
'An  expected data example would be "-00034CRLF", each expressed as a ASCII
28
'hex number.
29
30
'Program stratagy.  Access the serial port and extract characters as bytes.
31
'Each byte will be extracted to an array (sized at 20 bytes for test
32
'purposes)
33
34
'Each array byte will be displayed with a print statement.
35
'Each array byte will be compared to the previous byte, looking for a difference
36
'between bytes to ensure that the print statement does not miss unprintable
37
'characters.
38
39
40
DIM buffer(20) AS BYTE
41
42
DIM anystring AS STRING
43
44
45
'OPEN COM PORT TWO
46
OPEN COM "COM2:9600,N,8,1" FOR BINARY AS #1
47
'COM2, 9600 BAUD, NO PARITY BIT, EIGHT DATA BITS, ONE STOP BIT,
48
49
50
GET #1,,buffer()    'Read the port as a file, place the characters in "buffer()"
51
52
53
FOR I = 1 TO 19
54
55
    print buffer(I)
56
    if (buffer(I) <> buffer(I - 1)) then print " Found a difference";
57
   
58
NEXT
59
60
CLOSE #1
61
62
input "Enter CR to end the test. ", anystring$
63
64
END                   'program now terminates