Problem with VB serial
I might have asked this before, but I just can't get past it. I need to send a hex command (0xBB, or 187) out the serial port.
A propeller-based device I'm developing needs to see the command and do something. I can send 187 out the serial port in any number of ways (terminal, python, whatever) and they all work perfectly fine.
But when I use "SerialPort.Write(187)" in VB (after setting up the port, etc.) the propeller obviously doesn't see it as 187, because it doesn't respond.
I know the serial port is set up, because the TX LED on my USB to serial converter flashed every time I try to send it from the VB app.
Is there some difference in the way VB would handle a normal serial port vs. the virtual one created by the FTDI chip?
thanks, Justin
A propeller-based device I'm developing needs to see the command and do something. I can send 187 out the serial port in any number of ways (terminal, python, whatever) and they all work perfectly fine.
But when I use "SerialPort.Write(187)" in VB (after setting up the port, etc.) the propeller obviously doesn't see it as 187, because it doesn't respond.
I know the serial port is set up, because the TX LED on my USB to serial converter flashed every time I try to send it from the VB app.
Is there some difference in the way VB would handle a normal serial port vs. the virtual one created by the FTDI chip?
thanks, Justin
Comments
You might try the following method
Dim my_array As Byte() = New Byte(3) {&H0,&H0,&H0,&H0}·· 'create and initialize an array of bytes (a buffer)
my_array(0)=&HBB·· 'assign 187 to element 0
SerialPort1.Write(my_array, 0, 1)· 'transmit 187 as 1 byte
If you need a Newline or Carriage return you would need to transmit 2 bytes like the following
my_array(0)=&HBB·· 'assign 187 to element 0
my_array(1)=&HD·····'assign carriage return to element 1
SerialPort1.Write(my_array, 0, 2)· 'transmit 187 as·one byte followed by a second byte 13 (CR)
The array gives you the option to transmit a string of bytes if needed and also elements can be added if required
Jeff T.
EDIT missed a curly bracket off the end of the array
Post Edited (Unsoundcode) : 11/11/2007 11:28:27 PM GMT
edit: well, your idea works fine so I guess I'll stick with it. I am just not entirely sure why it's necessary...
edit 2: well now that I think about it, I will need to send more than one byte in some cases.
Thanks for the help!
Post Edited (Whelzorn) : 11/12/2007 12:05:17 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
The SerialPort or SerialPort1 is just a name used in declaration.
Justin there are a couple of ways of sending one byte but I figured the array is much faster and much·more flexible. The array can be used in Write or Read statements and down the line I am confident you will find it·much more·useful than being able to send one byte.
Jeff T.
If I use a terminal, capture all the data to a file, then rename it a jpg, that works fine. But if I send the 0xBB from this basic app, the FTDI chip's LED stops blinking about half way through the transfer, but it blinks the entire time when I use a terminal. I haven't actually found a way to have the VB app to send all of the data to a file (I need to use a delegate, which I don't really understand) but the USB to serial converter's LED should indicate transfer regardless, right?? Obviously not, but I'm not sure why.
I gave this link in another post recently, and although I still have a hard job getting my head around delegates at times this article really helped me understand the basics.
http://www.developerfusion.co.uk/show/5251/
Jeff T.
Dim my_array(20000) as Byte···
Dim index as Int16=0
Then in the Data_Received event
Serialport.Read(my_array,index,1)
If my_array(index) = EOF Then
index=0
Goto the write array to·file routine
Else
index +=1
EndIf
Jeff T.