FreeBasic and Arduino communication

For issues with communication ports, protocols, etc.
BasicCoder2
Posts: 2894
Joined: Jan 01, 2009 7:03
Location: Australia

Re: FreeBasic and Arduino communication

Postby BasicCoder2 » Feb 24, 2016 4:19

Came across this which gave an Arduino example I needed to use with MrSwiss's terminal program.

http://forums.trossenrobotics.com/tutor ... rial-3300/

Now I work need to work through MrSwiss's terminal program to get it clear in my mind what is happening on the FreeBASIC side of the communication and how to write my own stuff. I haven't used the COM OPEN thingy before. It appears to be like writing/reading a file.

Running MrSwiss's terminal program and the Arduino code below I could type in a number (I assume a string) and it was returned as expected.


Code: Select all

int serialData = 0;

void setup()
{
  Serial.begin(9600);  'start serial connection at 9600 baud rate
}

void loop()
{
  if (Serial.available() > 0)    'check if serial port available
  {
    serialData = Serial.read();  'read any data
    Serial.println(serialData);  'send it back to sender
  } 
}
caseih
Posts: 1040
Joined: Feb 26, 2007 5:32

Re: FreeBasic and Arduino communication

Postby caseih » Feb 24, 2016 5:51

Oh good. Yes was the kind of thing I had in mind. Yes serial is just like normal input and output, nearly at least. Basic has always been good at that sort of thing.
D.J.Peters
Posts: 7169
Joined: May 28, 2005 3:28
Location: Germany

Re: FreeBasic and Arduino communication

Postby D.J.Peters » Feb 24, 2016 10:16

@BasicCoder2 you don't have to reinvent the wheel again I wrote it 10 years ago.
Event driven RS232 class (windows)

Joshy
BasicCoder2
Posts: 2894
Joined: Jan 01, 2009 7:03
Location: Australia

Re: FreeBasic and Arduino communication

Postby BasicCoder2 » Feb 24, 2016 20:05

@Joshy,

Thanks. Over the next few weeks I hope to get my head around this FreeBasic and Arduino serial port communication well enough to use it with the Arduino. I have never really looked at it before as up to now I was happy using the k8055 to connect the pc to motors and sensors. For some Arduino projects wireless connections to a FreeBASIC program might also be useful. Of course I should just learn Python and be done with it but I just didn't warm to that language after a few attempts at learning it.
.
MrSwiss
Posts: 2024
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: FreeBasic and Arduino communication

Postby MrSwiss » Feb 24, 2016 22:51

BasicCoder2 wrote:... type in a number (I assume a string) ...

You are assuming wrong, it gets sent Byte by Byte.
REASON: my Ardino-Sketch is using a Short (16bit Integer) to store incoming stuff.
A String would 'blow' that ...

In order for you to check FB-Terminal's Code in an easier Way:
    I've simplified it to be Windows only (a lot less Code)
    better contrast (the Eyes are not any longer, what they used to be)
    no more conditional compiling Directives etc. etc. see comments
FB-Terminal.bas:

Code: Select all

' FB-Terminal.bas
' FB-Terminal.exe - Windows only
' original code by: dasyar, FreeBASIC-Forum
'
' =================================================
' MrSwiss changes: 2016-02-18 / 24
' - renamed from FBterm.bas to FB-Terminal.bas
' - Windows only (deleted all Linux related stuff)
' - NO more conditional compiling directives
' - reformated code for "readability"
' - rewritten Printing Routine ( colrPrtPos() )
' - changed colors for more contrast
' - changed Button Positions (better distribution)
' - converted If Then Else EndIf to single Line IF
'   (where it makes sense)
' - added comments (where needed)
' - replaced Integer(s) with Long(s), for FBC x64
' - deleted all unneccessary "$" on keywords
' =================================================

Screen   12
Width   80, 30
Locate   ,, 1

' Globals
Dim Shared As Double   t
Dim Shared As Long      column, row, pos1, pos2, row1, column1
Dim Shared As String   Key, buffer, numtosend
Dim Shared As UByte      numtosend2
' Locals
Dim As Long      b=4, p=2, e=1   ' prefered startup: "9600", "COM3:", "On"
Dim As Boolean   flag         ' typical use of Boolean(s)
Dim As String   baud(0 To 7) = {"1200","2400","4800","9600","19200","38400","57600","115200"}
Dim As String   port(0 To 9) = {"COM1:","COM2:","COM3:","COM4:","COM5:","COM6:","COM7:","COM8:","COM9:","COM10:"}
Dim As String   echo(0 To 1) = {"Off"," On"}
Dim As String   Escape = Chr(27)
Dim As Long      res, x, y, buttons

''''''''' Headers for Functions and Subroutines '''''''''''
Declare Sub InfoBar   ()
Declare Sub InfoBar2()
Declare Sub ColrPrtPos(   ByVal row As Long, ByVal col As Long, ByVal Stg As String, _
                  ByVal CFG As ULong=&hFF000000, ByVal CBG As ULong=&hFFFFFFFF )
Declare Sub TextCursor(   ByRef flag As Boolean )   ' hand flag over, instead of 'Shared' declaration
Declare Sub sendnum   ()

''''''''' Start of Program ''''''''''''
Cls
begin:
InfoBar()

ColrPrtPos(2,24,port(p),15,9)
ColrPrtPos(2,41,baud(b),15,9)
''''''''' Main Screen '''''''''''''''''
Do
   res = GetMouse (x, y, , buttons)
   Key = InKey
   If Key = Escape Then Exit Do
   ''''''''''' Mouse over Quit '''''''''''
   If x > 1 And x <= 32 And y > 16 And y < 31 And buttons And 1 Then GoTo Cend
   '''''''''' Mouse over Connect '''''''''
   If x > 49 And x <= 112 And y > 16 And y < 31 And buttons And 1 Then
      Sleep 200,1
      Exit Do
   End If
   '''''''''' Mouse over port ''''''''''''
   If x > 144 And x <= 176 And y > 16 And y < 31 And buttons And 1 Then
      p += 1
      If p = 10 Then p = 0
      ColrPrtPos(2,24,space(10),,9)
      ColrPrtPos(2,24,port(p),15,9)
      Sleep 200,1
   End If
   '''''''''' Mouse over baud ''''''''''''
   If x > 280 And x <= 312 And y > 16 And y < 31 And buttons And 1 Then
      b += 1
      If b = 8 Then b = 0
      ColrPrtPos(2,41,space(8),,9)
      ColrPrtPos(2,41,baud(b),15,9)
      Sleep 200,1
   End If
Loop
''''''''' End of Main Screen ''''''''''

''''''''' Live Terminal '''''''''''''''
InfoBar2()
View Print 1 To HiWord(Width)
ColrPrtPos(2,54,echo(e),15,9)
View Print 3 To HiWord(Width)
Color 7, 0 : cls

Open Com port(p) & baud(b) & ",n,8,1,cs0,ds0,cd0,rs" as #1
'' Open Com "COM1:115200,n,8,1,cs0,ds0,cd0,rs" As #1
If Err <> 0 Then
   ColrPrtPos(3,1,"Error opening " & port(p),14,0)
   Sleep 2000,1 : Cls : GoTo begin
End If


Do

   res = GetMouse (x, y, , buttons)
   Key = InKey
   TextCursor(flag)
   '''''''''' Mouse over Disconnect '''''''''
   If x > 49 And x <= 128 And y > 16 And y < 31 And buttons And 1 Then
      Close #1 : Color 7, 0 : Cls
      Sleep 200,1 : GoTo begin
   End If
   ''''''''' Mouse over echo '''''''''''''
   If x > 384 And x <= 416 And y > 16 And y < 31 And buttons And 1 Then
      e += 1 : If e > 1 Then e = 0
      View Print 1 To HiWord(Width)
      ColrPrtPos(2,54,space(4),,9)
      ColrPrtPos(2,54,echo(e),15,9)
      View Print 3 To HiWord(Width)
      Color 7,0 : Cls : Sleep 200,1
   End If
   ''''''''' Mouse over Send Number ''''''
   If x > 500 And x <= 582 And y > 16 And y < 31 And buttons And 1 Then sendnum()
   ''''''''' Mouse over Cls ''''''''''''''
   If x > 600 And x <= 624 And y > 16 And y < 31 And buttons And 1 Then
      View Print 3 To HiWord(Width)
      Color 7, 0 : Cls : Sleep 200,1
   End If
   '''''''''' Terminal Screen ''''''''''''
   Color 7, 0
   If Key <> "" Then
      If Key = Chr(13) Then   ' Check for CR
         Print #1, Chr(13);   ' Send CR
      Else
         Print #1,Key;
         If echo(e) <> "Off" Then Print Key + " ";   ' add a space after command
      End If
   End If

   While LOC(1) > 0
      buffer = Input(LOC(1),#1)
      Print buffer;
   Wend

   Sleep 1
Loop
''''''''' End of Live Terminal ''''''''
Cend:
Close
End
''''''''' End of Program ''''''''''''''

''''''''' Functions and Subroutines '''
Sub InfoBar()
   Cls
   Locate 1,1
   View Print 1 To HiWord(Width)
   ColrPrtPos(2, 1,Space(80),15,9)
   ColrPrtPos(1, 1,Space(80),15,9)
   ColrPrtPos(1,36,"FB-Terminal",15,9)
   ColrPrtPos(2, 1,"Quit",15,4)
   ColrPrtPos(2, 7,"Connect",15,4)
   ColrPrtPos(2,19,"Port",15,4)
   ColrPrtPos(2,36,"Baud",15,4)
   Color 7, 0
End Sub

Sub InfoBar2()
   View Print 1 To HiWord(Width)
   ColrPrtPos(2, 1,Space(80),15,9)
   ColrPrtPos(2, 7,"Disconnect",15,4)
   ColrPrtPos(2,49,"Echo",15,4)
   ColrPrtPos(2,54,"Off",15,9)
   ColrPrtPos(2,63,"Send Number",15,4)
   ColrPrtPos(2,76,"Cls",15,4)
   View Print 3 To HiWord(Width)
   Color 7, 0
End Sub

Sub ColrPrtPos(   ByVal row As Long, _
            ByVal col As Long, _
            ByVal Stg As String, _
            ByVal CFG As ULong = &hFF000000, _
            ByVal CBG As ULong = &hFFFFFFFF )
   If CFG <> &hFF000000 OrElse CBG <> &hFFFFFFFF Then Color(CFG, CBG)
   Locate row, col : Print Stg;   ' NO LF invoked!
End Sub

Sub TextCursor(ByRef flag As Boolean)   ' recoded MrSwiss
   column = Pos
   row = CsrLin
   If Timer - t > .5 Then
      flag = Not(flag)
      If flag Then Print "_" Else Print " ";
      Locate row,column
      t = Timer
   End If
End Sub

Sub sendnum()
   Input "Enter a number to send (0 - 255) space delimited";numtosend
   pos1 = InStr(numtosend, " ")
   If pos1 = 0 And Len(numtosend) > 0 Then
      Print #1, Chr(Val(numtosend));
      Print Chr(Val(numtosend));
   Else
      numtosend2 = Val(Left(numtosend,pos1))
      Print #1, Chr(numtosend2);
      Print Chr(numtosend2);
      Do While pos1 > 0
         pos2 = pos1
         pos1 = InStr(pos1+1, numtosend, " ")
         numtosend2 = Val(Mid(numtosend,pos2+1,pos1-pos2))
         Print #1, Chr(numtosend2);
         Print Chr(numtosend2);
      Loop
   End If
   ''''''''' Get rid of garbage char '''''
   row1 = CsrLin ' Get row position
   column1 = Pos ' Get column position
   Locate row1,(column1-1)
   Print " " ' Get rid of garbage char
   Locate row1,(column1-1)
End Sub
BasicCoder2
Posts: 2894
Joined: Jan 01, 2009 7:03
Location: Australia

Re: FreeBasic and Arduino communication

Postby BasicCoder2 » Feb 25, 2016 1:58

@MrSwiss,

I had already stripped your code example to it's bare bones :)

FreeBasic code:

Code: Select all

Dim Shared As String   Key, buffer

Cls

Open Com "COM9:9600,n,8,1,cs0,ds0,cd0,rs" As #1
If Err <> 0 Then
   Print "Error opening COM9"
   Sleep 2000,1
   Cls
   end
End If

Do
   Key = InKey

   If Key <> "" Then
      If Key = Chr(13) Then   ' Check for CR
         Print #1, Chr(13);   ' Send CR
      Else
         Print #1,Key;
      End If
   End If

   ' When used with a serial device, LOC returns the number of bytes
   ' waiting to be read from the serial device's input buffer.
   While LOC(1) > 0
      buffer = Input(LOC(1),#1)
      Print buffer;
   Wend

   Sleep 1
Loop until Key=chr(27)


Close #1

sleep



This is the Arduino test code which turns the pin13 LED on with an 'a' key and off if you enter a 'b' key.

Arduino code:

Code: Select all

int serialData = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(13,OUTPUT);
}

void loop()
{
  if (Serial.available() > 0)
  {
    serialData = Serial.read();
    if (serialData == 97)
       digitalWrite(13,HIGH);

    if (serialData == 98)
       digitalWrite(13,LOW);
       
    Serial.println(serialData);  // return data
  } 
}
MrSwiss
Posts: 2024
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: FreeBasic and Arduino communication

Postby MrSwiss » Feb 25, 2016 12:19

@BasicCoder2,

you seem to get "into it" :-)

I've had a look at the Python stuff you've mentioned recently (only the Sketch), Servo-Control.
It proofed to be "full of Beans", e.g. missing bracketing and so on, so I've given it a work-over:

Code: Select all

#include <Servo.h>          // include the Servo-Library

Servo myservo;              // define a Servo-Object
int angle = 0;              // a Short in FB (16bit)
int newAngle = 0;           // dito
const byte MaxChars = 4;    // a Const Byte in FB (8bit)
char strValue[MaxChars+1];  // a fixed size 'ZString * 5' in FB (4 + Terminator)
byte index = 0;             // a Byte in FB (8bit)

void setup() {
  Serial.begin(9600);       // set serial speed (in Baud)
  myservo.attach(10);       // define the servo's Pin
  angle = 90;               // define start position of servo (Center)
}                           // the working range of the servo is: 0 to 180

void loop() {
  // do: nothing
}

void serialEvent() { 
  while(Serial.available()) {
    char ch = Serial.read();
      // if negative, the remaining positive is set! (on next run)
      // therefore, the 'controlling program' MUST prevent that!
      if(index < MaxChars && isDigit(ch)) {
        strValue[index++] = ch;
      } else {
        strValue[index] = 0;
        newAngle = atoi(strValue);
        if(newAngle < 181) {    // 180 is a valid input! fixed!
          if(newAngle < angle) {
            for(; angle > newAngle; angle -= 1) {   // step size = -1
              myservo.write(angle);
              // maybe a small 'delay(2);' or similar needed
            }
          } else {
            for(; angle < newAngle; angle += 1) {   // step size = +1
              myservo.write(angle);
              // maybe a small 'delay(2);' or similar needed
            }
          }
        } else {
          Serial.write(64);     // indicate 'above max. value' prepend "@"
        }
        Serial.write(strValue); // return new Angle setting (if any)
        // Serial.write(10);       // append a LF (line feed) to show 'finished'
        index = 0;
        angle = newAngle;
      }
   }
}
The corresponding FB-Code, call it 'Servo.bas' if you like:

Code: Select all

' Servo.bas -- (c) 2016, MrSwiss
' tested: FBC for WIN64 ver. 1.05.0 + Arduno AVR 168 / 16 KHz

ReDim As String      inpLine(1 To 1)   ' dynamic string array (stores Servo.txt)
Const As String      inFile = "Servo.txt"
Dim As Long       inFileNo, LineCnt = 0
Dim As Boolean      ErrExit

inFileNo = FreeFile
Color 15, 4 : Cls

If Open (ExePath+"\"+inFile For Input As #inFileNo) Then   ' "Servo.txt" must be in EXE-DIR!
   Cls : Locate 2, 2
   Print "ERROR: opening file "+ExePath+"\"+inFile+", aborting ..."
   ErrExit = TRUE
Else
   Locate 2,2 : Print "OPEN: '"+inFile+"' success!"
End If
If ErrExit Then Close inFileNo : Sleep : End   ' on "Open File"-Error quit prog.

Do Until Eof(inFileNo)      ' read whole file, line by line until EOF OR preset max-len
   LineCnt += 1         ' starts at 1 (0 + 1 = 1, see inpLine()/LineCnt declarations)
   Line Input #inFileNo, inpLine(LineCnt)   ' read one line into string array
   ReDim Preserve inpLine(1 To LineCnt+1)   ' append a new string to array, keep content
   If LineCnt > 2500 Then   ' set array-max. to 2500 strings
      LineCnt = 2500      ' adjust array line counter (-1), important !
      Exit Do            ' get out of do/loop NOW !!!
   EndIf
Loop
ReDim Preserve inpLine(1 To LineCnt)   ' throw away 'empty' string !
Close inFileNo                     ' always close opened file, if no longer required
Dim As Const Long maxLine = LineCnt      ' remember the max. LineCnt

' ====================================================================== '
' Serial Communication starts here:
' ---------------------------------------------------------------------- '
' Contrary to FB-Terminal:
' ~~~~~~~~~~~~~~~~~~~~~~~~
' Send / Receive works with short Strings (ZString * 5 for sending),
' receiving String Lenght varies, see Explanation on LOC().
' ====================================================================== '

inFileNo = FreeFile         ' re-use of declared var.

Open Com "COM3:9600,N,8,1,cs0,ds0,cd0,rs" As inFileNo   ' change as needed!
If Err Then
   Locate 2,2 : Print "OPEN: 'COM3:9600,N,8,1' failed!"
   Sleep : Close inFileNo : End
Else
   Locate 2,42 : Print "OPEN: 'COM3:9600,N,8,1' success!"
EndIf

View Print 4 To 25         ' Console setup ...
Color 14, 1 : Cls
Sleep 2000, 1            ' give some Time to establish Connect ...

' below: NOT to be confused with OS-/HW-Buffers (they can't be controlled from here!)
Dim As ZString * 5    sendStr = ""   ' TX-Buffer (transmit/send)
Dim As String       buffer  = ""   ' RX-Buffer (receive)


Do
   LineCnt   = 1            ' re-use of declared var.

   While LineCnt < maxLine+1      ' run until the End of String Array
      sendStr = inpLine(LineCnt)   ' get TX-Buffer (Cmd_Line from StringArray (max. 4 Byte))
      If CLng(sendStr) < 0 Then sendStr = ""   ' don't allow negative values, see Sketch!
      Print "FB: " + sendStr;      ' suppress LF (we want Arduino's Response on the same Line!)
      Print #inFileNo, sendStr   ' send Command String to Arduino
      LineCnt += 1      ' prepare array index for next run
      Sleep 300, 1      ' give Arduino Time to answer ...
      If LOC(inFileNo) > 0 Then   ' LOC() returns Number of Bytes to read
         buffer = Input(LOC(inFileNo), #inFileNo)   ' read Serial-Buffer (into our own)
         Print " A: " + buffer   ' show the Response from Arduino
      Else
         Print " A: ???"   ' if we didn't get anything from Arduino, _
      End If            ' this may happen at Communication Start!
      buffer = ""         ' clear RX-Buffer for next run
   
      Sleep 700, 1      ' run approx. once a Second (a new Command)
   Wend

   Print "~~~~~~~~~~~~~~~~~~~~~~~"   ' indicate end of Data reached ... restart   

   Sleep 2000, 1         ' wait 2 Seconds before re-Start
Loop Until InKey() = Chr(255) + "k"   ' click the X to quit Program

Close inFileNo            ' always close opened COM-PORT, if no longer required
View Print 1 To 25         ' reset Console to default
Color 7, 0 : Cls         ' Color dito
End                     ' quit
Below the 'Servo.txt' File needed by 'Servo.exe':

Code: Select all

120;
90;
180;
140;
110;
70;
30;
0;
90;
The values (and their Number) can be changed any Time, just for Test's.

Explanations:
    Servo.txt is read (in full) into Memory and thereafter released.
    It contains what could be called: Aduino-Commands (Servo Position).
    This Example is sending/receiving String (unlike the other Examples posted before).
    I've written detailed Comments in the respective Code-Files
If there are still Questions, just ask ...
BasicCoder2
Posts: 2894
Joined: Jan 01, 2009 7:03
Location: Australia

Re: FreeBasic and Arduino communication

Postby BasicCoder2 » Feb 26, 2016 0:42

@MrSwiss,

Something amiss as all the servo does is twitch with each change except for a big move clockwise at the start and a big move anticlockwise (back to start position I assume) with the program exit.

Screen outputs.
FB: 120; A: 120; ' big move

FB: 90; A: 90; 'twitch

FB: 180; A: 180 'twitch

and so on ....

One problem I did have with another Arduino servo example was it would move back and forth a few times as it was programmed to do and then freeze. Giving the board its own power supply instead of using the USB power supply seemed to fix that.

.
MrSwiss
Posts: 2024
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: FreeBasic and Arduino communication

Postby MrSwiss » Feb 26, 2016 2:29

@BasicCoder2,

yes it is probably a Power issue, since the Guy who posted the original Sketch mentioned
using a Motor Driver Shield (which would take the Strain off the Arduino).
Alternative a powered USB-Hub, or as you mentioned, a separate Power Supply.

The Servo might also not support the 1° Steps. You'd have to check Doc. of Servo for min.
Step-Size and so on. With bigger Steps you might have to use a Delay (as in Comments).
BasicCoder2
Posts: 2894
Joined: Jan 01, 2009 7:03
Location: Australia

Re: FreeBasic and Arduino communication

Postby BasicCoder2 » Feb 26, 2016 3:27

@MrSwiss,

Inserting a delay(1) fixed the problem.

When I used delay(2) I got a strange result.

FB: 120; A: 120
FB: 90; A: 90
FB: 180; A: ???
FB: 140; A: 180140
FB: 110; A: 110
FB: 70; A: 70

And larger delays gave other strange results.

I find the need for a delay less than robust although I see it used that way in other example code.

Although there are lots of interesting stand alone projects for the Arduino my interest involves the power of a pc and the ease of using FreeBASIC.
The arduino is then just used as an intelligent usb interface for any FreeBASIC hardware project.

.
Last edited by BasicCoder2 on Feb 26, 2016 8:27, edited 3 times in total.
caseih
Posts: 1040
Joined: Feb 26, 2007 5:32

Re: FreeBasic and Arduino communication

Postby caseih » Feb 26, 2016 5:26

As it happens I've been writing some FB code today to read serial data from a device I'm working on. More or less equivalent to what you are doing. The device is an Atmel device, but it's not Arduino. I had to reverse engineer their protocol, which wasn't too difficult.

I'm using input(#sp,1) to read 1 byte at a time. I've found that input() blocks if there's no bytes forthcoming on the serial port, which is usually fine. I've discovered that a keystroke (at least in graphics mode; not sure about console mode) will cause input() to return an empty string, which works well for me because I can then check inkey to look at the keystroke. So my program can be more or less interactive. But I read that lof() should return the number of bytes waiting in the serial port buffer. However on my Linux machine this always returns 0. It would be nice if this worked, as I could then implement a timeout to do some background tasks like update the screen, and some other things.

Is this a bug perhaps, specific to Linux?
MrSwiss
Posts: 2024
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: FreeBasic and Arduino communication

Postby MrSwiss » Feb 26, 2016 11:00

@BasicCoder2,

the Output you've posted indicates that:

Sleep 300, 1 ' give Arduino Time to answer ... (in FB Prog.)

is probably set a bit to short [for: delay(2);], since it is something like, roughly:
(try [500, 1], + subtract added value from the second Sleep, before the 'Wend')

((singleStep + StepDelay) * StepNumbers) + "Margin"
Margin = Time for running Prog. + Communication Overhead + Delay

Communication Overhead: might be reduced by 'upping' the Baud-Rate, e.g. 19'200.
I've run my Arduino up to: 115'200 Baud ... (the Setting in Properties: COM-PORT).

You'd probably have to find out empirically, e.g. Trial & Error Method.


@caseih,

I'm using LOC() to get the Number of Bytes to read (from Serial Buffer "OS").
Don't know about LOF()? Isn't this more Keyboard-Buffer related? CR&LF/LF Stuff?
Since I'm on WIN, I've no (in Depth) Information about HW Treatment in UX/LX.
caseih
Posts: 1040
Joined: Feb 26, 2007 5:32

Re: FreeBasic and Arduino communication

Postby caseih » Feb 26, 2016 15:39

I'll try it out, MrSwiss. The docs indicate lof() is the proper call as it's supposed to return the number of bytes unread in the buffer. loc() returns the current read position in the file, with no mention of what it does with a serial port. I'll give it a shot. EDIT: Yes it seems to work as a trigger. loc() returns 0 when the buffer is empty, and when it's full, it counts up.
MrSwiss
Posts: 2024
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: FreeBasic and Arduino communication

Postby MrSwiss » Feb 26, 2016 16:56

caseih wrote:... file, with no mention of what it does with a serial port.
@caseih, your Manual is probably outdated.

(from Manual 1.05.0) [LOC()] Description: When used with a serial device, LOC returns the number of bytes waiting to be read
from the serial device's input buffer.
It even has a Example with Serial ... Alternative: see Online-Doc (The most up-to-Date Version, in any Case).
caseih
Posts: 1040
Joined: Feb 26, 2007 5:32

Re: FreeBasic and Arduino communication

Postby caseih » Feb 26, 2016 20:53

Ahh yes. So it does. Lof()'s page says something similar, which is why I tried it first, but it doesn't work, at least under Linux.

Return to “Hardware Interfaces / Communication”

Who is online

Users browsing this forum: No registered users and 2 guests