Using RS485 within C#

  • Thread starter Thread starter Niki Estner
  • Start date Start date
N

Niki Estner

Most PCs don't have a RS485 port. If you use a RS232-RS485 adapter, you
could go with one of the tutorials you already found. If you have some
special hardware in your PC that has an RS485 port, you should refer to the
docs of the HW

Niki
 
Someone knows where to get tutorials or examples of RS485 Implementation
within C#?
I seach a lot, but all examples are related to RS232, but not RS485. The
sample question I have is how to provide device address within COMM
interface?

TNX
 
Tamir Khason said:
Thank you for quick response
How can I know if my computer have RS485 port..

If you didn't put one into it yourself, it doesn't have one.
I'm trying to work with
special hardware using RS485 protocol, however it very old and lack of
documentation so sniffing it's firmware to detect the protocol and then
emulate it

Get a RS232-RS485 bridge.

Niki
 
Tamir,

Niki is correct. If you didn't order a special RS-485 card and install
a converter yourself, then your computer does not have one.

That said, if you install and adapter, then the RS-485 will operate just
like your standard RS-232 comm port. If there is a device addressing
protocol on the serial bus, then it will be separate the normal serial
communication tools. I recommend you closely read the specs of the device
that you are connecting with. It should specify either a hardware
addressing protocol or a software communications protocol (message
wrappers).

Jim
 
Thank you for quick response
How can I know if my computer have RS485 port.. I'm trying to work with
special hardware using RS485 protocol, however it very old and lack of
documentation so sniffing it's firmware to detect the protocol and then
emulate it

Please advice what to do...
 
Thank you for response,
As I answered to Niki, there are old Win98 machine without special connector
working with this device.
I'm trying to connect and operate the device.
Following the sequence working from old machine:

0.00000560 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000560 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: 1
0.00000960 Prog1.exeVCOMM_WriteComm COM1 SUCCESS Length: 6: 00 00 80 80 80
E0
0.00000800 Prog1.exeWriteNotifyProc COM1 VOID TRANSMIT: TXCHAR
0.00000480 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: -1
0.00000400 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000880 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000640 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: 1
0.00001440 Prog1.exeVCOMM_WriteComm COM1 SUCCESS Length: 6: 00 00 60 80 80
E0
0.00000880 Prog1.exeWriteNotifyProc COM1 VOID TRANSMIT: TXCHAR
0.00000400 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: -1
0.00000480 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000640 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000480 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: 1
0.00001040 Prog1.exeVCOMM_WriteComm COM1 SUCCESS Length: 6: 00 00 60 80 80
00
0.00000800 Prog1.exeWriteNotifyProc COM1 VOID TRANSMIT: TXCHAR
0.00000320 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: -1
0.00000320 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000800 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000560 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: 1
0.00001200 Prog1.exeVCOMM_WriteComm COM1 SUCCESS Length: 6: 00 00 60 80 80
00
0.00000960 Prog1.exeWriteNotifyProc COM1 VOID TRANSMIT: TXCHAR
0.00000480 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: -1
0.00000400 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000800 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000640 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: 1
0.00001360 Prog1.exeVCOMM_WriteComm COM1 SUCCESS Length: 6: 00 00 60 80 80
00
0.00000880 Prog1.exeWriteNotifyProc COM1 VOID TRANSMIT: TXCHAR
0.00000320 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: -1
0.00000400 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000800 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000640 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: 1
0.00001280 Prog1.exeVCOMM_WriteComm COM1 SUCCESS Length: 6: 00 00 60 80 80
00
0.00000880 Prog1.exeWriteNotifyProc COM1 VOID TRANSMIT: TXCHAR
0.00000400 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: -1
0.00000320 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000720 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000480 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: 1
0.00001040 Prog1.exeVCOMM_WriteComm COM1 SUCCESS Length: 6: 00 00 60 80 80
00
0.00000880 Prog1.exeWriteNotifyProc COM1 VOID TRANSMIT: TXCHAR
0.00000320 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: -1
0.00000320 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000640 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00001680 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: 1
0.00001040 Prog1.exeVCOMM_WriteComm COM1 SUCCESS Length: 6: 00 00 60 80 80
00
0.00000800 Prog1.exeWriteNotifyProc COM1 VOID TRANSMIT: TXCHAR
0.00000320 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: -1
0.00000400 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000640 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000480 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: 1
0.00001120 Prog1.exeVCOMM_WriteComm COM1 SUCCESS Length: 6: 00 00 60 80 80
00
0.00000880 Prog1.exeWriteNotifyProc COM1 VOID TRANSMIT: TXCHAR
0.00000320 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: -1
0.00000320 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000720 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000720 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: 1
0.00001440 Prog1.exeVCOMM_WriteComm COM1 SUCCESS Length: 6: 00 00 80 80 80
E0
0.00001040 Prog1.exeWriteNotifyProc COM1 VOID TRANSMIT: TXCHAR
0.00000400 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: -1
0.00000320 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000480 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000480 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: 1
0.00001040 Prog1.exeVCOMM_WriteComm COM1 SUCCESS Length: 6: 00 00 80 80 80
E0
0.00000560 Prog1.exeWriteNotifyProc COM1 VOID TRANSMIT: TXCHAR
0.00000320 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: -1
0.00000400 Prog1.exe VCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0

Following my sequence (wich does not works)
0.00004190 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 80 80 80
E0
0.00527609 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
E0
0.00622621 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
00
0.00620917 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
00
0.00614715 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
00
0.00616531 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
00
0.00614464 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
00
0.00621252 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
00
0.00622034 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
00
0.00621867 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
00
0.00621978 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
00
0.00614128 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
00
0.00621252 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
00
0.00614799 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
00
0.00621978 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
00
0.00622370 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
00
0.00622733 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
00
0.00613430 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 80 80 80
E0
0.00620973 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 80 80 80
E0

As you can probabaly see the commands are same:

0.00000640 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0
0.00000480 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: 1
0.00001120 Prog1.exeVCOMM_WriteComm COM1 SUCCESS Length: 6: 00 00 60 80 80
00
0.00000880 Prog1.exeWriteNotifyProc COM1 VOID TRANSMIT: TXCHAR
0.00000320 Prog1.exeVCOMM_SetWriteCallBack COM1 SUCCESS Trigger: -1
0.00000320 Prog1.exeVCOMM_GetCommQueueStatus COM1 SUCCESS RX: 0 TX: 0

0.00622733 Sample1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 6: 00 00 60 80 80
00

Except that old PC using VCOMM lib and I'm using kernel comm write (this
should be the same)

But in first case it works and in my programm it does not.

Please advice what is the problem....
 
There are no special hardware in old PC where the device working with
(Win98), but the cabel connect the pc and device have only two wires. So
maybe it using RS232 - How to check this... I have no any documentation
regarding the device connected, except the program on Win98 wich working
fine with it
 
If the Win98 machine already talks to the device and there is no special
'other' device attached; then it must be doing RS-232 to RS-485 conversion
internal to the device already.

That should mean that on your machine if you want to talk to the device with
C# then use a C# Serial (RS-232) library. One is available if you search on
MSDN.
 
Back
Top