Qbasicnews.com
July 08, 2020, 08:05:13 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: data exchange via rs232  (Read 7894 times)
A.Sadjadian
New Member

Posts: 18


« on: July 11, 2004, 05:13:23 AM »

help needed to exchange data between 2 computers running DOS and programs in Qbasic. using the rs232 cable( in this case really a Wireless RS232 Cable). one computer is running an inustrial control program and one is the user interface program.( the control computer is installed on a rotating platform )

A.Sadjadian
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #1 on: July 11, 2004, 05:56:00 AM »

Is the serial cable a null modem (crossover) cable, or is it a straight-through cable? If it's straight-through, you'll need to get a null modem adapter to make it work.

Once you have a null modem cable, you can use OPEN with "com1:" or "com2:" to communicate between computers. Here's a simple example: http://www.basicguru.com/files/abc/abc9803/chat.bas
Logged
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #2 on: July 12, 2004, 03:16:57 AM »

Quote from: "A.Sadjadian"
Wireless RS232 Cable


What do you mean by wireless cable? Its a contradictory statement :Huh:
Logged
A.Sadjadian
New Member

Posts: 18


« Reply #3 on: July 14, 2004, 03:08:40 AM »

Dear Plasma
 Thank you very much. I would start trying your program right now.

AND. I think my cable is what you call nul . Anyway it has 3 wires pin 2 to pin 3 on the other computer, pin 3 to pin 2 (crossover) and pin 5 to pin 5.

Meanwhile I succeded in sending from one computer to the other and receving ok. However I can not do the reverse i.e. when I run the sending program on one the other can receive but when I exchange the program between the 2 system does not work. Always new problems for Newbie.

Best Regards
A.Sadjadian
Logged
A.Sadjadian
New Member

Posts: 18


« Reply #4 on: July 14, 2004, 03:14:06 AM »

Dear Linux Lover
Salaam

It does seem a contradiction. I searched internet for a wireless RS232 and found this ( I have ordere on yesterday from UK). I suppose the name is to imply that the wireless connection is totally tarnsparent to the user you connect the 2 wireless terminal (small boxes) to the serial DB9 connectors of the 2 computers and they act as if an RS232 cable exist between them, no s/w to install and no drivers to use. Note that I am using DOS for industrial controls systems as I have found it less buggy than windows in some 17 years of use.

A.Sadjadian
Logged
A.Sadjadian
New Member

Posts: 18


« Reply #5 on: July 14, 2004, 04:16:50 AM »

Dear Plasm
Salaam
I had to ad  cd0,cs0,ds0 to your program open com string befor it worked with my cable BUT the problem is still there, it works one way only from computer A  to b but not from computer B to A. Any recommendations??
Logged
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #6 on: July 14, 2004, 04:44:41 AM »

are the two machines identically setup? I mean if you're using any kind of DOS emulation on a windows PC then that will hamper our efforts to track down your problem.

Are you running in pure DOS mode?
Logged
A.Sadjadian
New Member

Posts: 18


« Reply #7 on: July 14, 2004, 09:10:10 AM »

Thanks for the help in the forum
Data exchange is ok now. Trouble was due to faulty connection inside one of the computers. Sorry to bother you.
AND NOW  the natural next in line, is 9600 bps the top speed possible with qbasic? Anyway to go up to the top of the com port range of 115000 bps?
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #8 on: July 14, 2004, 10:28:23 AM »

9600 is the top speed "natively supported". Of course there is a way past this:

Code:
DEFINT A-Z
DECLARE SUB ComSpeed (Port, Baud&)

' Set the speed and open the port
ComSpeed 2, 115200
OPEN "COM2: ,N,8,1" FOR RANDOM AS #1

' Now send your data however you normally would, for example:
Rqst.Pkt$ = "440900000000d35e"
PRINT #1, Rqst.Pkt$
SLEEP 1
LINE INPUT #1, Resp.Pkt$

' Close the port when you're done
CLOSE #1

SUB ComSpeed (Port, Baud&)

  ' Based on BaudLatch() sub by Donn Bly
  '
  '  Port = COM Port (1, 2, 3, or 4)
  ' Baud& = Baud setting (9600, 14400, 19200, 38400, 57600, 115200, etc.)

  BaudDiv = 115200 / Baud&
  IF BaudDiv = 0 THEN BaudDiv = 1
  SELECT CASE Port
    CASE 4
      BaseAddr = &H2E8  ' com4
    CASE 3
      BaseAddr = &H3E8  ' com3
    CASE 2
      BaseAddr = &H2F8  ' com2
    CASE ELSE
      BaseAddr = &H3F8  ' com1
  END SELECT

  OldLSR = INP(BaseAddr + 3)
  OUT BaseAddr + 3, OldLSR OR &H80    ' Enable the Divisor Latch
  OUT BaseAddr + 0, BaudNum MOD &HFF  ' Lo Byte of Baud Rate
  OUT BaseAddr + 1, BaudNum \ &H100   ' Hi Byte of baud Rate
  OUT BaseAddr + 3, OldLSR            ' Disable Divisor Latch

END SUB
Logged
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #9 on: July 14, 2004, 03:53:20 PM »

AS: This question is a bit off topic but why dont you use C/C++? It's better/faster at this stuff than QB.
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #10 on: July 14, 2004, 10:14:57 PM »

BBQ: This site is called QBasicNews, you know...  :roll:
Logged
A.Sadjadian
New Member

Posts: 18


« Reply #11 on: July 15, 2004, 03:01:01 AM »

Dear Plasma
Salaam
Thanks a lot for the big help. I will presently try the code you have sent and try to somehow measure the improvement in the program. In my control systems communication is secondary to the actual control proccess and so I want it to take as short a time as possible.
Logged
A.Sadjadian
New Member

Posts: 18


« Reply #12 on: July 15, 2004, 03:14:16 AM »

Dear BBQ

 Quite a long story. In short though.
1- QB is extremely easier to debug which is very important in custom SW meant to use only by one user.
2- Usually the speed is not critical with modern hi MHz motherboards. However less time for comunication means more time to CONTROL
3- AND I am not really a PROGRAMMER (after all I am asking as a newbie). I program my control system because it needs intimate familiarity with the control system design and programmers (at least here)  do not seem to like accepting the responsibility of multi thausand dollar loss of productivity  a bug can cause and the very limited field testing possibilities (at least not for the kind of money I can offer)
4- My system are almost all one of a kind. No repeats

Would gladly supply more details if you care to email me off list
Logged
A.Sadjadian
New Member

Posts: 18


« Reply #13 on: July 15, 2004, 12:16:05 PM »

Dear Plasma
I have now tried your code but it does not work.
There is a BaudDiv which is not used anywhere and a couple of
BaudNum that is not defined so is ZERO.
If I replace BaudNum s with BaudDiv then it does work but much slower than 9600 baud, may be at 1200 bps rate.
Any sujjestions?
Logged
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #14 on: July 15, 2004, 12:31:37 PM »

@Plasma: Even though this is a qb board, it's our duty to inform newbies about using correct s/w for their needs.

@AS: Did you try other modes like 14400, 19200, 38400, 57600?
Logged
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!