Saturday, September 5, 2015

Better piping. Output ascii to serial handler.

Want to collect data and output it via RS232.
Thought of [Collect and send] _--> Com2

Better, I think [Collect] --> [Sending app] --> Com2

So with Collect being (trivial) generator asc1out.bas and the Sending app being s8serialhaptic.bas (the one from ProgsSept15), got good results from serial Bray Term on HP Vectra.
Here's code for asc1out.bas

'Ascout sends string of chars to serialHaptic  by piping
here:
print "A123";
sleep 1000,0
print "Q246";
sleep 1000,0
goto here


and here's Sender file:

'Now going to get input from keybd that outputs on serial . Worked.
'Worked, in that it sent A and got back a char from arduino A0SCREAD. Now going to cut out all the 'commented rubbish.
Dim As Integer ms 'millisecs
ms = 200
Dim As String sadresult 
'open com "com16:9600,n,8,1,cs0,cd0,ds0,rs" as #1
open com "com2:9600,n,8,1,cs0,cd0,ds0,rs" as #1
if err <> 0 then
    print "Error opening COM2:"
    sleep
    end
end if
'sadresult = Input$ (1,#1) 'clear out crap in in buff
do
print ">";
'print #1, "A";
sadresult = Input$ (1)
print #1, sadresult;
'print #1, "B123"
'print "a";
print sadresult 'display result
'sleep ms,0 'reading evering 3 seconds

'print "B"; 
'sleep ms,0 'reading evering 2 seconds
'print"C";
'sleep ms,0 'reading evering 2 seconds



loop until inkey$ = chr$(27)
close
sleep

Next step, tidy up files get info to go both ways.
Big third step: replace usb/serial cable with Bluetooth both ends.


Tethered output going

Got serial cable via usb-serial on Dell and fed by null-modem cable to HP Vectra.  Using Bray terminal both were sending and receiving OK but when I cam to write a simple com program in FreeBasic it froze and reboots were required. Turns out the first "Open COMn" line is very important. see two versions below. One caused lock up. Maybe due to time outs. Here's the version that worked:

'serout2.bas
Dim b as byte
'didn't work --> Open COM "COM2: 9600,N,8,1,BIN,DS0"  As #1
 open com "com2:9600,n,8,1,cs0,cd0,ds0,rs" as #1 
do
PRINT #1,"A"
   
Print ". ";
sleep 500
loop until inkey$ = chr$(27)
close
'Sleep
End