PDA

View Full Version : [Question(s)] com port via VB Script - help needed



cbrooks999
01-24-2015, 11:09 AM
Hi all;

I have some basic programming skills but am new to vb scripting.

I'm looking to be able to create a simple vb script I can call to control a physical motor.

I was hoping to create a high/low state on 2 pins (one for left on for right rotation) through either a serial DB9 port (preferred) or parallel port.

Can anyone offer an example script I can call to turn a pin on and then another to turn it off? (high/low)

Thanks !!!

JeffRo
01-27-2015, 02:51 PM
I do have some samples in VB if this will help, I have samples of using the Parallel Port as well as the pin out and how to use the Mscomm or serial. Which would you prefer.

cbrooks999
01-27-2015, 04:10 PM
Thanks. I "believe" that a parallel port is "easier"? However is not typically available on newer laptops so an adapter would be required. If this is possible on a serial (DB9) port, I'd really be interested in that. So... either or both? lol I'm open to suggestions. I do want to avoid a micro controller though. thx!

jwatte
01-28-2015, 10:16 AM
The PC serial hardware cannot do this. PC parallel port hardware can sometimes do this, but support is so old and ancient (and USB versions so undocumented and hard to find) that you really don't want to do it that way.

The easiest way is to get some USB-connected microcontroller, and tell that what to do. You can use an Arduino Leonardo, or a Teensy 3.1, or an OpenCM 9.04, or one of a number of other controllers available. You then write a very small piece of software to run on that controller to toggle pins as appropriate, and talk to that controller from the PC using a serial port (check the SerialPort class/component.)

Assuming your Arduino runs a sketch like this:



void setup() {
Serial.begin(9600);
}

char cmd = 0;

void loop() {
if (Serial.available()) {
char ch = Serial.read();
if (cmd == 0) {
if (ch == '+' || ch == '-') {
cmd = ch;
}
} else {
if (ch >= 2 && ch <= 13) { // digital pins 2 .. 13 allowed
pinMode(ch, OUTPUT);
digitalWrite(ch, (cmd == '+') ? HIGH : LOW);
}
cmd = 0;
}
}
}


Then, you can tell the controller to turn pin 8 high by doing:



Namespace x
Public Class y
Private serialPort1 As System.IO.Ports.SerialPort
Public Sub New()
InitializeComponent();
serialPort1.Write(New Byte() {CByte("+"C), 8}, 0, 2)
End Sub
End Class
End Namespace

Det
01-28-2015, 03:40 PM
Just dropping in: Are you sure about your hardware-setup? Quote: igh/low state on 2 pins (one for left on for right rotation)
does not seem to work to me? Does your hardwaresetup involve something like a H-Bridge (an L293d IC or something)?

(Just my 2cts)

JeffRo
01-29-2015, 07:43 AM
I have used two different servo controller boards and have found that the Veyron 24 Channel works the best and is much more forgiving.
You can check it out here. https://www.dfrobot.com/index.php?route=product/product&product_id=1145&search=veyron&description=true The other one I have used is by Pololu and they make it in a 6, 12, 18 and 24 channel. https://www.pololu.com/search?query=Maestro&x=5&y=9 There are samples of using VB with the Pololu board and as for the Veyron board I can help out there.