Shop OBEX P1 Docs P2 Docs Learn Events
DEMO: Microsoft Word 2010 ---> Propeller communication — Parallax Forums

DEMO: Microsoft Word 2010 ---> Propeller communication

Beau SchwabeBeau Schwabe Posts: 6,568
edited 2011-08-19 11:01 in Propeller 1
Microsoft Word 2010 To Propeller communication

Inspired from the recent thread...

http://forums.parallax.com/showthread.php?133885-Get-data-from-Notepad-into-Propeller

...Here is a DEMO that will read the text from a word document and send it serially to the Propeller, upon which the Propeller will display the received text on a TV terminal. You don't need a Propeller Demo board, but you do need the same TV connections as the Propeller Demo Board.

Here goes...

Derived from this excellent sight, I will describe how to communicate to the Propeller using MS Word.

Let's get started:
For this demonstration we will use Microsoft Word 2010's VBA editor.

To Start MicroSoft Word 2010

Start --> All Programs --> MicroSoft Office --> MicroSoft Word 2010

To Open Visual Basic you might need to enable the Developer Tab. To do this Select...

File --> Options --> Customize Ribbon

on the far right, make sure that Developer is checked and then select OK

Now, Select the Developer Tab and on the far right select Visual Basic

Under Project (Document1) right click and Insert ... UserForm

A blank Visual Basic Form should pop up ... At this point if you don't have mscomm32.ocx or some other valid Serial driver you will need to get it.

Following the directions on the above sight, mscomm32.ocx didn't work for me so I went with the
NETcomm OCX Driver

After installing the driver, right click on the visual basic UserForm1 Toolbox and Select Additional Controls...

Scroll down and select NETCommOCX.NET.Comm ... Click OK

With the newly added NET.Comm control, Click and drag it into the User Form1

Do the same thing with the Command.Button control. Under Properties of the CommandButton1, change the Caption to read something like ... “Send Text

In the Project Window under Project(Document1) where you see UserForm1, right click on UserForm1 and select View Code

Cut and Paste the Code Below into the View Code Window
'Start Code
'--------------------------------------------------------------------------------------------------------
'	The Serial Program
Private Sub CommandButton1_Click()

    NETComm1.DTREnable = False                          'Turn DTREnable OFF

    NETComm1.RThreshold = 1                             'Set the Receive Threshold to 1

    NETComm1.SThreshold = 1                             'Set the Transmit Threshold to 1

    

    Selection.HomeKey Unit:=wdStory                     'Position the cursor at the Top line

    Selection.EndKey Unit:=wdLine, Extend:=wdExtend     'Select the Top line

       

    NETComm1.PortOpen = True                            'Open the serial port

    NETComm1.Output = Selection.Text                    'Send Top Line via COM port

    NETComm1.PortOpen = False                           'Close the serial port

End Sub
'--------------------------------------------------------------------------------------------------------
'End Code

Under The Developer Tab, Select Macros ... Give a macro name like “TextTest”, and select Create.

You should see a code window that contains the following....
Sub TextTest()

'

' TextTest Macro

'

'



End Sub

...Edit the code window so that it has UserForm1.Show somewhere between Sub TextTest()
and End Sub

Almost There!!!

Load the supplied Microsoft Word 2010.Spin file into the Propeller with the F11 option, and find out what the Propeller Enumerates to on the COM port by pressing F7. Visual Basic will only allow COM 16 so if your Propeller is enumerating higher that that
you need to do one little quick fix...

In the Windows Device Manager Control Panel:

Start --> Control Panel --> System --> Hardware --> Device Manager

...Click on the “+” to Ports (COM & LPT) to expand it. Find the USB serial port that matches what the Propeller IDE indicated.

Right Click on that item and select Properties --> Port Settings --> Advanced

Under the COM Port Number: Change it to something less than or equal to 16 ... ignore the (in use) unless you know it's a specific port that your system is using. (You can always change it back)

Click OK, and ignore the in use warning if applicable.

The Windows Device Manager Control Panel will still probably show the original value until you refresh it (close, and re-open) ... that's ok, we're done with the Device manager.

You can close it.

Go back to the Visual Basic code ... Developer TAB --> Visual Basic

Right click on the NET.COM icon in the UserForm1 and select Properties

Change the CommPort number so that it reflects what the Propeller IDE reported

Ready To Run!!

Make sure that you hit F11 on the Propeller IDE with the supplied code, and that you have a TV connected using the Propeller Demo Board TV connections

Go to the top line of your Word Document1 and enter something like “Hello Parallax Forums” ...
Note: This DEMO will only send the TOP line of text, I will leave it as an exercise for you to send an entire document or whatever portion that you desire. Also, you could go the other direction and have the Propeller populate a word document with text.

Ok, Now that you have something in the first line of the word document, time to print it to the TV monitor.

From the word document, select View --> Macros --> TextTest (<--or the name that you gave it) --> Run

Your UserForm1 should have popped up with a button “Send Text” .... Well, go ahead, CLICK IT!!, and look at the TV Monitor.


Enjoy!! hope this opens some cool doors for you! :-)

Comments

  • TubularTubular Posts: 4,717
    edited 2011-08-19 07:24
    Nice, Beau. I like that we have a few different solutions for this now.

    I'm surprised that mscomm32.ocx didn't work - I always had good luck with this in days gone by (VB6). Could be something simple.
  • idbruceidbruce Posts: 6,197
    edited 2011-08-19 07:32
    Tubular

    That mscomm32.ocx sounds a bit interesting

    Bruce
  • Mike GMike G Posts: 2,702
    edited 2011-08-19 07:32
    If I remember correctly it has something to do with licensing. mscomm32.ocx came with VB6/5. So if you had VB6 it would work. My memory is a little foggy though.
  • idbruceidbruce Posts: 6,197
    edited 2011-08-19 07:34
    HOW TO: Provide Run-Time License Information for MsComm32.ocx in Microsoft Visual C++
    http://support.microsoft.com/kb/315501
  • RaymanRayman Posts: 14,876
    edited 2011-08-19 07:46
    Have you taken a look at the method on this page?:
    http://dev.emcelettronica.com/serial-port-communication-excel-vba

    I think it should work with Word too. It has the advantage of not having to deal with add-ins...
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-08-19 08:02
    Tubular,
    "I'm surprised that mscomm32.ocx didn't work" - Me, too... it was a licensing issue, but I have VB4 installed on the same computer and have used mscomm32.ocx and it works just fine.... I'm sure it's something simple but I didn't want to dig into fixing it... the alternative seemed simple enough.

    Mike G,
    "If I remember correctly it has something to do with licensing. mscomm32.ocx came with VB6/5" ... VB4 also
  • idbruceidbruce Posts: 6,197
    edited 2011-08-19 08:04
    I can't wait to toy around with this control in VC++ and apply it to the Propeller. Looks good to me.

    Bruce
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-08-19 11:01
    I have had versions of MScomm32.ocx that will not work for me, the version at the following link has always been good and also contains some good reference material. NETcomm is a wrapper for the MScomm control which overcomes some licensing problems.

    http://www.yes-tele.com/mscomm.html

    Jeff T.
Sign In or Register to comment.