Qbasicnews.com

QBasic => QB Discussion & Programming Help => Topic started by: A.Sadjadian on July 11, 2004, 05:13:23 AM



Title: data exchange via rs232
Post by: A.Sadjadian 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


Title: data exchange via rs232
Post by: Plasma 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


Title: Re: data exchange via rs232
Post by: TheBigBasicQ 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 :???:


Title: data exchange via rs232
Post by: A.Sadjadian 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


Title: data exchange via rs232
Post by: A.Sadjadian 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


Title: data exchange via rs232
Post by: A.Sadjadian 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??


Title: data exchange via rs232
Post by: TheBigBasicQ 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?


Title: data exchange via rs232
Post by: A.Sadjadian 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?


Title: data exchange via rs232
Post by: Plasma 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


Title: data exchange via rs232
Post by: TheBigBasicQ 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.


Title: data exchange via rs232
Post by: Plasma on July 14, 2004, 10:14:57 PM
BBQ: This site is called QBasicNews, you know...  :roll:


Title: data exchange via rs232
Post by: A.Sadjadian 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.


Title: data exchange via rs232
Post by: A.Sadjadian 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


Title: data exchange via rs232
Post by: A.Sadjadian 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?


Title: data exchange via rs232
Post by: TheBigBasicQ 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?


Title: data exchange via rs232
Post by: Plasma on July 15, 2004, 07:23:53 PM
Yeah, my bad...it should be BaudDiv instead of BaudNum. I don't have a null modem cable right now so I can't test it out, try switching the open and the ComSpeed:

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

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

' 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, BaudDiv MOD &HFF  ' Lo Byte of Baud Rate
  OUT BaseAddr + 1, BaudDiv \ &H100   ' Hi Byte of Baud Rate
  OUT BaseAddr + 3, OldLSR            ' Disable Divisor Latch

END SUB


@BBQ: How do you know what his "needs" are? Maybe he needs to use QB?


Title: data exchange via rs232
Post by: TheBigBasicQ on July 17, 2004, 12:26:51 PM
Hey I was just suggesting :D


Title: data exchange via rs232
Post by: A.Sadjadian on August 02, 2004, 09:08:03 AM
THANKS ALL FOR THE REPLIES
the communication via RS232 is working OK (up to 57600 bps NOT at 115200)

But Alas, the Wireless RS232 Cable I purchased proved faulty. It will give me some 3 metres range (instead of at least 50)Manufacturere is supposed to send me a new pair soon.

AND  I have managed to land myself in another qb problem, large program to be modolarised. I am asking for help under a new topic.