View Full Version : One character at a time!
ziloo
October 21st, 2006, 01:52 AM
Alright programming gurus!
I want to send a character from one PC to another via serial port.
What I need is a program in Quickbasic, that will take care of
sending and receiving one single character at a time. The same
software is sitting on both computers :sigh:.
Luke
October 21st, 2006, 01:59 AM
You want to chat or send files?
For sending files you will better use procomm or laplink.
But here are two chatting programs, not written by me, but working good.
http://www.republika.pl/grzesiek21/szereg_oprogramowanie.htm#inne
Site is in Polish, but you shouldn't have any probles with recognising listings, there are two, second use I/O functions built-in QBASIC, so it won't propably run on BasicA or GW-Basic.
mbbrutman
October 21st, 2006, 06:02 AM
Did you try searching on the web first? Serial communications from BASIC is all over.
ziloo
October 21st, 2006, 06:25 AM
Whenever one is looking for a needle in a haystack, it is always better to ask
those who have alread been in the barn! ... yee haw ... :biggrin:
mbbrutman
October 21st, 2006, 06:42 AM
Good point but are you looking for a program that is already done, or programming examples? And what are you going to do with it? Might help narrow down the corner of the barn to look in.
For programming examples I'd say just go look at some - what you like is a matter of personal preference.
IBMMuseum
October 21st, 2006, 09:30 AM
Alright programming gurus!
I want to send a character from one PC to another via serial port. What I need is a program in Quickbasic, that will take care of sending and receiving one single character at a time. The same software is sitting on both computers.
There is an example of "Slow Baud Rate for Debugging" in the "Undocumented PC" book. It is in Assembler, but QB can do the same things (hint: you want to set the serial port divisor to give a lower rate of transmission). For vintage systems you could maybe still have a newer UART with FIFO come into play (which could suppress showing the bytes received until the FIFO threshold was reached (in this case it would be best for your program to just disable the FIFOs, if present).
I'll provide some code details momentarily...
Mike Chambers
October 21st, 2006, 09:59 AM
Alright programming gurus!
I want to send a character from one PC to another via serial port.
What I need is a program in Quickbasic, that will take care of
sending and receiving one single character at a time. The same
software is sitting on both computers :sigh:.
::ears perk::
did you say quickbasic? :D
i reckon i know a bit about that language... there are two real ways to access COM ports in QB. one of which is much easier, so we'll go with that one.
i'll assume you know how to open files for access already. let me know if i'm mistaken here.
you'll want to open a COM port with this command (QB is limited to COM1 and COM2 with this method i believe)
OPEN "COM1:9600,N,8,1" FOR RANDOM AS #1
obviously, you can change 9600,N,8,1 to whatever you want for port settings.
when you want to read a byte do this:
tmpbyte$ = SPACE$(1)
GET #1, , tmpbyte$
when you want to write data, do this:
tmpdataout$ = "omg i am so leet"
PUT #1, , tmpdataout$
you should get the picture. it's fairly easy. there can be a small lag (1 second or so) during GET if there is no waiting data to grab, which is why i don't like using this method but for a chat program or whatever it's not really a problem.
remember to close the open port handle when you're finished like this:
CLOSE #1
you dont NEED to use #1 as the handle. you can do other numbers. just remember which you use for the PUT and GET commands. to have QB determine the first free file handle, use this command:
ff = FREEFILE
now the variable ff holds the handle value, and you can replace all "#1" with "ff"
in addition to chatting character by character, you can manage file transfers this way :)
EDIT: if you're having problems trying this, i have no problem loading up QB and actually writing you a sample program for it.
IBMMuseum
October 21st, 2006, 10:07 AM
There is an example of "Slow Baud Rate for Debugging" in the "Undocumented PC" book. It is in Assembler, but QB can do the same things (hint: you want to set the serial port divisor to give a lower rate of transmission).
One question is that whether QuickBASIC would override your baud rate setting when you OPEN the port, and also prevent you from changing the settings while it is open. The UART in a serial port do happen to deal with "one character at a time", but what time interval will you need? The example has two bits per second (E100h divisor), but shows other divisor rates for things like five bytes per second (divisor of 900h) & up.
For the non-custom programming of the UART, it looks like the DOS interrupt call (INT 14h, Function 0 "Initialize Serial Port") can set the port as low as 110 baud (which is about 11 characters per second). QuickBASIC looks to be more flexible, as my manual (4.5, although older & newer should be similiar here) says you can set the baud rate to what you want. So I guess I come to the position of the other responses to ask what you have tried so far & why it isn't working for you.
ziloo
October 21st, 2006, 10:08 AM
Thanks a million to all of you champs! Great stuff!
I am going to read up some material (has been a while) and try a few things, and
will get back to you when I get something.
Mike Chambers
October 21st, 2006, 10:14 AM
it looks like the DOS interrupt call (INT 14h, Function 0 "Initialize Serial Port") can set the port as low as 110 baud (which is about 11 characters per second).
wow.. 110 baud. pfft, screw this cable modem. i'm gonna run a null modem cable to my ISP! it would take well over a second just to transfer a header from a TCP packet lol.
Mike Chambers
October 21st, 2006, 10:16 AM
Thanks a million to all of you champs! Great stuff!
I am going to read up some material (has been a while) and try a few things, and
will get back to you when I get something.
so what exactly is the program for... i'm assuming you're making a chat proggie?
ziloo
October 21st, 2006, 11:46 AM
so what exactly is the program for... i'm assuming you're making a chat proggie?
It is a long term project for connecting a PC to a data acquisition system (DAS).
So, I am trying and testing few ideas about serial communication. Later on,
it would be fun to connect several such DAS to a PC in a sort of network
arrangement. But I have a lot of learning to do...
Mike Chambers
October 21st, 2006, 12:43 PM
It is a long term project for connecting a PC to a data acquisition system (DAS).
So, I am trying and testing few ideas about serial communication. Later on,
it would be fun to connect several such DAS to a PC in a sort of network
arrangement. But I have a lot of learning to do...
thats pretty cool. what kind of PC you going to be running it on? something vintage i guess? 286? XT?
if its all going to be qb, and you need some help i'll be more than glad to help if you need it.
IBMMuseum
October 21st, 2006, 12:44 PM
...So, I am trying and testing few ideas about serial communication. Later on, it would be fun to connect several such DAS to a PC in a sort of network arrangement. But I have a lot of learning to do...
I highly recommend Jan Axelson's (but I promise I am not a shill for her) "Serial Port Complete" (ISBN 0-9650819-2-3) "Programming and Circuits for RS-232 and RS-485 Links and Networks". Although the code samples are for (Windows-based versions of) Visual Basic they could be ported to QuickBASIC. You can get it from places like Jameco or directly from the author (links from http://www.lvr.com/serport.htm).
Chris2005
October 23rd, 2006, 04:20 PM
perhaps it's just an anamoly, but the first edition of this book:
http://www.amazon.com/Programmers-Guide-Serial-Communication-2nd/dp/0672302861/sr=8-1/qid=1161649111/ref=sr_1_1/102-5380435-9485767?ie=UTF8&s=books
is sitting on the shelf at a nearby library. Haven't read it...
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.