Mscomm, serial port question 
Author Message
 Mscomm, serial port question

I am trying to send and receive data from a serial device using Mscomm /
VB6.

The device receives data from either a remote control, or a serial port (my
goal), in a 3 byte format, and reflects all data received from the remote
control back through the serial port.

Communication is at 9600 baud,one stop bit,no parity.

The first byte is OFE, followed by two bytes corresponding to the 16-bit
words of a command table.

For example:

Command 1 = 1111111111111111  which when sent by the remote control reflects
back  t?? (using mscomm1.input) which translates to 254 255 255 ansi,
11111110 11111111 11111111 binary etc. (This is good and makes sense to me
as FE in hex is 254 in decimal, and 11111111 in binary is 255 in decimal)

My problem is in sending data to the device.  How do I send the above
command to the device through the serial port?

I have tried the following:

dim arr() as byte
mscomm1.portopen = true
arr = "t??"
mscomm1.output = arr

the device blinks and receives data but excutes the wrong command.
mscomm1.output = "t??" does nothing.

What am I doing wrong?
Is Unicode invoved here?
The concept of byte arrays is confusing.  I have used VB3, but VB6 is new to
me.

Any help would be greatly appreciated.

Thanks,

Bob H



Thu, 21 Jun 2001 03:00:00 GMT  
 Mscomm, serial port question
It looks like you are confusing a Byte Array with a String.
You first define the Byte Array which is correct.
dim arr() as byte
But then you try to assign a String to the Byte Array which is not...
arr = "t??"
You need to do something like the following
arr(0) = 254
arr(1) = 255
arr(2) = 255
That should work for what you want to do
Quote:

> I am trying to send and receive data from a serial device using Mscomm /
> VB6.

> The device receives data from either a remote control, or a serial port (my
> goal), in a 3 byte format, and reflects all data received from the remote
> control back through the serial port.

> Communication is at 9600 baud,one stop bit,no parity.

> The first byte is OFE, followed by two bytes corresponding to the 16-bit
> words of a command table.

> For example:

> Command 1 = 1111111111111111  which when sent by the remote control reflects
> back  t?? (using mscomm1.input) which translates to 254 255 255 ansi,
> 11111110 11111111 11111111 binary etc. (This is good and makes sense to me
> as FE in hex is 254 in decimal, and 11111111 in binary is 255 in decimal)

> My problem is in sending data to the device.  How do I send the above
> command to the device through the serial port?

> I have tried the following:

> dim arr() as byte
> mscomm1.portopen = true
> arr = "t??"
> mscomm1.output = arr

> the device blinks and receives data but excutes the wrong command.
> mscomm1.output = "t??" does nothing.

> What am I doing wrong?
> Is Unicode invoved here?
> The concept of byte arrays is confusing.  I have used VB3, but VB6 is new to
> me.

> Any help would be greatly appreciated.

> Thanks,

> Bob H



Thu, 21 Jun 2001 03:00:00 GMT  
 Mscomm, serial port question
Yup, that's it.

Thanks for the help Brad.

Bob H

Quote:

>It looks like you are confusing a Byte Array with a String.
>You first define the Byte Array which is correct.
>dim arr() as byte
>But then you try to assign a String to the Byte Array which is not...
>arr = "t??"
>You need to do something like the following
>arr(0) = 254
>arr(1) = 255
>arr(2) = 255



Fri, 22 Jun 2001 03:00:00 GMT  
 Mscomm, serial port question

Quote:

>Yup, that's it.

>>It looks like you are confusing a Byte Array with a String.
>>You first define the Byte Array which is correct.
>>dim arr() as byte
>>But then you try to assign a String to the Byte Array which is not...
>>arr = "t??"
>>You need to do something like the following
>>arr(0) = 254
>>arr(1) = 255
>>arr(2) = 255

I missed the beginning of this thread, but the code:
Dim arr() As Byte
arr = "t??"
Is perfectly legitimate providing you remember that VB is going to store the
Unicode values for the string in the byte array.  When I try this I get a 6
element array with the values 254,0,255,0,255,0
It can also be done the other way as in:
Dim arr() As Byte
Dim str As String
arr = "t??"
str = arr


Fri, 22 Jun 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. mscomm - send/receive from serial port

2. ?MSCOMM - Read Signals From Serial Ports

3. Using serial port without using MSCOMM

4. Mscomm doesn't hear my serial port

5. MSComm problem with multi-port serial card

6. VB Communications, MSComm, Serial Ports and Modems...

7. Modems, Serial Ports, MSComm and VB

8. Modem, serial port, MSComm and VB Communications

9. Serial port, MSComm, Modem and VB communication

10. VB3 Serial Port Control without MSCOMM.VBX

11. MSCOMM and multiple serial ports

12. Problems with opening the serial port using MsComm

 

 
Powered by phpBB® Forum Software