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

Sunday, August 16, 2015

Piped output to RS232 COM port

Want output of exe file to pipe to COM 16 where Arduino is. So made a simple char out file below:



This above file gets piped into a serial out file that reads the keyboard (normally std in) and outputs char it gets.

I used the command below:


S8erialHaptic.exe waits for std in and sends chars it gets out COM 16.

Here's the file that does the receiving from a1scout and the sending to com16.

'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
if err <> 0 then
    print "Error opening COM16:"
    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 "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

nn

Saturday, July 25, 2015

Use mode in batch file to fix serial paramters


Here's my batch file:
----------------------------------------------
rem set serial port to 9600,8,n,1
mode com16 baud=9600 parity=n data=8
-------------------------------------------------


hh

Ascii table

Got it from here.



c

Friday, July 24, 2015

This site is good for redirecting to COM ports

This helped me a lot.


In above, I wrote a little exe file in FreeBasic to output a character every 5 seconds. The Arduino was on COM16 via USB-Serial. Somehow the baudrate etc was all ok.
Here's the FreeBasic program: (note most of it is commented out)
---------------------------------------------------------------------------------------
' this time redirect output via dos command
'this part just print chars to standard output
dim adresult as single
' open com "com16:9600,n,8,1,cs0,cd0,ds0,rs" as #1
if err <> 0 then
    print "Error opening COM16:"
    sleep
    end
end if
do
print 59;
print #1,59;
' rem input #1, adresult 'get result
' print adresult 'display result
' sleep 3
sleep 5000,0 'reading evering 2 seconds
loop until inkey$ = chr$(27)
sleep
----------------------------------------------------------------------------------
c