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

Serial Communications Active X Demo

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

    Serial Communications Active X Demo

    The following is a demo program that uses a low cost ActiveX control to add RS232 Serial routines to Alpha5 Version 10 and possibly Version 8 & 9. Should also work in version 11 if you don't want to use it's built in .NET support and serial routines provided by .NET.

    This sample script creates a Dialog box that allows the serial port parameters to be set and the port opened. Provision for sending commands and receiving text are provided. With little work this dialog can be made modeless and can send text to forms and global variables etc.

    Code:
    'Date Created: 17-Mar-2014 10:56:11 AM
    'Last Updated: 20-Mar-2014 08:43:59 AM
    'Created By  : Paul Verboom
    'Updated By  : Paul Verboom
    '----------
    'Ser-Config
    '----------
    'Configure and test serial communications
    'using StrokeReader ActiveX Control
    'http://strokescribe.com/en/serial-port-about.html
    '
    'Well documented, low cost ($70) unlimited ditribution
    'serial port interface ActiveX control with event-driven, asynchronous data transfer.
    'free demo version of StrokeReader puts up occasional nag screen
    'but is perfectly adequate for testing purposes.
    
    'This code devolped in Alpha Ver 10 should work in version 9 as well
    'Alpha5 Ver 11 has support for .NET and it's serial routines.
    
    'Name: StrokeReader Control
    'Prog Id: strokescribe.strokereaderctrl.1
    'UUID: {7E42B8C5-73BE-4806-8904-FF4080A696EC}
    
    '-----------------------------
    '// Set up Serial paramters --
    '-----------------------------
    DIM PortName as C                        'Parameters for serial Port
    DIM BaudRate as C
    DIM DataBits as C
    DIM Parity as C
    DIM StopBits as C
    'PortName = "COM4 -"                    'Default Parameters for serial port
    'BaudRate = "9600"                                    
    'DataBits = "8"    
    'Parity = "None"
    'Stopbits = "1"
    
    '-------------------------------------
    '// Retrieve settings from registry --
    '-------------------------------------
    DIM PT as P
    PT.PortName = ""
    PT.BaudRate = "9600"
    PT.DataBits = "8"
    PT.Parity = "None"
    PT.Stopbits = "1"
    :REGISTRY.LOAD_SETTINGS("PineTracker",PT)
    PortName = PT.PortName                    'Can not use dot variables in Dialogs 
    BaudRate = PT.BaudRate                     'so copy them to regular strings
    DataBits = PT.DataBits
    Parity = PT.Parity
    StopBits = PT.StopBits
    
    '-------------------------------------
    '// Set up variables used by Dialog --
    '-------------------------------------
    delete TextBld                            'Variables used by xBasic code
    DIM SHARED TextBld as C = ""            'That processes StrokeReader events
    delete TextIn                            'Clear variable before use
    DIM SHARED TextIn as C = ""                'in case event code somehow
    Delete Status                            'creates a variable with local scope
    DIM SHARED Status as C = ""
    
    DIM SHARED TextOut as C                    'The text to be sent to serial port
    
    DIM Result as C                            'The result after exiting dialog
    
    DIM s AS C                                'used to build list of available ports
    DIM Ports as C
    DIM Port as C
    
    DELETE a_Port                            'Building list of ports must be done within
    DIM a_Port[0] as c                        'the Dialog as ACtiveX Control is Used
    
    DELETE a_BaudRate                        'Define available/common Bud rates
    DIM a_BaudRate[10] as c
    dim temp_list as c 
    temp_list = <<%list%
    115200
    57600
    38400
    19200
    9600
    1200
    300
    %list%
    a_BaudRate.initialize(temp_list)
    
    '-----------------------------
    '// Set some default values --
    '-----------------------------
    DIM DialogTtl as C = "StrokeReader in Alpha5 Demo"    'Title for Dialog
    
    dim Sample_Textout as c                                'Sample text to send out serial port
    Sample_Textout = <<%list%
    This is a test.
    This is the second test.
    %list%
    
    '-----------------------------------
    '\\ Complete variable assignments --
    '-----------------------------------
    DELETE a_SendText                                    'Define pull down for text to send out serial port
    DIM a_TextOut[line_count(Sample_Textout)] as c
    a_TextOut.initialize(Sample_Textout)
    
    '--------------------------------------------------------------------
    '\\ Define ObjectName required to place ActiveX Control in xDialog --
    '--------------------------------------------------------------------
    dim SR as P
    dim SR.object as P
    dim SR.class as C
    SR.class = "strokescribe.strokereaderctrl.1"
    SR.Events =<<%code%
    function commevent as v (Evt as N,data as C)
        'Evt - Can be one of following values:
        'EVT_DISCONNECT (=0)
        'EVT_DATA (=1)
        'EVT_SERIALEVENT (=2)
        'EVT_CONNECT (=3)
        'Data - Can contain an array of received bytes or a text string or 
        '        an integer mask value indicating the type of serial port events that occurred.
        Select 
            Case Evt = 0
                Status = "Disconnected"
            Case Evt = 3
                Status = "Connected"
                TextTest = "Can set it here"
            Case Evt = 1
                TextBld = TextBld + data
                while chr(13) $ TextBld
                    S = left(TextBld,AT(CHR(13),TextBld)-1)
                    TextBld = substr(TextBld,AT(CHR(13),TextBld)+1)
                    'while Left(TextBld,1) $ crlf()
                    '    TextBld = substr(TextBld,2)
                    'wend
                    TextIn = TextIn + S + crlf()
                    '!ui_msg_box("TextIn",TextIn,UI_OK)
                    '!ui_beep(UI_ASTERISK_BEEP)
                wend
            Case Evt = 3
                Status = "Control line Change"
                'Could be elborated to to include information from Data value
            Case Else
                Status = "Unknown serial Event Type"
        end select            
    end function
    %code%
    
    '---------------------------
    '// Define the Dialog Box --
    '---------------------------
    'Notes
    '{ActiveX}                     - Places ActiveX control dialog, requires dot variable defined prepared previously
    '{Watch=}                    - Fires an event when a variable changes such as incoming text
    '{StartUp}                     - Defines a event to trigger such as connect when dialog is displayed.
    '
    'The Textin window must be read only [%r%.40VARIABLENAME] otherwise processing an event
    'will cause the current value on screen to be assigned to the Variable overwritting
    'the incoming text placed in the variable by the the StrokeReader event
    '
    Dialog =<<%dlg%
    {region}
    <%T= Press to reread available Serial Ports%&Read Ports!Ports>
    | [.80,5PortName^#a_Port];
    {activex=1,1SR}
    {startup=Ports}
    {Watch=TextIn!Show}
    Baud Rate:| [%v%.7BaudRate^=a_BaudRate];
    {region}Data Bits:{endregion}|
    {region}(DataBits:5)(DataBits:6)(DataBits:7)(DataBits:8){endregion};
    
    {region}Parity:{endregion}|
    {region}(Parity:None)(Parity:Odd)(Parity:Even)(Parity:Mark)(Parity:Space){endregion};
    ;
    {region}Stop Bits:{endregion}|
    {region}(StopBits:1)(StopBits:1.5)(StopBits:2){endregion};
    ;
    <%T= Press to send enterred Text%&Send!Send>
    | [%v%.77TextOut^+a_TextOut];
    TextIn:| [%rmw%.80,10TextIn!show];
    Status:| [.80Status];
    {endregion};
    {line=1,0};
    {region}
    {SP4}
    <%T=Apply port settings and open connection%20&Connect!Connect>
    {SP4}
    <%T=Disconnect from port%20&Disconnect!Disconnect>
    {SP4}
    <%T=Save Settings and Exit%15&Exit>
    {endregion};
    %dlg%
    
    '-----------------------------------
    '// Define code for event buttons --
    '-----------------------------------
    Code =<<%code%
    if a_dlg_button = "Connect" then                     'Connect to port set all parameters first
        a_dlg_button = ""
        SR.object.datamode = 1                            'Data mode is Text Only in this demo
        S = tagged_pattern("COM1[^0-9 ]","1",PortName)    'Extract Port Number from full name we built
        SR.object.port = val(S)
        SR.object.baudrate = val(BaudRate)                'Dialog returns actual value for BaudRate
        select                                            'Convert Stop bits values to flags needed
            case StopBits = "1"                            ' by Stroke Reader
                SR.object.stopbits = 0
            case StopBits = "1.5"
                SR.object.stopbits = 1
            case StopBits = "2"
                SR.object.stopbits = 2
        end select
        SR.object.databits = val(DataBits)
        select                                            'Convert Parity names to actual to 
            case Parity = "None"                        'Values needed by stroke Reader
                SR.object.parity = 0
            case Parity = "Odd"
                SR.object.parity = 1
            case Parity = "Even"
                SR.object.parity = 2
            case Parity = "Mark"
                SR.object.parity = 3
            case Parity = "Space"
                SR.object.parity = 4
        end select            
        SR.object.connected = .T.
        if SR.object.error <> 0                     'Check if any error opening port
            ui_msg_box(DialogTtl,SR.object.errordescription,UI_ATTENTION_SYMBOL+UI_OK)
        end if
    end if 
    
    if a_dlg_button = "Disconnect" then             'Close the Connection
        a_dlg_button = ""
        IF SR.object.connected = .F.
            Status = "Com Port already closed"
        else
            SR.object.connected = .F.
        end if
    end if
    
    if a_dlg_button = "Show" then                     'refresh dialog Forcing display of 
        a_dlg_button = ""                            'incoming text in dialog 
    end if                                            'event triggered by variable watch 
    
    if a_dlg_button = "Send"                         'Send the entered of selected text
        a_dlg_button = ""
        DIM S as C
        IF a_TextOut.Find(TextOut) < 1                'add text to array for future use
            a_TextOut[] = TextOut
        end if
        S = TextOut
        IF right(S,1) <> CHR(13)                    'add carriage return if none
            S = S + CHR(13)
        end if
        SR.object.send(S)
    end if
    
    if a_dlg_button = "Ports"                        'refresh the list of available 
        a_dlg_button = ""                            ' serial ports
        REDIM a_Port[0] as C
        Ports = SR.object.PortsAvailable
        PortList = comma_to_crlf(Ports)
        AvailablePorts = "" 
        for each Port in PortList
            s = SR.object.GetPortFriendlyName(Port.value)
            a_Port[] = "COM" + Port.value + " - " + S
        next
    end if
    
    if a_dlg_button = "Exit"                        'close the port before control gets unloaded
        SR.object.connected = .F.                    'a_dlg_button is no cleared so we will exit after it's press
    end if        
    %code%
    
    '-------------------------------
    '// Finally put up the Dialog --
    '-------------------------------
    Result = ui_dlg_box(DialogTtl,Dialog,Code)
    
    '--------------------------------
    '// Write settings to registry --
    '--------------------------------
    DIM PT as P
    PT.PortName = PortName
    PT.BaudRate = BaudRate
    PT.DataBits = DataBits
    PT.Parity = Parity
    PT.Stopbits = Stopbits
    :REGISTRY.SAVE_SETTINGS("PineTracker",PT)
    
    end

    #2
    Re: Serial Communications Active X Demo

    Hey Paul, Im drowning here, This topic of serial port communication is killing me, Ive all over this board seeking the needed knowledge to send and receive data between my PC and mobile bar code scanner that scans product and logs the qty of each. I was trying with Eltima Serial Port activeX, but they don't offer the support i need. I was very excited when I came across this post, and I was able to see the dialog ,set the port number and open the port, however nothing happened when i clicked on the "Send" button. I did download and install the suggested ActiveX. Would appreciate any assistance you can offer.

    Comment


      #3
      Re: Serial Communications Active X Demo

      I feel your pain. I too struggled with implementation Serial Communication in Alpha5. Their is a whole pile of stuff you need to get just right in order to get it to work. Hardware, communication parameters, events in Alpha5, not to mention implementing a library in an environment it was never tested in, and no example code exist for. Anyone of these things can keep the whole thing from working.

      My advice to anyone trying this it is to keep it as simple as possible at first, and as you get the basic stuff working add more to the whole.

      Start by Download and installing a copy of Real Term http://realterm.sourceforge.net/. This program is your friend when dealing with serial interfaces. You will see lots of examples on the internet showing hyperterm being used to debug serial interfaces. Hyperterm is used in these examples because it came with windows no other reason, certainly not because it works for this purpose. Learn Real Term and use it for testing, I cannot stress this enough.

      Connect a loopback connector to the RS232 port on the PC you are using and then open that port with Real Term. Set real term to not echo characters and anything you type should be echoed back to the terminal screen only when the loopback connector is in place. This verifies the serial port is working and accessible. This may seem like a redundant step put when dealing with serial ports in Windows it can not be assumed that they will work as expected. Just google RS232 loopback connector to find out what they are and how to build one it only takes one wire and and one connector, you can cut up a RS232 cable if need be.

      Next disconnect Real Term from the port and run my code. Once again anything you send should should appear back. If it does not try this trouble shooting step.

      Connect the port used by my code to another port running RealTerm, using a null modem cable. This second port with Real Term can be on same PC or separate PC. If you are using another port be sure to check it with the loopback connector first.Now you can see if my code is sending anything and not receiving or receiving but not sending. Once again use Google to find out what a null modem cable is and how to build one. If My code does nor work at all test your hardware setup by running RealTerm on both ports. Remember the serial port parameters must match Baud rate, Bits, Parity, etc.

      If my code is sending and receiving properly now you need to test the hardware (in this case scanner). Connect the device to a port and run (connect) RealTerm to the port. Make sure you don't need a null modem cable for the device or active DTR CTS type signals. Once again Google this stuff to find out more. Finally you will need to consult the documentation of the hardware (scanner) to see what communication parameters it is expecting, Baudrate, Parity etc. If you don't have that documentation the whole project just got much harder, if not impossible. RealTerm does make it easy try numerous combinations of parameters so it may be possible to puzzle these things out. Use Google to find out what common RS232 communication parameters are as starting point. As a side note most scanners I have seen only put out data when they successfully read a bar code.

      I hope this gives anyone trying to make the Alpha5 serial port thing work some useful pointers.
      Last edited by pboomwork; 01-24-2015, 12:01 PM.

      Comment


        #4
        Re: Serial Communications Active X Demo

        Although it is stated in the Code I should repeat you need to install the StrokeReader ActiveX control before running the code in this post. I can be downloaded from here https://strokescribe.com/en/serial-port-download.html
        The free demo version of StrokeReader puts up occasional nag screen but is perfectly adequate for testing purposes.
        The unlimited distribution version is only $70. This is a real deal compared to the other options out there.

        Comment


          #5
          Re: Serial Communications Active X Demo

          Paul, Thanks so much for you post .... your demo is great and I "almost" have success. Seems that in my environment the receive data event won’t fire. It sends data but will not receive. Have you tried it with Alpha v12?

          The hardware (using a null modem cable) between 2 PCs is working; have success using the StrokeReader samples in VB and Excel (VBA) . I even added a line to your code to show the data event on the status line:
          Case Evt = 1
          Status = "Data"
          TextBld = TextBld + data
          while chr(13) $ TextBld
          S = left(TextBld,AT(CHR(13),TextBld)-1)
          TextBld = substr(TextBld,AT(CHR(13),TextBld)+1)
          'while Left(TextBld,1) $ crlf()
          ' TextBld = substr(TextBld,2)
          'wend
          TextIn = TextIn + S + crlf()

          Any ideas would be most welcome.

          FYI – I have a great tool for serial work “Matko Stream Viewer” http://www.matko.com/downloads.htm

          Comment


            #6
            Re: Serial Communications Active X Demo

            Not sure what you are trying to do. Here is a simple example of intercepting a barcode scanner set to UPC-A:

            Code:
            dim sp as System::IO::Ports::SerialPort
            dim Buffer as C
            dim SizeRead as N
            dim BarCodeSize as N = 12
            dim ReadLog as C
            
            
            ui_dlg_box("Bar Code Scan",<<%dlg%
            {can_exit=close}
            {startup=init}
            {timer=CheckScanner}{interval=.5}
            {region}
            {region}
            [%MRV%.30,20ReadLog]
            {endregion}
            | {region}<Start>;<Stop>;<Close!close>
            {endregion}
            {endregion}
            %dlg%,<<%code%
            
            if a_dlg_button = "init" then
            	a_dlg_button = ""
            	sp.PortName = "COM1"
            	
            else if a_dlg_button = "Start" then
            	a_dlg_button = ""
            	hourglass_cursor(.t.)
            	sp.Open()
            	hourglass_cursor(.f.)
            	
            else if a_dlg_button = "Stop" then
            	a_dlg_button = ""
            	hourglass_cursor(.t.)
            	sp.Close()
            	hourglass_cursor(.f.)
            	
            else if a_dlg_button = "CheckScanner" then
            	a_dlg_button = ""
            	hourglass_cursor(.t.)
            	if sp.IsOpen
            		BytestoRead = sp.BytesToRead
            		if BytesToRead >= BarCodeSize
            			Buffer = ""
            			on error resume next
            			'debug(1)
            			
            			for i = 1 to BytesToRead
            				Buffer = Buffer + chr(sp.ReadChar())
            			next
            			
            			on error goto 0
            			if len(Buffer) >= BarCodeSize
            				StatusBar.Set_Text(Buffer)
            				ReadLog = ReadLog + Buffer + crlf()
            			else
            				StatusBar.Set_Text("Read error: " + Buffer)
            				' .. handle read error
            			end if
            		else
            			StatusBar.Set_Text("Bytes available = " + BytesToRead)
            		end if
            	else
            		StatusBar.Set_Text("Port not open.")
            	end if
            	hourglass_cursor(.f.)
            end if
            
            %code%)
            Works very well. The real code writes data to SQL or dbf depending upon the application (in my situation at least).
            Peter
            AlphaBase Solutions, LLC

            [email protected]
            https://www.alphabasesolutions.com


            Comment


              #7
              Re: Serial Communications Active X Demo

              Peter, Thanks for your code sample ... will give it a try later today. My application is reading an industrial truck scale. When you
              send it a 2 character code, it returns the gross weight... pretty simple task.

              Comment


                #8
                Re: Serial Communications Active X Demo

                Peter, Thank you! Thank you! ... tested great. Since is uses .Net I won't need to purchase ActiveX 3rd party product. You're a life saver ... I've been fooling with this for a couple of days and need to have my app tested and ready for use by the start of the new year.

                Comment


                  #9
                  Re: Serial Communications Active X Demo

                  Glad you got your serial scale sorted. To answer your question I've never tried this libray in anything other then Ver 10.5 which is what I own ,runtimes and all. Main reason I went this route no .NET support in Ver 10.5

                  Comment


                    #10
                    Re: Serial Communications Active X Demo

                    Main reason I went this route no .NET support in Ver 10.5
                    I'm pretty sure .NET runs just fine in v10. It's just not documented until v11. But I think it works.
                    Peter
                    AlphaBase Solutions, LLC

                    [email protected]
                    https://www.alphabasesolutions.com


                    Comment

                    Working...
                    X