Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Controlling etho / USB relay

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Controlling etho / USB relay

    Hi. I�m looking for some help and advise on firstly what hardware to buy and secondly how to send and receive data from the device using alpha5.

    I�m looking to be able to read some signals from a machine and when the signal is on run some xbasic code and depending on the result activate a relay which will allow a second machine to load some material from the first

    I have found this device http://www.robot-electronics.co.uk/htm/eth484tech.htm , but am unsure if it will work with Alpha5

    Any help and advice will be very much appreciated

    Thanks

    Pete
    Pete Jones
    IT Manager
    Midlands Metal Fabrications

    #2
    Re: Controlling etho / USB relay

    Pete, Below is a script we use to read information from a weight scale via serial. You might be able to use the code with a serial based device.

    FUNCTION Cas_Read_Scale AS C ( )

    'Dim some DotNet stuff
    DIM Serial_Port as System::IO::Ports::SerialPort
    DIM Parity as System::IO::Ports::Parity
    DIM StopBits as System::IO::Ports::StopBits
    DIM vReceiveString as C

    'Define COM port setting
    Serial_Port.PortName = "COM1"
    Serial_Port.BaudRate = 9600
    Serial_Port.DataBits = 8
    Serial_Port.Parity = Parity.None
    Serial_Port.StopBits = StopBits.One

    if Serial_Port.IsOpen = .F. then
    Serial_Port.Open() 'Open the Serial port

    vReceiveString = Serial_Port.ReadLine() 'Read scale data

    if left(vReceiveString,4)="NET:" .or. left(vReceiveString,4)="net:"
    Show_Weight(.t.,vReceiveString)
    end if

    Serial_Port.Close() 'Close the Serial port
    else
    msgbox("The Scale is turned off or Serial Port is in use by another device")
    end if

    END FUNCTION

    Comment


      #3
      Re: Controlling etho / USB relay

      Hi Scott,

      Thank you for the info, this may come in use later as we have a need to weigh powder in and out of our system!

      I have now purchased a USB experimental interface board which uses a dll file to communicate and am struggling with the correct syntax to use!

      The board comes with examples in various languages and the sample visual basic code works fine on my PC

      Code:
      Visual Basic 6.0
      Private Declare Sub ReadAll Lib "k8055d.dll" (ByVal data As Long)
      Private Declare Function Version Lib "k8055d.dll" () As Long
      Private Declare Function SearchDevices Lib "k8055d.dll" () As Long
      Private Declare Function SetCurrentDevice Lib "k8055d.dll" (ByVal CardAddress As Long) As Long
      Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Long) As Long
      Private Declare Sub CloseDevice Lib "k8055d.dll" ()
      Private Declare Function ReadAnalogChannel Lib "k8055d.dll" (ByVal Channel As Long) As Long
      Private Declare Sub ReadAllAnalog Lib "k8055d.dll" (ByVal Data1 As Long, ByVal Data2 As Long)
      Private Declare Sub OutputAnalogChannel Lib "k8055d.dll" (ByVal Channel As Long, ByVal data As Long)
      Private Declare Sub OutputAllAnalog Lib "k8055d.dll" (ByVal Data1 As Long, ByVal Data2 As Long)
      Private Declare Sub ClearAnalogChannel Lib "k8055d.dll" (ByVal Channel As Long)
      Private Declare Sub SetAllAnalog Lib "k8055d.dll" ()
      Private Declare Sub ClearAllAnalog Lib "k8055d.dll" ()
      Private Declare Sub SetAnalogChannel Lib "k8055d.dll" (ByVal Channel As Long)
      Private Declare Sub WriteAllDigital Lib "k8055d.dll" (ByVal data As Long)
      Private Declare Sub ClearDigitalChannel Lib "k8055d.dll" (ByVal Channel As Long)
      Private Declare Sub ClearAllDigital Lib "k8055d.dll" ()
      Private Declare Sub SetDigitalChannel Lib "k8055d.dll" (ByVal Channel As Long)
      Private Declare Sub SetAllDigital Lib "k8055d.dll" ()
      Private Declare Function ReadDigitalChannel Lib "k8055d.dll" (ByVal Channel As Long) As Boolean
      Private Declare Function ReadAllDigital Lib "k8055d.dll" () As Long
      Private Declare Function ReadCounter Lib "k8055d.dll" (ByVal CounterNr As Long) As Long
      Private Declare Sub ResetCounter Lib "k8055d.dll" (ByVal CounterNr As Long)
      Private Declare Sub SetCounterDebounceTime Lib "k8055d.dll" (ByVal CounterNr As Long, ByVal DebounceTime
      As Long)
      Private Declare Function ReadBackDigitalOut Lib "k8055d.dll" () As Long
      Private Declare Sub ReadBackAnalogOut Lib "k8055d.dll" (ByRef Buffer As Long)
      My Problem now is how I convert this to Xbasic and get it all working

      As a starting point it would be good to open the device and read the digital inputs. I have tried the following without success

      Code:
      'private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Long) As Long
      Declare k8055d OpenDevice As LL
      'Private Declare Function ReadAllDigital Lib "k8055d.dll" () As Long
      Declare k8055d ReadAllDigital As L
      dim h as n 
      h = OpenDevice(0)
      dim data1 as n
      data1 = ReadAllDigital()
      It would be great if someone had a few pointers to get me in the right direction

      Thanks

      Pete
      Pete Jones
      IT Manager
      Midlands Metal Fabrications

      Comment


        #4
        Re: Controlling etho / USB relay

        You might want to look at


        A5_Run_VBScript()
        There can be only one.

        Comment


          #5
          Re: Controlling etho / USB relay

          I'd guess that Marcel Kollenar knows more about this stuff than anyone. He has also done an amazing job on his website to provide guidance on how to communicate with external dll's via Declare, Declarestruct and Type. Here' s the link

          http://members.home.nl/xbasic/01c224...701/index.html
          Finian

          Comment


            #6
            Re: Controlling etho / USB relay

            Stan,

            I took a look at A5_Run_VBScript() and managed to get it to run using the sample in the help file although when I try some of the VB code supplied with the device I get an error OLE Automation Error. Source is Microsoft VBScript compilation error."Expected end of statement"

            Code:
            dim vbscript as c 
            vbscript= <<%a%
            Option Explicit
            Dim n As Integer
            Private Declare Function version Lib "k8055d.dll" Alias "Version" () As Long
            Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Long) As Long
            Private Declare Function ReadAllDigital Lib "k8055d.dll" () As Long
            Public Sub form_load()
                Dim ver As Long
                ver = version()
                MsgBox CStr(ver \ 2 ^ 24) + "." + CStr(&HFF And (ver \ 2 ^ 16)) + "." + CStr(&HFF And (ver \ 2 ^ 8)) + "." + CStr(&HFF And ver)
                Dim sd
                sd = OpenDevice(2)
                MsgBox sd
                Dim do_board
                do_board = ReadAllDigital
                MsgBox do_board
                End
            End Sub
            %a%
            result = a5_run_VBScript(vbscript) 
            if result <> "" 
                 ui_msg_box("script error", result, UI_STOP_SYMBOL) 
            end if
            I'm not sure that this is the best way to go though as the VB code that came with the device is only a sample and I would have no idea how to program what I need in VB.

            Finian,

            I have seen Marcel's website, but am still struggling to understand the syntax and if I need a declarestructure aswell!

            The following gives the version of the dll in VB and doesn't need the device to work, so if I had a little bit of help to crack this bit it would put me on track for the rest I have attached the dll file
            Code:
            Private Declare Function version Lib "k8055d.dll" Alias "Version" () As Long
                Dim ver As Long
                ver = version()
                MsgBox CStr(ver \ 2 ^ 24) + "." + CStr(&HFF And (ver \ 2 ^ 16)) + "." + CStr(&HFF And (ver \ 2 ^ 8)) + "." + CStr(&HFF And ver)
                End
            End Sub
            My code looks like this

            Code:
            Declare k8055d.dll bver@Version as L
            ver = bver()
            ui_msg_box("",ver)
            and it errors on line 2 with "too few parameters"
            Attached Files
            Last edited by Pete119j; 04-16-2014, 03:46 AM.
            Pete Jones
            IT Manager
            Midlands Metal Fabrications

            Comment


              #7
              Re: Controlling etho / USB relay

              Success

              Arrived this morning and gave it one last go and have got 3 of the functions to work.

              Code:
              'Get version of DLL file
              ' VB6 Private Declare Function version Lib "k8055d.dll" Alias "Version" () As Long
              Declare k8055d.dll bver@Version L 'the version function name has to be changes to bver as it conflicts with the alpha5 function version()
              ver = bver()
              ui_msg_box("",ver)
              
              'Open Device
              'VB6 Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Long) As Long
              declare k8055d.dll OpenDevice LL
              a = opendevice(0) 
              ui_msg_box("",a)
              
              'Read All Digital outputs
              'VB6 Private Declare Function ReadAllDigital Lib "k8055d.dll" () As Long
              declare k8055d.dll ReadAllDigital L
              b = readalldigital()
              ui_msg_box("",b)
              Now all I need to do is get it to interact with the machine!
              Pete Jones
              IT Manager
              Midlands Metal Fabrications

              Comment


                #8
                Re: Controlling etho / USB relay

                Since I spent some time on this today, I thought I would weight in on the topic.
                I was given the assignment by my client of connecting a Brecknell Scale to the web app I had developed for him.
                After some discussion with the great technical support at Brecknell, we got the port set up correctly using their software, and successfully tested it with Hillgraeve's HyperTerminal . I then wrote this Xbasic function as an Ajax callback in the onFocus event of the dialog's weight field:
                function getScaleWeight as c (e as p)
                dim sp as system::io::Ports::SerialPort
                dim vn_scale_count as n = 0

                sp.PortName = "COM5"
                sp.Open()
                repeat_query:
                sleep(2)
                if vn_scale_count = 15 then
                goto error_msg
                end if

                vc_comm_string = sp.ReadExisting()
                if vc_comm_string = "" then
                vn_scale_count = vn_scale_count + 1
                goto repeat_query
                end if
                vn_weight_value = val(remspecial(vc_comm_string))/1000
                sp.close()
                e._set.weight.value = vn_weight_value

                end

                error_msg:
                sp.close()
                getScaleWeight = "alert('Too many tries, script failed');"

                end function
                This function fires after the user is told through an alert box to hit the "Hold/Print" button on the scale after closing the alert box. The script then keeps trying to read the comm port until it either gets the data, or times out. Adjusting the sleep time or the number of tries will adjust the total time before the script times out if no data appears.
                Hope this helps.
                Jay
                Jay Talbott
                Lexington, KY

                Comment


                  #9
                  Re: Controlling etho / USB relay

                  Hi Jay,
                  Thanks for the update. I may need something like this in the future. Could you expand on the physical setup. Since you are doing this through a call back which I assume runs on the server does that mean the scale is connected to the server?

                  Thanks
                  Tim Kiebert
                  Eagle Creek Citrus
                  A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                  Comment


                    #10
                    Re: Controlling etho / USB relay

                    Good point, Tim.
                    Yes, it will have to be on the server.
                    Jay
                    Jay Talbott
                    Lexington, KY

                    Comment


                      #11
                      Re: Controlling etho / USB relay

                      Thought it might. :-) Thanks
                      Tim Kiebert
                      Eagle Creek Citrus
                      A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                      Comment


                        #12
                        Re: Controlling etho / USB relay

                        Since you bought it up, Tim, I have been pondering the possibility of getting the data from a serial port if the computer is attached to a client, not to the server.
                        This link:
                        http://stackoverflow.com/questions/6...he-serial-port indicates that this is possible, but I am wondering if anyone reading this has ever done such a thing.

                        Any help, suggestions, or advice would be appreciated.

                        Jay
                        Last edited by Jay Talbott; 08-13-2014, 01:37 PM.
                        Jay Talbott
                        Lexington, KY

                        Comment

                        Working...
                        X