Pages: 1 [2] 3   Go Down
Author Topic: Serial data to Visual Basic, Visual C++, Java  (Read 7823 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 86
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

May be any of you can help me.

Sometimes, when speaking to arduino from linux, i just read crap from arduino, and after some refreshes, i read good values.
Both are configured at 9600, no parity, 8bits, 1 stop bit.

Do you know why is it happening?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Mikmo!
can you put the link? I´m trying to develop some interface betwen Arduino and a VB6 app. I was wondering to write a protocol using the interrupt signals an serial event for read an write de analogs an digital pins from a VB6 environment.
I´ll be pleased to send the results, but at this moment is only a paper. I´m a newbie in C programming.
Logged

Denver
Offline Offline
God Member
*****
Karma: 20
Posts: 779
Inactive - PM
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry to resurrect a (relatively) old thread, but I  found something that may be helpful to those who want to use VBScript to communicate to the Arduino. It's a free OCX available at:
http://home.comcast.net/~hardandsoftware/NETCommOCX.htm

Quote
The NETCommOCX is an ActiveX control that wraps the functionality of MSComm32.ocx.

Using this, it was easy for me to write a script that sends the date and time to my sketch with no special programming environment installed.

John
Logged

"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry !

I just realized that i goofed up and forgot to actually post the promised link.

Here it is.

http://mikmo.dk/misc/vbarduino.zip

I'm currently working on a much more advanced project involving Arduino and VB.net. When i get a little further more source code will be made available.

Logged

0
Offline Offline
Edison Member
*
Karma: 8
Posts: 1411
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
This may have been posted before, but "repetition is the mother of learning".
It is possible to send data on serial port in windows just by using the windows-installed components. A simple vb script that reads a text file and sends it to serial port is shown below:

Code:
Const ForReading = 1
Const ForWriting = 2

'-------------------------------
' open USB serial port (COMx);
'
' If the serial monitor in Arduino IDE is open, you will get an "access denied" error.
' Just make sure that the serial monitor is closed (so bytes are not sent by the arduino board).
'-------------------------------
Set fso = CreateObject("Scripting.FileSystemObject")
Set com = fso.OpenTextFile("COM4:9600,N,8,1", ForWriting)

'---------------------------------------------
' read content of text file line by line;
' write line to COMx;
'---------------------------------------------

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\docs\quotes.txt", ForReading)

MsgBox("Ready to write file content to COM")

   Do While objFile.AtEndOfStream <> True
      '--------------------------------------------------
      ' read a few (10) characters at a time; serial buffer is limited to 32 characters;
      ' writing a character to eeprom takes about 11 ms (assuming that there is no serial.prints in the loop);
      ' therefore, after each batch of 10 chars sent to COM, we should wait no less than 110 ms;
      ' we use 200 to have a margin of safety;
      '--------------------------------------------------

      strChars = objFile.Read(10)
      com.Write(strChars)
      WScript.Sleep(200)
   Loop


objFile.Close
com.Close()

MsgBox("Finished writing to COM")


I used this script to load an 25LC256 eprom with quotes from a text file, part of my implementation of the "Life clock" project initiated by Mr. BroHogan (see http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1214682544).
According to the datasheet, the eprom requires a 5 ms delay after each byte written (it takes its time to carve the data onto the silicon). In my writeByte function, I used a delay of 10 ms.

A 32K text file takes about 10 minutes to write to the eprom using this script.
« Last Edit: February 01, 2009, 08:15:28 pm by florinc » Logged

Denver
Offline Offline
God Member
*****
Karma: 20
Posts: 779
Inactive - PM
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks florinc!
That's even simpler than what I was doing. (My goal was to de-geekify   the setting of the clock for others.)
I tried it and it works great & no SW to install.
Fine way to load up an EEPROM too!
Logged

"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll

Cumming, GA
Offline Offline
Edison Member
*
Karma: 20
Posts: 1657
Ultimate DIY: Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is what Processing and Firmata are all about.  If you find Processing hard, you are only going to be able to hack around someone else's VB code since Processing is probably easier to master than modern versions of VB.  

Just take the time to study Processing and firmata and you will soon be able to help yourself find solutions to your design ideas.  It's all in there and it's platform independent too.
« Last Edit: February 01, 2009, 10:01:51 pm by pwillard » Logged

Denver
Offline Offline
God Member
*****
Karma: 20
Posts: 779
Inactive - PM
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

pwillard,

There are many ways I could have chosen to to allow friends and family to have a simple way to reset the time on my project.

Requiring them to install Processing, is not one I would have considered. Beyond that, at 14.1K I'd never be able to fit Firmata.

I'm not sure who's code you felt I was hacking around in, but I did appreciate the example that allows VbScript to be used without the need to install anything. I don't suppose that VbScript is cross-platform, but that's fine - it was just a simple means to an end.

Thanks for the suggestion, anyway.
Logged

"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll

Cumming, GA
Offline Offline
Edison Member
*
Karma: 20
Posts: 1657
Ultimate DIY: Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, my perspective might be a little off. I have a number of different servers running at home, some Linux, some Windows.  Processing proved to be a life safer since it was portable and readily available with solutions for Arduino.

I'd also like to mention though, that Richard Grier's book on Visual Basic Serial Communication is excellent. His web pages are mentioned on posts above.  The book is well worth the purchase price.
« Last Edit: February 02, 2009, 01:01:59 pm by pwillard » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm also interested in interfacing the Arduino with VB.

However, I'm a newb in VB and the last time i touched it was in HS days and never messed with serial.

Can someone post a simple code with the Arduino sending an Int to VB text box?

And also step by step for setting up the VB end would be most helpful.

I have VB 6.0 and Visual Studio 2008 provided by my school, if that helps.
Logged

Cumming, GA
Offline Offline
Edison Member
*
Karma: 20
Posts: 1657
Ultimate DIY: Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, now you see the problem.  Microsoft radically changed VB with every release.  VB6 and the VB inside Visual Studio 2008 are amazingly different from each other once you decide you want to do something with the serial ports.  VB6 has the MSCOM library built in (if you have the right version).  VS 2008 practically tries to deny that the serial port even exists and my first attempts to use 2008 showed me that there were some flaws in the library.

If you decide to go with 2008, here is a reference to some of the things that changed: http://msdn.microsoft.com/en-us/library/ms364066(vs.80).aspx
Logged

0
Offline Offline
Edison Member
*
Karma: 8
Posts: 1411
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I guess this is well known, but again, "repetition is the mother of learning": there is a big difference between VB (short for Visual Basic) and VB script.

Visual Basic is a language, like C++, Java etc.  The code one writes in Visual Basic must be compiled using some software from Microsoft (Visual Studio, for example). One needs to buy/install/maintain this software.

On the other hand, VB script does not require any extra software. It comes with the windows operating system (that is, it is built in). The beauty of VB script (besides costing zero) is that code can be put together and tested fast.

Mikhal, for a quick solution to your problem, you can get some inspiration from the VB script posted earlier. Just  open the COM port for reading (instead of writing) and read as if you would from a text file. It is that simple. It is all there for you to play with. There is no input box, indeed, but you can just display the value sent from arduino.



« Last Edit: February 02, 2009, 03:20:55 pm by florinc » Logged

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Mikhal!

Follow the link in my previous post. The Vb code is Visual studio 2003, but it should convert to VS 2008 without problems.

The code reads the values of 16 slide pots from Arduino serial, as integers and displays them in a form.

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks alot MikMo, even though i ccouldnt completely convert your code to work on studio 2008, the coding itself did help me alot.

I ended up using VB 6.0 for simplicity sake.

Also I have a question, can a single serial port send and receive at once under VB?

I got a debug error when i tried to send > 1 byte to the arduino.

Under the standard arduino interface and hyperterm, everything works fine
Logged

Cumming, GA
Offline Offline
Edison Member
*
Karma: 20
Posts: 1657
Ultimate DIY: Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

FIRMATA is an attempt to do that.  It's at least a somewhat documented protocol.

http://firmata.org/wiki/V2.0ProtocolDetails

It might not be a bad place to start... instead of starting from scratch.
Logged

Pages: 1 [2] 3   Go Up
Jump to: