VCOMM in C#

  • Thread starter Thread starter Nicholas Paldino [.NET/C# MVP]
  • Start date Start date
Question:
I have to emulate working with some device via COM port. From sniffer I set
on the device I got hexs i have to send in order to device to do what ?I
want it to do, but HOW TO SEND IT.
I tryed libs from INET (StreamCom, etc) example from MSDN, but no chance. I
can not get what I need to.
Following the sample of "speech" sniffed from device:
0.00000720 Writer VCOMM_GetCommQueueStatus 0xC147DA54 SUCCESS RX: 0 TX: 0
0.00000640 Writer VCOMM_SetWriteCallBack 0xC147DA54 SUCCESS Trigger: 1
0.00001280 Writer VCOMM_WriteComm 0xC147DA54 SUCCESS Length: 6: 00 00 80 80
80 E0
0.00000640 Writer WriteNotifyProc 0xC147DA54 VOID TRANSMIT: TXCHAR
0.00000400 Writer VCOMM_SetWriteCallBack 0xC147DA54 SUCCESS Trigger: -1
0.00000480 Writer VCOMM_GetCommQueueStatus 0xC147DA54 SUCCESS RX: 0 TX: 0
How to emulate such thing with C# program?

TNX
 
Tamir,

What do you mean by six-bit hex? Hex is just a representation of a
value, just like bits are (they are values in base 2). I don't think it is
possible to send just bits, but rather you have to send bytes.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tamir Khason said:
I tried this approach, however instead of sending 6bit hex it sends much
longer 8/16. Maybe I missed something...

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "



message news:[email protected]...
Tamir,

The protocol that the device uses when sending and receiving information
is up to you to determine. However, telling you how to send the information
is easy. Check out the article in MSDN titled "Use P/Invoke to Develop a
.NET Base Class Library for Serial Device Communications", located at (watch
for line wrap):

http://msdn.microsoft.com/msdnmag/issues/02/10/NETSerialComm/default.aspx

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tamir Khason said:
Question:
I have to emulate working with some device via COM port. From sniffer
I
set
on the device I got hexs i have to send in order to device to do what ?I
want it to do, but HOW TO SEND IT.
I tryed libs from INET (StreamCom, etc) example from MSDN, but no
chance.
I
can not get what I need to.
Following the sample of "speech" sniffed from device:
0.00000720 Writer VCOMM_GetCommQueueStatus 0xC147DA54 SUCCESS RX: 0
TX:
TX:
 
I tried this approach, however instead of sending 6bit hex it sends much
longer 8/16. Maybe I missed something...

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "



Nicholas Paldino said:
Tamir,

The protocol that the device uses when sending and receiving information
is up to you to determine. However, telling you how to send the information
is easy. Check out the article in MSDN titled "Use P/Invoke to Develop a
.NET Base Class Library for Serial Device Communications", located at (watch
for line wrap):

http://msdn.microsoft.com/msdnmag/issues/02/10/NETSerialComm/default.aspx

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tamir Khason said:
Question:
I have to emulate working with some device via COM port. From sniffer I set
on the device I got hexs i have to send in order to device to do what ?I
want it to do, but HOW TO SEND IT.
I tryed libs from INET (StreamCom, etc) example from MSDN, but no
chance.
I
can not get what I need to.
Following the sample of "speech" sniffed from device:
0.00000720 Writer VCOMM_GetCommQueueStatus 0xC147DA54 SUCCESS RX: 0 TX: 0
0.00000640 Writer VCOMM_SetWriteCallBack 0xC147DA54 SUCCESS Trigger: 1
0.00001280 Writer VCOMM_WriteComm 0xC147DA54 SUCCESS Length: 6: 00 00 80 80
80 E0
0.00000640 Writer WriteNotifyProc 0xC147DA54 VOID TRANSMIT: TXCHAR
0.00000400 Writer VCOMM_SetWriteCallBack 0xC147DA54 SUCCESS Trigger: -1
0.00000480 Writer VCOMM_GetCommQueueStatus 0xC147DA54 SUCCESS RX: 0 TX: 0
How to emulate such thing with C# program?

TNX
 
Tamir,

You don't want to send 2155905248, because it is a long, which is 8
bytes. Rather, you want to create an array of six bytes, and then send
that. So, for your app, you would do:

// Create the array of bytes
byte[] bytes = new byte[6];

// Set the values.
bytes[0] = 0;
bytes[1] = 0;
bytes[2] = 0x80;
bytes[3] = 0x80;
bytes[4] = 0x80;
bytes[5] = 0xe0;

Of course, you would have to have some logic to make this more generic,
but once you do that, you can pass the array of six bytes through the serial
port.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tamir Khason said:
sorry, bytes. The structures sent are like this :(Length 6): 0x0000808080E0.
However while i send 2155905248 I recieve (Length 8)0x00000000808080E0 and
this does not works

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

message news:[email protected]...
Tamir,

What do you mean by six-bit hex? Hex is just a representation of a
value, just like bits are (they are values in base 2). I don't think it is
possible to send just bits, but rather you have to send bytes.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tamir Khason said:
I tried this approach, however instead of sending 6bit hex it sends much
longer 8/16. Maybe I missed something...

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "



"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message Tamir,

The protocol that the device uses when sending and receiving
information
is up to you to determine. However, telling you how to send the
information
is easy. Check out the article in MSDN titled "Use P/Invoke to
Develop
a
.NET Base Class Library for Serial Device Communications", located at
(watch
for line wrap):
http://msdn.microsoft.com/msdnmag/issues/02/10/NETSerialComm/default.aspx
Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Question:
I have to emulate working with some device via COM port. From
sniffer
I
set
on the device I got hexs i have to send in order to device to do
what
?I
want it to do, but HOW TO SEND IT.
I tryed libs from INET (StreamCom, etc) example from MSDN, but no
chance.
I
can not get what I need to.
Following the sample of "speech" sniffed from device:
0.00000720 Writer VCOMM_GetCommQueueStatus 0xC147DA54 SUCCESS RX:
0
TX:
0
0.00000640 Writer VCOMM_SetWriteCallBack 0xC147DA54 SUCCESS
Trigger:
1 00 0
TX:
 
sorry, bytes. The structures sent are like this :(Length 6): 0x0000808080E0.
However while i send 2155905248 I recieve (Length 8)0x00000000808080E0 and
this does not works

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

Nicholas Paldino said:
Tamir,

What do you mean by six-bit hex? Hex is just a representation of a
value, just like bits are (they are values in base 2). I don't think it is
possible to send just bits, but rather you have to send bytes.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tamir Khason said:
I tried this approach, however instead of sending 6bit hex it sends much
longer 8/16. Maybe I missed something...

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "



message news:[email protected]...
Develop
a
.NET Base Class Library for Serial Device Communications", located at (watch
for line wrap):

http://msdn.microsoft.com/msdnmag/issues/02/10/NETSerialComm/default.aspx

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Question:
I have to emulate working with some device via COM port. From
sniffer
what
00
 
o, you are right, but still while I'm sending
new byte[] {0x00,0x00,0x80,0xA8,0x80,0x40}

I recieve in sniffer like I sent Length 13: 53 79 73 74 65 6D 2E 42 79 74
65 5B 5D

WHY?



--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

Nicholas Paldino said:
Tamir,

You don't want to send 2155905248, because it is a long, which is 8
bytes. Rather, you want to create an array of six bytes, and then send
that. So, for your app, you would do:

// Create the array of bytes
byte[] bytes = new byte[6];

// Set the values.
bytes[0] = 0;
bytes[1] = 0;
bytes[2] = 0x80;
bytes[3] = 0x80;
bytes[4] = 0x80;
bytes[5] = 0xe0;

Of course, you would have to have some logic to make this more generic,
but once you do that, you can pass the array of six bytes through the serial
port.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tamir Khason said:
sorry, bytes. The structures sent are like this :(Length 6): 0x0000808080E0.
However while i send 2155905248 I recieve (Length 8)0x00000000808080E0 and
this does not works

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

message news:[email protected]...
Tamir,

What do you mean by six-bit hex? Hex is just a representation of a
value, just like bits are (they are values in base 2). I don't think
it
is
possible to send just bits, but rather you have to send bytes.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I tried this approach, however instead of sending 6bit hex it sends much
longer 8/16. Maybe I missed something...

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "



in
message Tamir,

The protocol that the device uses when sending and receiving
information
is up to you to determine. However, telling you how to send the
information
is easy. Check out the article in MSDN titled "Use P/Invoke to Develop
a
.NET Base Class Library for Serial Device Communications", located at
(watch
for line wrap):


http://msdn.microsoft.com/msdnmag/issues/02/10/NETSerialComm/default.aspx

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Question:
I have to emulate working with some device via COM port. From sniffer
I
set
on the device I got hexs i have to send in order to device to do what
?I
want it to do, but HOW TO SEND IT.
I tryed libs from INET (StreamCom, etc) example from MSDN, but no
chance.
I
can not get what I need to.
Following the sample of "speech" sniffed from device:
0.00000720 Writer VCOMM_GetCommQueueStatus 0xC147DA54 SUCCESS
RX:
0 Trigger: 00
00
RX:
 
I detected that this device using RS485. is it changes something?

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

Nicholas Paldino said:
Tamir,

You don't want to send 2155905248, because it is a long, which is 8
bytes. Rather, you want to create an array of six bytes, and then send
that. So, for your app, you would do:

// Create the array of bytes
byte[] bytes = new byte[6];

// Set the values.
bytes[0] = 0;
bytes[1] = 0;
bytes[2] = 0x80;
bytes[3] = 0x80;
bytes[4] = 0x80;
bytes[5] = 0xe0;

Of course, you would have to have some logic to make this more generic,
but once you do that, you can pass the array of six bytes through the serial
port.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tamir Khason said:
sorry, bytes. The structures sent are like this :(Length 6): 0x0000808080E0.
However while i send 2155905248 I recieve (Length 8)0x00000000808080E0 and
this does not works

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

message news:[email protected]...
Tamir,

What do you mean by six-bit hex? Hex is just a representation of a
value, just like bits are (they are values in base 2). I don't think
it
is
possible to send just bits, but rather you have to send bytes.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I tried this approach, however instead of sending 6bit hex it sends much
longer 8/16. Maybe I missed something...

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "



in
message Tamir,

The protocol that the device uses when sending and receiving
information
is up to you to determine. However, telling you how to send the
information
is easy. Check out the article in MSDN titled "Use P/Invoke to Develop
a
.NET Base Class Library for Serial Device Communications", located at
(watch
for line wrap):


http://msdn.microsoft.com/msdnmag/issues/02/10/NETSerialComm/default.aspx

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Question:
I have to emulate working with some device via COM port. From sniffer
I
set
on the device I got hexs i have to send in order to device to do what
?I
want it to do, but HOW TO SEND IT.
I tryed libs from INET (StreamCom, etc) example from MSDN, but no
chance.
I
can not get what I need to.
Following the sample of "speech" sniffed from device:
0.00000720 Writer VCOMM_GetCommQueueStatus 0xC147DA54 SUCCESS
RX:
0 Trigger: 00
00
RX:
 
Hello Tamir

Sorry for the late response. I reviewed the issue thread. When sending data
, you send 0x0000808080E0. However, you found that the data is
0x00000000808080E0 when in transferring, right?

I am not familar with the device that you describe. Based on my knowledge,
when using COMM transferring data, we have several predefined signals. In
fact, these soft signals are defined as some constant characters. So if the
data contains these characters, the data will be recoded and un-codeds on
the other side. That may be the reason that you met this issue.

Have you tried binary transferring and closed those soft signal? That may
make things clear.

Thanks.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thank you for response:
Questions:
Have you tried binary transferring and closed those soft signal? That may
make things clear.
The only way to transfer something to COMM is binary way (for my knowledge)
but what do you mean by " closed those soft signals"
, you send 0x0000808080E0. However, you found that the data is
0x00000000808080E0 when in transferring, right?
As far I undertand 0x0000808080E0 and 0x00000000808080E0 are the same number
808080E0 - zeros in the beginning are just place holders, but maybe I'm
wrong./..
 
Hi Tamir,

"The only way to transfer something to COMM is binary way (for my
knowledge)"
Right, Win32 API only supports binary mode transfer now.

"closed those soft signals"
Forget about it. I remember there is some applications who can use some
special characters in the data stream to similar signals such as data
begin, data end... However, it seems not related to this issue.

If you have time, please check
http://www.htservices.com/Tools/VBandC/SerialCommunications.htm

This page has many code sample on RS232 and RS484. Please use them for
testing and let me know whether it is OK for you.

Thanks.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top