Author Topic: How to define commands in Visual basic to control microcontroller  (Read 34197 times)

shilpa deepak

  • Member
  • ***
  • Posts: 3
Hi Jan,

This mail was in reference with your article "Access serialports with VisualBasic and PICBASIC".Here you have stated as "The routine understands two commands, “L11” and “L10”. On receiving “L11”, the routine sets PORTB.0 = 1 to turn on LED RB1 on the PICDEM 2 Plus board." I would like to know to how did you deternine the type of commands that the PICDEM 2 Plus board would understand?

I am working on a customised board where DSP is my target processor and I have successfully created a GUI in visual basic.Now,I would like to link my GUI with my target board i.e. I would like to communicate the GUI with my target board similar to the article that you have described as turning on/off the LED available on the PIC board.Hence,I thought I will follow the same guidelineas as you have described but I was wondering to how shall I determine the type of commands?

Waiting for your valuable inputs.

Thanks,
Shilpa

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: How to define commands in Visual basic to control microcontroller
« Reply #1 on: August 11, 2010, 10:05:38 am »
I wrote PIC firmware to look for and respond to those commands. In general, many systems define ASCII commands that terminate with a CR/LF. The receiving device stores received data up to a CR/LF and then looks to see if the data contains a defined command.

Jan

shilpa deepak

  • Member
  • ***
  • Posts: 3
Re: How to define commands in Visual basic to control microcontroller
« Reply #2 on: August 11, 2010, 11:42:31 pm »

Hi Jan,

Could you please explain me in detail?

Thanks,
Shilpa


I wrote PIC firmware to look for and respond to those commands. In general, many systems define ASCII commands that terminate with a CR/LF. The receiving device stores received data up to a CR/LF and then looks to see if the data contains a defined command.

Jan

GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
Re: How to define commands in Visual basic to control microcontroller
« Reply #3 on: August 12, 2010, 04:53:32 am »
Umm, I do quite a bit of PC to PIC interfacing in my Job.  So I will try,  it depends on what type of interface you have in the Micro, I get a mixture depending on who wrote the commands handler device used etc.  The PIC I am having to battle at the moment is a PIC16F688 the comms routine in it accepts strings delimited with # #, commands like #I# will give ATE_Xed this is fine as the Serial Ports classes Write() methods can have \r\n or (char)10 and (char)13 added as needed.
A recommendation is just set up a Form add in the serial port class and try sending some out (short pins 2 & 3 on D-type 9 way) add a button to the form and in the click routine
send something like "Hello World!" and see if it comes back to a text box on the form. Then send a command the Micro will respond to like my #I# with the 2-3 short still in place so you can tell what has gone out (and come back) then connect up to the micro and try. Also a snooper program to what is going and coming can be useful for finding out if the device is behaving nicely.

Glenn (best of luck)

shilpa deepak

  • Member
  • ***
  • Posts: 3
Re: How to define commands in Visual basic to control microcontroller
« Reply #4 on: August 12, 2010, 05:26:25 am »
Hi Glenn,

Thanks for the response.I would like to know to how did you arrive at the point of knowing that your microcontroller would accept only #I# command why not something else?

What actually I have tried is fortunately I have two serial ports in my PC and I hooked a back to back RS232 cable and plugged into both serial ports. I transmitted some character from COM1 and could receive the same on COM2.This proves to me that my serial communication routine works fine.

Now what I am trying out is as I donot have a microcontroller board,I am planning to transmist some characters from COM1 and write only a receive routine in COM2 and to check if it is getting received or not?

Between it would be great if you could let me know to how to determine what type of commands?

Regards,
Shilpa

GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
Re: How to define commands in Visual basic to control microcontroller
« Reply #5 on: August 12, 2010, 07:29:47 am »
Hi,
Ok then, I didn't do the code in the PIC that was done by a Colleague from the knowledge I have of the board.  I think the RX & TX lines of the port are wired to one of the input pins of the PIC the code in the PIC interprits the signals and away. The #I# is in the dictonary of the board to produce the "ATE_Xed".  If thats what you were after I can't help too much. If you want to know how to set up the Serial Port class and use that I have only really used C# for it not VB.  I think you should know how to set it up from Jan example code and then use the com port method of writing that your device expects. Strings are common, try a command like myComPort.WriteLine("L000:8"); that turns a Relay off on the board that I have currently connected to my Com 1.

From your description of using one com port for Outgoing another Incoming it seems a bit of a waste of resources when you consider only one pin can be used for outgoing data (RX pin 3 of a 9 way) and one pin incoming (TX or pin 2 of a 9 Way).   Really you need to know the following before wandering down the path
1) What is the Device (PIC, MSP430 etc)
2) What is it communication parameter, Baud rate, Stop bits, Handshaking etc.
3) Does it need a carriage return or a line feed or both
4) You do need to know the commands of the device you are using (if its a consumer item they will be out there hiding on a website)
Hope that helps!

Glenn

GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
Re: How to define commands in Visual basic to control microcontroller
« Reply #6 on: August 12, 2010, 11:10:51 am »
Just thought of this link its C#, but the Q&A section is quite good at explaining some issues you might have.

http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx

Glenn