Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

communication using RS232.

Status
Not open for further replies.

jamankuet

Technical User
Mar 2, 2006
11
0
0
CA
Hi..

Can any one send me a piece of coding how to communicate or send data to RS232 terminal? I am trying to communicate between a PIC and PC through RS 232. I know how to communicate through PIC if a data comes to RS 232 terminal but i need to send some data to RS232 from the PC program. I am using a QBASIC 4.5.

Thanks a lot.
Jaman
 
The answer has always been 42

what type of answer this is..is it a reply or something else...sorry...i couldnt figure out..
 
thanks a lot..i will look into those...
 
On the earlier GWBasic it was a matter of opening the com port as a channel and reading from it or writing to it. Don't know if I can find any code in the archives and even if it would be helpful to the version you are using.

Ed Fair
Give the wrong symptoms, get the wrong solutions.
 
Start up qbasic, press <esc> and then press <shift>F1 to bring up the help.

Move the cursor to "Index" and press return

Press the "O" key, this takes you to the "O" section of help.

Move the cursor to "Open COM" to display the syntax of the command to open a comms port.

For example, To open a comms port at 300 baud, no parity, 8 bits, for Random access as file number 1, the syntax is:

open "com1:300,n,8" FOR RANDOM AS #1

Use the RB[n] and TB[n] options to set the size of the receive and transmit buffers.

Then consult the help on Input #filenumber, variable list to discover the syntax of how to read from the com port.

Hope that's enough to get you going.

The syntax doesn't look much different from the old gwbasic so far as I recall.

 
yes i have gone thorugh that i tried with the following code:

DIM b AS STRING * 1 '1 byte string (8 bits)

OPEN "COM1:19200,N,8,1,BIN,CD0,CS0,DS0,OP0,RS,TB2048,RB2048" FOR RANDOM AS #1
For i = 1 to 1000
b = CHR$(7)
PUT 1, , b
next i
CLOSE

the purpose of this code is to send 7 continuously to the rs232(as i have understand from help). But whenever i run the code it shiws me that "device is not connected". But i know that rs232 is connected as i can download a hex file to a PIC using rs232 and that thing works just fine. SO there should not be any problem with rs232. May be i am missing something.I am still trying to figure out but any help would be greatly apperitiated.

Thanks
Jaman
 
also eof function can be used but at first i want to just send a numeric 7(with 8 bits) to rs232.
 
chr$(37)?

Ed Fair
Give the wrong symptoms, get the wrong solutions.
 
that is the way (chr$(7)) i think to input 7 as an unsigned byte value..may be i am wrong..if so than let me know...

I have searched some documentation and found that this might be a reason..i am running in windows xp and using an old version of QBASIC(4.5). I want to synchronize it with an other program bcz this program will be tied up with a control algorithm that i have written in QBASIC 4.5. For some reason i need to synchronize a value with the PIC and thats why i need to send a data to rs232 so that PIC can peak the data whenever it will get a byte to its rs232 terminal. I am trying this thing in home now with PIC but in my lab i am using windows 98. There is a snowstrom today and will give a try to run the same thing in lab pc. In the mean time if you have something to say, just throw a message.

I am really stacked on this issue.

Thanks
Arif
 
chr$(7) is bell code if I recall. 10=lf 12=ff 13=cr
numeric is 30(0) to 39(9)
Has been a while, and the memory is going.
Try a:
for v=20 to 45:print chr$(v):next
to see what it puts out.

Ed Fair
Give the wrong symptoms, get the wrong solutions.
 
Will XP allow a dos program to access the ports..... it was difficult & slow with NT.
 
DIM b AS STRING * 1
DIM i AS LONG, le AS LONG

line input "File name? "; file$

OPEN file$ FOR INPUT AS #1 'verify file exists
CLOSE
OPEN file$ FOR BINARY AS #1
OPEN "COM1:19200,N,8,1,BIN,CD0,CS0,DS0,OP0,RS,TB2048,RB2048" FOR RANDOM AS #2
le = LOF(1)
PRINT "Transfering:"; le; "bytes at baud rate 19200 to COM1"
FOR i = 1 TO le
GET 1, , b 'read from #1, the file
PUT 2, , b 'write to #2, the COM1
NEXT i
CLOSE
PRINT "Done transfering in binary mode."
SYSTEM

this can send a entire binary file to rs232. I tried this today and think its okay although i couldnt figure out the PIC response. But may be tomorrow..Although its true that XP was a problem. Thank you guys for all your help. I will try to keep in touch.

Thanks
Arif
 
Ed 0-9 is CHR$(48) to CHR$(57) (30-39 is hex value) but since you used 10 for line feed,12 for FormFeed,etc. it is assumed you are using decimal values.


 
You're right. I was pulling the stuff from different periods of time in the memory where I was using different values. Was just attempting to get him of chr$(7) for the decimal value 7.

Ed Fair
Give the wrong symptoms, get the wrong solutions.
 
i tried to catch the byte through PIC but seems to me not working..one reason might be that QBASIC has max baud rate 9600 but in PIC and hyperterminal i am using 19200..i have to strict on this 19200 as i am also displaying the PIC data using rs232..that issue is major concern than this issue...so although it will send byte to rs232 PIC will not recover it due to unsynchronize baud rate...around 7 days work just vanished..i need to fix the PIC coding in an another way..but this option (sending data to PIC through hyperterminal) is probably the most accurate one...

Arif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top