DIY hardware interface for simple data collection and robot control?

For issues with communication ports, protocols, etc.
h4tt3n
Posts: 698
Joined: Oct 22, 2005 21:12
Location: Denmark

Re: DIY hardware interface for simple data collection and robot control?

Post by h4tt3n »

MrSwiss wrote:
h4tt3n wrote:Do you know of an economic, software controllable piece of hardware that will allow us to flip a series of pins on/off or do measurements on them?
Yes, have a look at Arduino, or any of the many Clones: "Open Source HW", as well as
plenty possible add on Modules (for many specific tasks, such as Network, Robotics etc.).
Controlled by itself, autonomous mode (external control via VCP, serial communication).

Price here, for a Uno/Clone: 15 - 25 US$/piece (completely assembled/soldered board).
There are even special sets available, for educational purposes.
Thanks, noted! :-)
h4tt3n
Posts: 698
Joined: Oct 22, 2005 21:12
Location: Denmark

Re: DIY hardware interface for simple data collection and robot control?

Post by h4tt3n »

badidea wrote:Apart from the hardware, do you have practical (automation) ideas that the students would interest?
Yes. Most of it is pretty straight-forward. For the input part, I want to measure if a certain switch is on or off. I'd also like to measure frequency / rotations per second when comparing different pendulums / wind turbines / steam engines / DIY electromotors etc. I would also like to measure voltage as a means of comparing temperature / light / sound / generator output. For the output part, I would simply like to be able to turn stuff on and off, like a LED, relay, or thyristor.

With these basic building blocks, some scrap metal and bit of duct tape we can make almost everything.
Gunslinger
Posts: 103
Joined: Mar 08, 2016 19:10
Location: The Netherlands

Re: DIY hardware interface for simple data collection and robot control?

Post by Gunslinger »

A lot of arduino starter kit are easy to find.
https://nl.aliexpress.com/store/1738188 ... autifyAB=5
h4tt3n
Posts: 698
Joined: Oct 22, 2005 21:12
Location: Denmark

Re: DIY hardware interface for simple data collection and robot control?

Post by h4tt3n »

Hello again,

I've been looking into things and have decided on the Arduino. I have ordered an Arduino Uno and Mega and some extra shields for sensor input and motor control. The programming ide is very straight forward to use for anyone with basic programming skills, and when the mailman arrives I'll already have several test programs ready to install.
As a side note, growing up with the Commodore and Amiga computers, the lack of direct hardware access in modern pc's have become increasingly frustrating, and simply beeing able to read and write directly to a pin without having to install any libraries, drivers or bypass abstraction layers or safety measures really feels like beeing "home" again :-)

I'll keep you updated, Cheers Mike
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: DIY hardware interface for simple data collection and robot control?

Post by grindstone »

I found an interesting site:
http://vusb.wikidot.com/start
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: DIY hardware interface for simple data collection and robot control?

Post by MrSwiss »

h4tt3n wrote:I'll keep you updated, Cheers Mike
Well, how far is your current progress? Just curious ...
h4tt3n
Posts: 698
Joined: Oct 22, 2005 21:12
Location: Denmark

Re: DIY hardware interface for simple data collection and robot control?

Post by h4tt3n »

MrSwiss wrote:
h4tt3n wrote:I'll keep you updated, Cheers Mike
Well, how far is your current progress? Just curious ...
I ended up trying Arduino and wasn't disappointed. It's basically like an old Commodore 64 in a matchbox :-) For a very few quid, and spending a very little time, you've got LED's blinking and stepper motors humming about. Throw in a few rubber bands, some duct tape, scrap wood, and LEGO bricks, and you're away inventing stuff.

Cheers, Mike
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: DIY hardware interface for simple data collection and robot control?

Post by TJF »

Hi h4tt3n!

Arduino is a good choise, since newcommers can get a system running in a short time. They don't have to study lots of configuration stuff.

But it's limited when it comes to big memory or fast CPU requirements, ie. video or network tasks. And you cannot follow your initial plan
h4tt3n wrote:... I am planning on using FB as an integral part of my education.
Unfortunatelly nobody pointed you to the Beaglebone hardware yet. That are modern check card computers in a cost range starting at Arduino level, but running a modern CPU under LINUX. Several hardware flovours are availabe, ie.
  • Pocket Beagle (headless, cheap and small)
  • Green (headless with original headers)
  • Green wireless (WLAN, headless with original headers)
  • Black (hdmi output)
  • Blue (prepared for roboting tasks)
Due to special co-processors (PRU = Programable Realtime Unit, two are available) they do not only have the same realtime capabilities as an Arduino, they are much better even when running under a non-realtime OS.

Unlike other LINUX systems the hardware configuration is as easy as on the Arduino. No setup in any system files. Instead everything gets controlled in single source from your code, when you use a special library called libpruio.

And finally this library is a FreeBASIC project. You can also use FreeBASIC for you project code, and therefor follow your original planning. (Further languages: currently C and Python.)

Do not hasitate to ask if you need further information.

Regards
h4tt3n
Posts: 698
Joined: Oct 22, 2005 21:12
Location: Denmark

Re: DIY hardware interface for simple data collection and robot control?

Post by h4tt3n »

Hi TJF,

That looks really cool! :) So far I'm going to stick with Arduino because I don't really need a lot of cpu power or memory, but I really, really need it to be simple, and I need the very easy I/O functionality that allows you to add sensors, led's, motors and so on.

Cheers, and happy holidays,
Mike
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: DIY hardware interface for simple data collection and robot control?

Post by TJF »

It does not only look cool :-)

Sure, it takes a lot off effort starting a new educational job. Everything has to be prepared well, in order not to fail in the classroom. You don't need much CPU power and memory. But your students may need in future. And when you have your head free, starting to think about their needs, I hope you'll remember my proposal.

All the best for your job!
fridlund
Posts: 24
Joined: Jun 03, 2007 15:24
Location: Southern California

Re: DIY hardware interface for simple data collection and robot control?

Post by fridlund »

Hi Ms. Swiss,
Re: the below, can you share any FB code you've written to use your LabJack U12? This looks like a simple DAQ that could work for my own lab applicaion as well. I just need the code to achieve A/D conversion of 4 channels, possibly some Digital I/O to 2 or 3 outputs. I see your application is commercial. Mine is not, but for my private university lab, and I'd be happy to sign any necessary NDA's
Many thanks,
Alan

I prefer a LabJack U12, any day (which I use for my commercial environmental Monitoring-SW).
    MrSwiss
    Posts: 3910
    Joined: Jun 02, 2013 9:27
    Location: Switzerland

    Re: DIY hardware interface for simple data collection and robot control?

    Post by MrSwiss »

    fridlund wrote:Hi Ms. Swiss, <-- MrSwiss please (I'm not Miss Switzerland ;-) )
    Re: the below, can you share any FB code you've written to use your LabJack U12?
    Sorry, but no (commercial), it's also far too complex for simple use.

    For simple Lab-Applications I'd use a "graphical coding environment" which most likely contains
    the necessary "building-block" to access the HW. This is far simpler, than coding that sort of
    thing yourself. (You'll have to link to a in C written DLL, e.t.c.)

    In the LabJackU12's driver kit, there is one of them included ... (trial version, IIRC).
    There are of course others like LabView(TM), to which you might already have access to, if
    you're working at a University (no additional cost).
    MrSwiss
    Posts: 3910
    Joined: Jun 02, 2013 9:27
    Location: Switzerland

    Re: DIY hardware interface for simple data collection and robot control?

    Post by MrSwiss »

    It is also from the FBC 32 bit, only days ...
    Therefore, I've tested it (q & d -- hack) if it still works, in principle.

    Just as a demo, how to load the DLL and access one single Function within.
    (I'd never use it that way. I'd split it into a static Lib, which the .exe loads.)

    LabJack_U12-first.bas:

    Code: Select all

    ' LabJack_U12-first.bas -- (c) 2019-10-16, MrSwiss
    '
    ' just a quick & dirty hack to show minimal use
    '
    
    Dim As Any Ptr  LJ_lib                  ' the DLL's base address
    
    #Ifdef __FB_64BIT__
    LJ_lib = DylibLoad("C:\Windows\System32\ljackuw.dll")   ' FBC 64
    #Else
    LJ_lib = DylibLoad("C:\Windows\SysWOW64\ljackuw.dll")   ' FBC 32
    #EndIf
    
    If LJ_lib = 0 Then
        Print "ERROR: 'ljackuw.dll' load failed!"
        Beep : Sleep : End 1
    End If
    
    Dim LJ_AISample As Function( _          ' Declaration of Function
        ByVal idnum       As Long   Ptr, _  ' @I32
        ByVal demo        As Long,       _  ' I32
        ByVal stateIO     As Long   Ptr, _
        ByVal updateIO    As Long,       _
        ByVal ledOn       As Long,       _
        ByVal numChannels As Long,       _
        ByVal channels    As Long   Ptr, _
        ByVal gains       As Long   Ptr, _
        ByVal disableCal  As Long,       _
        ByVal overVoltage As Long   Ptr, _
        ByVal voltages    As Single Ptr  _  ' float (binary32)
        ) As Long
    LJ_AISample = DylibSymbol(LJ_lib, "AISample")   ' Function Ptr
    
    If LJ_AISample = 0 Then
        Print "ERROR: 'LJ_AISample' load failed!"
        Beep : Sleep : End 2
    End If
    
    ' the whole data to be sent/aquired must be pre-allocated (dimmed)
    Dim As Long     LJ_idnum = -1, _        ' use @LJ_id in call (pointer)
                    LJ_demo = 0, _          ' straight use (not a pointer) real (not demo)
                    LJ_stateIO(0 To 3), _   ' digital pin's: 0 .. 3 (lo = 0, hi > 0)
                    LJ_updateIO = 0, _      ' default: don't update digital IO's (output)
                    LJ_ledOn = 1, _         ' default: ON
                    LJ_numChannels = 4, _   ' get 4 analog channels (max.)
                    LJ_channels(0 To 7) = { 0, 1, 2, 3, 4, 5, 6, 7 }, _ ' SE channels (2 call's needed!)
                    LJ_gains(0 To 3), _     ' not used on SE channels only differential channels
                    LJ_disableCal = 0, _    ' typically: OFF
                    LJ_overVoltage(0 To 7), _   ' per call only 4 needed
                    LJ_idx = 0              ' helper for channels selection (0 or 4)
    Dim As Single   LJ_voltages(0 To 7)     ' either @LJ_voltages(0) or @LJ_voltages(4)
    
    
    If LJ_AISample(@LJ_idnum, LJ_demo, @LJ_stateIO(0), LJ_updateIO, LJ_ledOn, _
                   LJ_numChannels, @LJ_channels(LJ_idx), @LJ_gains(0), LJ_disableCal, _
                   @LJ_overVoltage(LJ_idx), @LJ_voltages(LJ_idx)) > 0 Then
        Print "ERROR: 'LJ_AISample' call failed!"
        Beep : Sleep : End 3
    Else
        Print "AI0: "; LJ_voltages(0)
        Print "AI1: "; LJ_voltages(1)
        Print "AI2: "; LJ_voltages(2)
        Print "AI3: "; LJ_voltages(3)
        Print
        Print "D-I/O 0: "; LJ_channels(0)
        Print "D-I/O 1: "; LJ_channels(1)
        Print "D-I/O 2: "; LJ_channels(2)
        Print "D-I/O 3: "; LJ_channels(3)
    End If
    
    Sleep
    ' clean up: release loaded DLL
    DylibFree(LJ_lib)
    NOTE: it assumes a 64 bit Windows, may fail on 32 bits!
    fridlund
    Posts: 24
    Joined: Jun 03, 2007 15:24
    Location: Southern California

    Re: DIY hardware interface for simple data collection and robot control?

    Post by fridlund »

    Dear MrSwiss,
    Thank you so much for the help. I'll give your sample code a go.
    All the best,
    Alan
    fridlund
    Posts: 24
    Joined: Jun 03, 2007 15:24
    Location: Southern California

    Re: DIY hardware interface for simple data collection and robot control?

    Post by fridlund »

    Hi MrSwiss,
    It's been several weeks since you uploaded the U12 code, and I'm indebted to you sir. I managed to get it running and, folllowing your lead, some of the other U12 functions as well. I needed a scrolling plot of 4 A/D inputs with some Digital I/O for my application and so I thought I'd upload it here (below - I'll ask your forgiveness for the unprofessional coding in advance...).
    Two Q's:
    1. Would you mind if I uploaded this with attribution to you to the LabJack forum as well? They have almost no FB code for the U12.
    2. Have you by chance done any coding for the U3-HV? I'm having some problems setting up some of the U3 functions and wonder if you have some public code available as you did for the U12.
    Again, many thanks!
    Alan

    Code: Select all

    ' LabJack_U12-first.bas -- (c) 2019-10-16, MrSwiss
    '
    ' just a quick & dirty hack to show minimal use
    '
    ' LabJackTest for LabJack U12.
    '
    ' Code amended with scrolling plot -- 2019-11-25, Alan J. Fridlund,
    ' with much thanks to MrSwiss.
    
    SCREENRES 640,480                            ' Set up VGA resolution.
    Dim As Any Ptr LJ_lib                          ' To store the U12 DLL's base address.
    Dim FileNam as String
    Dim I As Integer
    Dim as Integer GraphCol, LeftGraphCol 
    Dim As Integer MaxScans, NumChan, NumScans
    Dim As Integer EOState0, EOState1, EIState2, EIState3 
    Dim As Single LJ_Plot(4), LJ_Voltages(4), VoltTemp
    Dim As String S
    
    # Ifdef __FB_64BIT__
     LJ_lib = DylibLoad("C:\Windows\System32\ljackuw.dll")      ' FBC 64
    # Else
     LJ_lib = DylibLoad("C:\Windows\SysWOW64\ljackuw.dll")   ' FBC 32
    # EndIf
    If LJ_lib = 0 Then
        Print "ERROR: 'ljackuw.dll' load failed!"
        Beep : Sleep : End 1
    End If
    
    Dim LJ_AISample As Function( _          ' Declaration of A/D Input Function
        ByVal idnum       As Long   Ptr, _  ' @I32
        ByVal demo        As Long,       _  ' I32
        ByVal stateIO     As Long   Ptr, _
        ByVal updateIO    As Long,       _
        ByVal ledOn       As Long,       _
        ByVal numChannels As Long,       _
        ByVal channels    As Long   Ptr, _
        ByVal gains       As Long   Ptr, _
        ByVal disableCal  As Long,       _
        ByVal overVoltage As Long   Ptr, _
        ByVal voltages    As Single Ptr  _  ' float (binary32)
        ) As Long
    LJ_AISample = DylibSymbol(LJ_lib, "AISample")   ' Function Ptr
    If LJ_AISample = 0 Then
        Print "ERROR: 'LJ_AISample' load failed!"
        Beep : Sleep : End 2
    End If
    
    '--------------------------------------
    ' Set up of these remaining functions following code by MrSwiss - AJF.
    '--------------------------------------
    
    Dim LJ_DigitalIO As Function( _          ' Declaration of Function
        ByVal Digidnum    As Long   Ptr, _  ' @I32
        ByVal demo        As Long,       _  ' I32
        ByVal trisIO      As Long,       _
        ByVal stateD      As Long   Ptr, _
        ByVal stateIO     As Long   Ptr, _
        ByVal updateDig   As Long,       _
        ByVal OutputD     As Long   Ptr  _
        ) As Long
    LJ_DigitalIO = DylibSymbol(LJ_lib, "DigitalIO")   ' Function Ptr
    If LJ_DigitalIO = 0 Then
        Print "ERROR: 'LJ_DigitalIO' load failed!"
        Beep : Sleep : End 2
    End If
    
    '--------------------------------------
    
    Dim LJ_EIDigitalIn As Function( _          ' Declaration of Function
        ByVal LJ_EIidnum       As Long   Ptr, _  ' @I32
        ByVal LJ_EIdemo        As Long,       _  ' I32
        ByVal LJ_EIchannel     As Long,       _
        ByVal LJ_EIread        As Long,       _
        ByVal LJ_EIstate       As Long   Ptr  _   
        ) As Long
    LJ_EIDigitalIn = DylibSymbol(LJ_lib, "EDigitalIn")   ' Function Ptr
    If LJ_EIDigitalIn = 0 Then
        Print "ERROR: 'LJ_EDigitalIn' load failed!"
        Beep : Sleep : End 2
    End If
    
    '--------------------------------------
    
    Dim LJ_EODigitalOut As Function( _          ' Declaration of Function
        ByVal LJ_EOidnum       As Long   Ptr, _  ' @I32
        ByVal LJ_EOdemo        As Long,       _  ' I32
        ByVal LJ_EOchannel     As Long,       _
        ByVal LJ_EOwriteD      As Long,       _
        ByVal LJ_EOstate       As Long        _   
        ) As Long
    LJ_EODigitalOut = DylibSymbol(LJ_lib, "EDigitalOut")   ' Function Ptr
    If LJ_EODigitalOut = 0 Then
        Print "ERROR: 'LJ_EODigitalOut0' load failed!"
        Beep : Sleep : End 2
    End If
    
    '--------------------------------------
    
    ' Nothing done with AOUpdate in the scrolling plot. - AJF
    Dim LJ_AOUpdate As Function( _          ' Declaration of Function
        ByVal AOidnum     As Long   Ptr, _  ' @I32
        ByVal trisd       As Long,       _  ' I32
        ByVal trisIO      As Long,       _  ' I32
        ByVal stateD      As Long   Ptr, _
        ByVal stateIO     As Long   Ptr, _
        ByVal updateDig   As Long,       _
        ByVal lngResCntr  As Long,       _
        ByVal count       As Long   Ptr, _
        ByVal gains       As Long   Ptr, _
        ByVal disableCal  As Long,       _
        ByVal AnalogOut0  As Single Ptr, _  ' float (binary32)
        ByVal AnalogOut1  As Single Ptr  _  ' float (binary32)
        ) As Long
    LJ_AOUpdate = DylibSymbol(LJ_lib, "AOUpdate")   ' Function Ptr
    If LJ_AOUpdate = 0 Then
        Print "ERROR: 'AOUpdate' load failed!"
        Beep : Sleep : End 2
    End If
    
    '--------------------------------------
    'Start of Scrolling Plot routine.
    
    Screen 640,480                                                         ' Set VGA screen mode, 8 bit color.
    Color 0, 0                                                                 ' Set up dark screen for scrolling plot.
    CLS
    FileNam = "TestFile.dat"  ' Just a test file name to write plotted data values.
    LeftGraphCol = 20
    GraphCol = LeftGraphCol + 1
    Line (LeftGraphCol - 1,470) - (630,470),12                 ' Set out plot abcissa and ordinate.
    Line (LeftGraphCol - 1,10) - (LeftGraphCol - 1,470),12
    
    NumChan = 4                                                            ' To sample 4 A/D channels.
    For I = 0 to NumChan - 1                                           ' Channels go from 0-3.
    Locate I*14+8,1: Color 5-I,0                                      ' Color-code A/D Inputs 0-3.
    Print "Ch": Print i                                                      ' Print A/D Channel labels on screen.
    Next
    If FileNam <> "" THEN                                               ' Print data file name on screen.
        LOCATE 60, 3: Color 7,0: Print " Recording to ";
        color 14,0: Print Filenam; " ";
    EndIf
    If Filenam <>"" Then OPEN Filenam for output as #1    ' Open the file for writing.
    
    Locate 60,58:Color 7,0                                              ' Display the labels for Dig inputs and outputs on screen.
    Print "O0:   O1:   I2:   I3:" 
    
    MaxScans = 1500                                                       ' Max # of scans of A/D inputs and I/O ports before auto-termination.
    NumScans = 0                                                            ' In-loop counter for # of scans of A/D inputs and I/O ports.
    
    Do                                                                            ' First acquire A/D inputs in array of size NumChannels (4 here).
    Dim As Long     LJ_idnum = -1, _        ' use @LJ_id in call (pointer)
                    LJ_demo = 0, _          ' straight use (not a pointer) real (not demo)
                    LJ_stateIO(0 To 3), _   ' digital pin's: 0 .. 3 (lo = 0, hi > 0)
                    LJ_updateIO = 0, _      ' default: don't update digital IO's (output)
                    LJ_ledOn = -1, _         ' default: ON
                    LJ_numChannels = 4, _   ' get 4 analog channels (max.)
                    LJ_channels(0 To 7) = { 0, 1, 2, 3, 4, 5, 6, 7 }, _ ' SE channels (2 call's needed!)
                    LJ_gains(0 To 3), _     ' not used on SE channels only differential channels
                    LJ_disableCal = 0, _    ' typically: OFF
                    LJ_overVoltage(0 To 7), _   ' per call only 4 needed
                    LJ_idx = 0              ' helper for channels selection (0 or 4)
    Dim As Single   LJ_voltages(0 to 7)     ' either @LJ_voltages(0) or @LJ_voltages(4)
    If LJ_AISample(@LJ_idnum, LJ_demo, @LJ_stateIO(1), LJ_updateIO, LJ_ledOn, _
                   LJ_numChannels, @LJ_channels(LJ_idx), @LJ_gains(0), LJ_disableCal, _
                   @LJ_overVoltage(LJ_idx), @LJ_voltages(LJ_idx)) > 0 Then
        Print "ERROR: 'LJ_AISample' call failed!"
        Beep : Sleep : End 
    Else                                                                        ' Call not failing means successful sampling.
        NumScans = NumScans + 1                                   ' Increment # of scans of A/D and Dig I/O ports.
        Locate 59, 33: Color 7,0: Print "Scans:";: Color 14,0: Print Numscans;  ' Print NumScans on screen.
        Color 7,0: Print " of:";: Color 14,0: Print MaxScans;
    End If
    
    Dim as Long LJ_EIidnum          = -1, _                        ' To read Digital Ports IO2 and IO3.
                LJ_EIdemo           = 0,  _
                LJ_EIchannel        = 2,  _
                LJ_EIread           = 0,  _
                LJ_EIstate          = 0
    If LJ_EIDigitalIn(@LJ_EIidnum, LJ_EIdemo, LJ_EIchannel, LJ_EIread, @LJ_EIstate) > 0 Then 
        Print "ERROR: 'LJ_EDigitalInCh2' load failed!"
        Beep : Sleep : End
    End If
    EIState2 = LJ_EIState
    LJ_EIChannel = 3
    If LJ_EIDigitalIn(@LJ_EIidnum, LJ_EIdemo, LJ_EIchannel, LJ_EIread, @LJ_EIstate) > 0 Then 
        Print "ERROR: 'LJ_EDigitalInCh3' load failed!"
        Beep : Sleep : End
    End If
    EIState3 = LJ_EIState
    
    Dim As Long     LJ_EOidnum  = -1, _                           ' To write Digital ports IO0 and IO1
                    LJ_EOdemo   = 0,  _ 
                    LJ_EOchannel= 0,  _
                    LJ_EOwriteD = 0,  _
                    LJ_EOstate  = 0      
    If GraphCol = 300 THEN                                              ' Just for giggles, at middle of plot set Dig Output IO0 to 0, IO1 to 1     
         LJ_EOChannel = 0
         LJ_EOstate  = 0      
         If LJ_EODigitalOut(@LJ_EOidnum, LJ_EOdemo, LJ_EOchannel, LJ_EOwriteD, LJ_EOstate) > 0 Then
            Print "ERROR: 'LJ_EODigitalOutCh0' call failed!": Beep  
            Else EOState0 = 0
         End If  
         LJ_EOChannel = 1
         LJ_EOstate  = 1
         If LJ_EODigitalOut(@LJ_EOidnum, LJ_EOdemo, LJ_EOchannel, LJ_EOwriteD, LJ_EOstate) > 0 Then
            Print "ERROR: 'LJ_EODigitalOutCh1' call failed!": Beep  
            Else EOState1 = 1
         End If  
    End IF
    If GraphCol = 21 THEN                                                'Just for giggles, switch IO ports at left of plot so Dig Output IO0 is 1, IO1 is 0                    
        LJ_EOChannel = 0
        LJ_EOstate  = 1      
        If LJ_EODigitalOut(@LJ_EOidnum, LJ_EOdemo, LJ_EOchannel, LJ_EOwriteD, LJ_EOstate) > 0 Then
            Print "ERROR: 'LJ_EODigitalOut3' call failed!": Beep
        Else EOState0 = 1
        EndIf
        LJ_EOChannel  = 1      
        LJ_EOstate  = 0      
        If LJ_EODigitalOut(@LJ_EOidnum, LJ_EOdemo, LJ_EOchannel, LJ_EOwriteD, LJ_EOstate) > 0 Then
            Print "ERROR: 'LJ_EODigitalOut3' call failed!": Beep
        Else EOState1 = 0
        EndIf
    End If  
    
    ' Now graph Scrolling Plot.
    Line (Graphcol+1, 461) - (GraphCol+1, 10), 0            ' Black line wipes across plot one step ahead of new data.
    If Filenam <>"" THEN
        If NumScans = 1 Then                                          ' On first scan, write a file header describing data.
            Print #1, "  Time    Scan#   AD0    AD1    AD2    AD3  O0 O1 I2 I3"
        End If    
        Print #1, Time$;
        Print #1, Using "#######"; NumScans;
    EndIf
    
    For I = 0 To NumChan - 1
        Locate I*14+9,4: Color 5-I
        Print Using "+##.##";LJ_Voltages(I)                      ' Print A/D input voltages on screen and write them to data file.
        If FileNam <> "" THEN Print #1, Using "+##.###"; LJ_Voltages(I);   
        LJ_Plot (I) = LJ_Voltages(I) *275 - i*112 + 2          ' Gain/offset #'s are fudged for plot placement; will need changing for diff voltage ranges.
        VoltTemp =  LJ_Plot(I)
        If VoltTemp < 11 Then VoltTemp = 11                    ' Confine displayed points to plot area.
        If VoltTemp > 461 Then VoltTemp = 461
        line (Graphcol, VoltTemp) - (GraphCol, VoltTemp-2), i+2         ' Draw data points with height*2 for thickness.   
    Next I
    
    Color 14, 0
    locate 59,61: Print Str(EOState0);                            ' Print Digital I/O values at bottom right of plot.
    locate 59,67: Print Str(EOState1);
    locate 59,73: Print Str(EIState2);
    Locate 59,79: Print Str(EIState3);
    
    If FileNam <> "" Then                                              ' Write Digital I/O values to data file.
        Print #1, Using "###"; EOState0; 
        Print #1, Using "###"; EOState1; 
        Print #1, Using "###"; EIState2; 
        Print #1, Using "###"; EIState3
    EndIf
    
    GraphCol = GraphCol + 1: If GraphCol >629 then GraphCol = LeftGraphCol + 1        ' Plot at right end of abcissa; reset to plot left.
    
    S = Inkey
    Loop Until NumScans >= MaxScans or S = chr(27)      ' Keep scanning until MaxScans or Esc keypress.
    
    Locate 57, 28                                                         ' Prompt on screen to end program.
    Color 7,0: Print "Press <";
    Color 12,0: Print "Enter";
    Color 7,0: Print "> to End Program."
    
    Do                                                                        ' <Enter> keypress to end proggie.
    S= inkey    
    Loop Until S = CHR(13) 
    
    Close #1                                                               ' Close data file and release loaded DLL.
    DylibFree(LJ_lib)
    End
    
    
    Post Reply